-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathto-code-options-from-query.ts
More file actions
119 lines (114 loc) · 3.67 KB
/
to-code-options-from-query.ts
File metadata and controls
119 lines (114 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
react_presets,
reactnative_presets,
flutter_presets,
vanilla_presets,
preact_presets,
solid_presets,
} from "@grida/builder-config-preset";
import { ParsedUrlQuery } from "querystring";
import { FrameworkConfig } from "@grida/builder-config";
export function get_enable_components_config_from_query(
query: ParsedUrlQuery
): boolean {
const enable_components = query["components"];
if (enable_components) {
return enable_components === "true";
}
// disabled by default
return false;
}
export function get_framework_config_from_query(query: ParsedUrlQuery) {
const framework = query.framework as string;
return get_framework_config(framework);
}
export function get_framework_config(framework: string) {
switch (framework) {
// react
case "react":
case "react_default":
case "react-default":
case "react.default":
return react_presets.react_default;
case "react-with-styled-components":
case "react_with_styled_components":
return react_presets.react_with_styled_components;
case "react-with-emotion-styled":
return react_presets.react_with_emotion_styled;
case "react_with_inline_css":
case "react-with-inline-css":
return react_presets.react_with_inline_css;
case "react_with_css_module":
case "react-with-css-module":
return react_presets.react_with_css_module;
// react-native
case "react-native":
return reactnative_presets.reactnative_default;
case "react-native-with-style-sheet":
return reactnative_presets.reactnative_with_style_sheet;
case "react-native-with-styled-components":
return reactnative_presets.reactnative_with_styled_components;
case "react-native-with-inline-style":
return reactnative_presets.reactnative_with_inline_style;
// preact
case "preact":
case "preact_default":
case "preact-default":
case "preact.default":
return preact_presets.default;
case "preact-with-styled-components":
case "preact_with_styled_components":
return preact_presets.with_styled_components;
case "preact-with-emotion-styled":
return preact_presets.with_emotion_styled;
case "preact_with_inline_css":
case "preact-with-inline-css":
return preact_presets.with_inline_css;
case "preact_with_css_module":
case "preact-with-css-module":
return preact_presets.with_css_module;
// solid-js
case "solid_with_styled_components":
case "solid-with-styled-components":
return solid_presets.solid_with_styled_components;
case "solid_with_inline_css":
case "solid-with-inline-css":
return solid_presets.solid_with_inline_css;
// flutter
case "flutter_default":
case "flutter-default":
case "flutter.default":
return flutter_presets.flutter_default;
// vanilla
case "vanilla":
case "vanilla-default":
case "vanilla.default":
return vanilla_presets.vanilla_default;
default:
console.warn(
'no matching framework preset found for "' + framework + '"',
"fallback to react preset"
);
return react_presets.react_default;
}
}
export function get_preview_runner_framework(query: ParsedUrlQuery) {
const preview = (query.preview as string) ?? "vanilla"; // make vanilla as default preview if non provided.
return get_framework_config(
preview || get_framework_config_from_query(query).framework
);
}
export function get_runner_platform(config: FrameworkConfig) {
switch (config.framework) {
case "react":
return "react";
case "flutter":
return "flutter";
case "flutter":
return "flutter";
case "vanilla":
return "vanilla";
default:
return "vanilla";
}
}