-
-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathindex.ts
More file actions
185 lines (173 loc) · 4.59 KB
/
index.ts
File metadata and controls
185 lines (173 loc) · 4.59 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import fs from 'node:fs';
import path from 'node:path';
import {
type Argv,
checkCancel,
copyFolder,
create,
type ESLintTemplateName,
select,
} from 'create-rstack';
const frameworkAlias: Record<string, string> = {
vue: 'vue3',
'solid-js': 'solid',
};
async function getTemplateName({ template }: Argv) {
if (typeof template === 'string') {
const pair = template.split('-');
const language = pair[1] ?? 'js';
const framework = pair[0];
return `${frameworkAlias[framework] ?? framework}-${language}`;
}
const framework = checkCancel<string>(
await select({
message: 'Select framework',
options: [
{ value: 'vanilla', label: 'Vanilla' },
{ value: 'react', label: 'React' },
{ value: 'vue3', label: 'Vue 3' },
{ value: 'vue2', label: 'Vue 2' },
{ value: 'lit', label: 'Lit' },
{ value: 'preact', label: 'Preact' },
{ value: 'svelte', label: 'Svelte' },
{ value: 'solid', label: 'Solid' },
],
}),
);
const language = checkCancel<string>(
await select({
message: 'Select language',
options: [
{ value: 'ts', label: 'TypeScript' },
{ value: 'js', label: 'JavaScript' },
],
}),
);
return `${framework}-${language}`;
}
function mapESLintTemplate(templateName: string): ESLintTemplateName {
switch (templateName) {
case 'react-js':
case 'react-ts':
case 'svelte-js':
case 'svelte-ts':
return templateName;
case 'vue2-js':
case 'vue3-js':
return 'vue-js';
case 'vue2-ts':
case 'vue3-ts':
return 'vue-ts';
default:
return `vanilla-${templateName.split('-')[1]}` as ESLintTemplateName;
}
}
function mapRstestTemplate(templateName: string): string {
switch (templateName) {
case 'react-js':
return 'react-js';
case 'react-ts':
return 'react-ts';
case 'vue3-js':
return 'vue-js';
case 'vue3-ts':
return 'vue-ts';
default:
return `vanilla-${templateName.split('-')[1]}`;
}
}
const root = path.join(import.meta.dirname, '..');
create({
root,
name: 'rsbuild',
templates: [
'vanilla-js',
'vanilla-ts',
'react-js',
'react-ts',
'vue3-js',
'vue3-ts',
'vue2-js',
'vue2-ts',
'svelte-js',
'svelte-ts',
'solid-js',
'solid-ts',
],
getTemplateName,
mapESLintTemplate,
extraTools: [
{
value: 'rstest',
label: 'Rstest - testing',
order: 'pre',
action: ({ templateName, distFolder, addAgentsMdSearchDirs }) => {
const rstestTemplate = mapRstestTemplate(templateName);
const toolFolder = path.join(root, 'template-rstest');
const subFolder = path.join(toolFolder, rstestTemplate);
copyFolder({
from: subFolder,
to: distFolder,
isMergePackageJson: true,
});
addAgentsMdSearchDirs(toolFolder);
},
},
{
value: 'react-compiler',
label: 'React Compiler - optimization',
order: 'pre',
when: (template) => template === 'react-js' || template === 'react-ts',
action: ({ templateName, distFolder }) => {
const toolFolder = path.join(root, 'template-react-compiler');
copyFolder({
from: path.join(toolFolder, templateName),
to: distFolder,
isMergePackageJson: true,
});
},
},
{
value: 'tailwindcss',
label: 'Tailwind CSS - styling',
action: async ({ distFolder }) => {
const from = path.join(root, 'template-tailwindcss');
copyFolder({
from: from,
to: distFolder,
isMergePackageJson: true,
});
// Insert tailwindcss import to main CSS file
const mainCssFile = ['index.css', 'App.css'];
for (const cssFile of mainCssFile) {
const filePath = path.join(distFolder, 'src', cssFile);
if (fs.existsSync(filePath)) {
const content = await fs.promises.readFile(filePath, 'utf-8');
await fs.promises.writeFile(
filePath,
`@import 'tailwindcss';\n\n${content}`,
);
break;
}
}
},
},
{
value: 'storybook',
label: 'Storybook - component development',
command: 'npm create storybook@latest -- --skip-install --features docs',
},
],
extraSkills: [
{
value: 'rsbuild-best-practices',
label: 'Rsbuild - best practices',
source: 'rstackjs/agent-skills',
},
{
value: 'rstest-best-practices',
label: 'Rstest - best practices',
source: 'rstackjs/agent-skills',
},
],
});