@jackie_qian/create-vue-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.mjs +5 -0
- package/dist/cli.js +348 -0
- package/dist/index.js +6 -0
- package/dist/scaffold.js +386 -0
- package/dist/templates/index.js +17 -0
- package/dist/templates/patchMain.js +42 -0
- package/dist/templates/renderAppWithRouter.js +6 -0
- package/dist/templates/renderEditorConfig.js +16 -0
- package/dist/templates/renderEnv.js +8 -0
- package/dist/templates/renderHomeView.js +8 -0
- package/dist/templates/renderJsConfig.js +17 -0
- package/dist/templates/renderMainJs.js +22 -0
- package/dist/templates/renderPagesIndex.js +8 -0
- package/dist/templates/renderRouter.js +35 -0
- package/dist/templates/renderStore.js +19 -0
- package/dist/templates/renderUnoConfig.js +19 -0
- package/dist/templates/renderViteConfig.js +118 -0
- package/dist/templates/renderViteConfigJs.js +104 -0
- package/dist/templates/renderVsCodeSettings.js +55 -0
- package/dist/templates.js +435 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/constants.js +20 -0
- package/dist/utils/util.js +168 -0
- package/package.json +39 -0
package/dist/scaffold.js
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
applyLatestStableRanges,
|
|
5
|
+
pathExists,
|
|
6
|
+
readJson,
|
|
7
|
+
removePath,
|
|
8
|
+
sortObjectKeys,
|
|
9
|
+
writeFileEnsureDir,
|
|
10
|
+
writeJson,
|
|
11
|
+
} from "./utils/util.js";
|
|
12
|
+
import {
|
|
13
|
+
renderEnv,
|
|
14
|
+
renderJsConfig,
|
|
15
|
+
renderMainJs,
|
|
16
|
+
renderRouter,
|
|
17
|
+
renderStore,
|
|
18
|
+
renderViteConfig,
|
|
19
|
+
} from "./templates/index.js";
|
|
20
|
+
export function getExampleTemplateDir() {
|
|
21
|
+
return new URL("../gen-js/", import.meta.url).pathname;
|
|
22
|
+
}
|
|
23
|
+
export async function updateTsconfigTypes(projectDir, typesToAdd) {
|
|
24
|
+
const candidates = [
|
|
25
|
+
path.join(projectDir, "tsconfig.app.json"),
|
|
26
|
+
path.join(projectDir, "tsconfig.json"),
|
|
27
|
+
];
|
|
28
|
+
for (const p of candidates) {
|
|
29
|
+
if (!(await pathExists(p))) continue;
|
|
30
|
+
const json = await readJson(p);
|
|
31
|
+
json.compilerOptions ??= {};
|
|
32
|
+
const current = Array.isArray(json.compilerOptions.types)
|
|
33
|
+
? json.compilerOptions.types
|
|
34
|
+
: [];
|
|
35
|
+
const merged = Array.from(new Set([...current, ...typesToAdd]));
|
|
36
|
+
json.compilerOptions.types = merged;
|
|
37
|
+
await writeJson(p, json);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function patchTsconfigApp(projectDir) {
|
|
42
|
+
const p = path.join(projectDir, "tsconfig.app.json");
|
|
43
|
+
if (!(await pathExists(p))) return;
|
|
44
|
+
const json = await readJson(p);
|
|
45
|
+
json.compilerOptions ??= {};
|
|
46
|
+
json.compilerOptions.baseUrl ??= ".";
|
|
47
|
+
json.compilerOptions.resolveJsonModule ??= true;
|
|
48
|
+
json.compilerOptions.paths ??= {};
|
|
49
|
+
json.compilerOptions.paths["#/*"] ??= ["./src/types/*"];
|
|
50
|
+
await writeJson(p, json);
|
|
51
|
+
}
|
|
52
|
+
export async function ensureCounterStoreInModules(targetDir, language) {
|
|
53
|
+
const ext = language === "ts" ? "ts" : "js";
|
|
54
|
+
const oldPath = path.join(targetDir, `src/stores/counter.${ext}`);
|
|
55
|
+
const newPath = path.join(targetDir, `src/stores/modules/counter.${ext}`);
|
|
56
|
+
const patchImportsInFile = async (filePath) => {
|
|
57
|
+
const raw = await fs.readFile(filePath, "utf8");
|
|
58
|
+
const next = raw.replace(
|
|
59
|
+
/((?:@\/|~\/|(?:\.\.?\/)+)stores\/)counter\b/g,
|
|
60
|
+
"$1modules/counter",
|
|
61
|
+
);
|
|
62
|
+
if (next !== raw) await fs.writeFile(filePath, next, "utf8");
|
|
63
|
+
};
|
|
64
|
+
const patchImportsInSrc = async () => {
|
|
65
|
+
const srcRoot = path.join(targetDir, "src");
|
|
66
|
+
if (!(await pathExists(srcRoot))) return;
|
|
67
|
+
const walk = async (dir) => {
|
|
68
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const fullPath = path.join(dir, entry.name);
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
await walk(fullPath);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!entry.isFile()) continue;
|
|
76
|
+
if (!/\.(?:[cm]?js|[cm]?ts|vue|jsx|tsx)$/.test(entry.name)) continue;
|
|
77
|
+
await patchImportsInFile(fullPath);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
await walk(srcRoot);
|
|
81
|
+
};
|
|
82
|
+
if (await pathExists(newPath)) {
|
|
83
|
+
if (await pathExists(oldPath)) await removePath(oldPath);
|
|
84
|
+
await patchImportsInSrc();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (await pathExists(oldPath)) {
|
|
88
|
+
const raw = await fs.readFile(oldPath, "utf8");
|
|
89
|
+
await writeFileEnsureDir(newPath, raw);
|
|
90
|
+
await removePath(oldPath);
|
|
91
|
+
await patchImportsInSrc();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await writeFileEnsureDir(
|
|
95
|
+
newPath,
|
|
96
|
+
`import { defineStore } from 'pinia'
|
|
97
|
+
import { computed, ref } from 'vue'
|
|
98
|
+
|
|
99
|
+
export const useCounterStore = defineStore('counter', () => {
|
|
100
|
+
const count = ref(0)
|
|
101
|
+
const doubleCount = computed(() => count.value * 2)
|
|
102
|
+
function increment() {
|
|
103
|
+
count.value++
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { count, doubleCount, increment }
|
|
107
|
+
})
|
|
108
|
+
`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
export async function applyExampleTemplateJs(targetDir, projectName, features) {
|
|
112
|
+
const pkgPath = path.join(targetDir, "package.json");
|
|
113
|
+
const pkg = await readJson(pkgPath);
|
|
114
|
+
pkg.name = projectName;
|
|
115
|
+
pkg.dependencies ??= {};
|
|
116
|
+
pkg.devDependencies ??= {};
|
|
117
|
+
pkg.scripts ??= {};
|
|
118
|
+
const removeDep = (obj, name) => {
|
|
119
|
+
if (obj[name]) delete obj[name];
|
|
120
|
+
};
|
|
121
|
+
if (!features.has("router")) removeDep(pkg.dependencies, "vue-router");
|
|
122
|
+
if (!features.has("pinia")) {
|
|
123
|
+
removeDep(pkg.dependencies, "pinia");
|
|
124
|
+
removeDep(pkg.dependencies, "pinia-plugin-persistedstate");
|
|
125
|
+
} else if (!features.has("piniaPersist")) {
|
|
126
|
+
removeDep(pkg.dependencies, "pinia-plugin-persistedstate");
|
|
127
|
+
}
|
|
128
|
+
if (!features.has("vant")) removeDep(pkg.dependencies, "vant");
|
|
129
|
+
if (!features.has("elementPlus")) removeDep(pkg.dependencies, "element-plus");
|
|
130
|
+
if (features.has("vant")) pkg.dependencies.vant ??= "^4.9.22";
|
|
131
|
+
if (features.has("elementPlus"))
|
|
132
|
+
pkg.dependencies["element-plus"] ??= "^2.7.6";
|
|
133
|
+
if (!features.has("pages"))
|
|
134
|
+
removeDep(pkg.devDependencies, "vite-plugin-pages");
|
|
135
|
+
if (!features.has("autoImport"))
|
|
136
|
+
removeDep(pkg.devDependencies, "unplugin-auto-import");
|
|
137
|
+
if (!features.has("components"))
|
|
138
|
+
removeDep(pkg.devDependencies, "unplugin-vue-components");
|
|
139
|
+
if (features.has("vant"))
|
|
140
|
+
pkg.devDependencies["@vant/auto-import-resolver"] ??= "^1.3.0";
|
|
141
|
+
if (!features.has("unocss")) removeDep(pkg.devDependencies, "unocss");
|
|
142
|
+
if (!features.has("eslintAntfu")) {
|
|
143
|
+
removeDep(pkg.devDependencies, "eslint");
|
|
144
|
+
removeDep(pkg.devDependencies, "@antfu/eslint-config");
|
|
145
|
+
}
|
|
146
|
+
if (!features.has("stylelint")) {
|
|
147
|
+
removeDep(pkg.devDependencies, "stylelint");
|
|
148
|
+
removeDep(pkg.devDependencies, "@stylistic/stylelint-config");
|
|
149
|
+
removeDep(pkg.devDependencies, "stylelint-config-recess-order");
|
|
150
|
+
removeDep(pkg.devDependencies, "stylelint-config-standard-scss");
|
|
151
|
+
removeDep(pkg.devDependencies, "stylelint-config-standard-vue");
|
|
152
|
+
removeDep(pkg.devDependencies, "stylelint-scss");
|
|
153
|
+
}
|
|
154
|
+
if (!features.has("sassEmbedded"))
|
|
155
|
+
removeDep(pkg.devDependencies, "sass-embedded");
|
|
156
|
+
if (features.has("eslintAntfu") && features.has("stylelint")) {
|
|
157
|
+
pkg.scripts.lint = "npm-run-all -s lint:eslint lint:stylelint";
|
|
158
|
+
pkg.scripts["lint:eslint"] = "eslint --fix";
|
|
159
|
+
pkg.scripts["lint:stylelint"] = 'stylelint "src/**/*.{css,scss,vue}" --fix';
|
|
160
|
+
} else if (features.has("eslintAntfu")) {
|
|
161
|
+
pkg.scripts.lint = "eslint --fix";
|
|
162
|
+
delete pkg.scripts["lint:eslint"];
|
|
163
|
+
delete pkg.scripts["lint:stylelint"];
|
|
164
|
+
} else if (features.has("stylelint")) {
|
|
165
|
+
pkg.scripts.lint = 'stylelint "src/**/*.{css,scss,vue}" --fix';
|
|
166
|
+
delete pkg.scripts["lint:eslint"];
|
|
167
|
+
delete pkg.scripts["lint:stylelint"];
|
|
168
|
+
} else {
|
|
169
|
+
delete pkg.scripts.lint;
|
|
170
|
+
delete pkg.scripts["lint:eslint"];
|
|
171
|
+
delete pkg.scripts["lint:stylelint"];
|
|
172
|
+
}
|
|
173
|
+
if (!features.has("eslintAntfu") || !features.has("stylelint"))
|
|
174
|
+
removeDep(pkg.devDependencies, "npm-run-all2");
|
|
175
|
+
if (features.has("gitHooks")) {
|
|
176
|
+
pkg.devDependencies["simple-git-hooks"] ??= "^2.11.1";
|
|
177
|
+
pkg.devDependencies["lint-staged"] ??= "^15.2.0";
|
|
178
|
+
pkg.scripts.prepare = "simple-git-hooks";
|
|
179
|
+
pkg["simple-git-hooks"] = {
|
|
180
|
+
"pre-commit": "pnpm lint-staged",
|
|
181
|
+
preserveUnused: true,
|
|
182
|
+
};
|
|
183
|
+
pkg["lint-staged"] = { "*.{js,ts,vue}": "pnpm lint" };
|
|
184
|
+
} else {
|
|
185
|
+
removeDep(pkg.devDependencies, "simple-git-hooks");
|
|
186
|
+
removeDep(pkg.devDependencies, "lint-staged");
|
|
187
|
+
if (pkg.scripts.prepare === "simple-git-hooks") delete pkg.scripts.prepare;
|
|
188
|
+
delete pkg["simple-git-hooks"];
|
|
189
|
+
delete pkg["lint-staged"];
|
|
190
|
+
}
|
|
191
|
+
if (pkg.scripts) pkg.scripts = sortObjectKeys(pkg.scripts);
|
|
192
|
+
if (pkg.dependencies) pkg.dependencies = sortObjectKeys(pkg.dependencies);
|
|
193
|
+
if (pkg.devDependencies)
|
|
194
|
+
pkg.devDependencies = sortObjectKeys(pkg.devDependencies);
|
|
195
|
+
await applyLatestStableRanges(pkg, targetDir);
|
|
196
|
+
if (pkg.dependencies) pkg.dependencies = sortObjectKeys(pkg.dependencies);
|
|
197
|
+
if (pkg.devDependencies)
|
|
198
|
+
pkg.devDependencies = sortObjectKeys(pkg.devDependencies);
|
|
199
|
+
await writeJson(pkgPath, pkg);
|
|
200
|
+
await writeFileEnsureDir(
|
|
201
|
+
path.join(targetDir, "vite.config.js"),
|
|
202
|
+
renderViteConfig("js", features),
|
|
203
|
+
);
|
|
204
|
+
await writeFileEnsureDir(
|
|
205
|
+
path.join(targetDir, "src/main.js"),
|
|
206
|
+
renderMainJs(features),
|
|
207
|
+
);
|
|
208
|
+
await writeFileEnsureDir(
|
|
209
|
+
path.join(targetDir, ".env.development"),
|
|
210
|
+
renderEnv("TITLE"),
|
|
211
|
+
);
|
|
212
|
+
await writeFileEnsureDir(
|
|
213
|
+
path.join(targetDir, ".env.production"),
|
|
214
|
+
renderEnv("TITLE"),
|
|
215
|
+
);
|
|
216
|
+
await writeFileEnsureDir(
|
|
217
|
+
path.join(targetDir, "jsconfig.json"),
|
|
218
|
+
renderJsConfig(),
|
|
219
|
+
);
|
|
220
|
+
if (!features.has("unocss"))
|
|
221
|
+
await removePath(path.join(targetDir, "uno.config.js"));
|
|
222
|
+
if (!features.has("router")) {
|
|
223
|
+
await removePath(path.join(targetDir, "src/router"));
|
|
224
|
+
await writeFileEnsureDir(
|
|
225
|
+
path.join(targetDir, "src/App.vue"),
|
|
226
|
+
`<template>
|
|
227
|
+
<div>
|
|
228
|
+
<h1>Hello World</h1>
|
|
229
|
+
</div>
|
|
230
|
+
</template>
|
|
231
|
+
`,
|
|
232
|
+
);
|
|
233
|
+
} else {
|
|
234
|
+
const router = renderRouter("js", features.has("pages"));
|
|
235
|
+
await writeFileEnsureDir(
|
|
236
|
+
path.join(targetDir, router.fileName),
|
|
237
|
+
router.content,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (!features.has("pinia")) {
|
|
241
|
+
await removePath(path.join(targetDir, "src/stores"));
|
|
242
|
+
} else {
|
|
243
|
+
const store = renderStore("js", features.has("piniaPersist"));
|
|
244
|
+
await writeFileEnsureDir(
|
|
245
|
+
path.join(targetDir, store.fileName),
|
|
246
|
+
store.content,
|
|
247
|
+
);
|
|
248
|
+
await ensureCounterStoreInModules(targetDir, "js");
|
|
249
|
+
}
|
|
250
|
+
if (!features.has("eslintAntfu"))
|
|
251
|
+
await removePath(path.join(targetDir, "eslint.config.js"));
|
|
252
|
+
if (!features.has("stylelint"))
|
|
253
|
+
await removePath(path.join(targetDir, "stylelint.config.js"));
|
|
254
|
+
if (!features.has("autoImport"))
|
|
255
|
+
await removePath(path.join(targetDir, "src/types/auto-import.d.ts"));
|
|
256
|
+
if (!features.has("components"))
|
|
257
|
+
await removePath(path.join(targetDir, "src/types/components.d.ts"));
|
|
258
|
+
if (!features.has("sassEmbedded"))
|
|
259
|
+
await removePath(path.join(targetDir, "src/assets/styles"));
|
|
260
|
+
}
|
|
261
|
+
export async function writeEslintConfig(targetDir, features) {
|
|
262
|
+
if (!features.has("eslintAntfu")) return;
|
|
263
|
+
const withAutoImportGlobals = features.has("autoImport");
|
|
264
|
+
const autoImportLine = withAutoImportGlobals
|
|
265
|
+
? `import autoImportGlobals from './.eslintrc-auto-import.json' with { type: 'json' }\n\n`
|
|
266
|
+
: "";
|
|
267
|
+
const autoImportConfig = withAutoImportGlobals
|
|
268
|
+
? `,
|
|
269
|
+
{
|
|
270
|
+
languageOptions: {
|
|
271
|
+
globals: autoImportGlobals.globals
|
|
272
|
+
}
|
|
273
|
+
}`
|
|
274
|
+
: "";
|
|
275
|
+
await writeFileEnsureDir(
|
|
276
|
+
path.join(targetDir, "eslint.config.js"),
|
|
277
|
+
`import antfu from '@antfu/eslint-config'
|
|
278
|
+
${autoImportLine}export default antfu(
|
|
279
|
+
{
|
|
280
|
+
type: 'app',
|
|
281
|
+
ignores: [
|
|
282
|
+
'public',
|
|
283
|
+
'dist',
|
|
284
|
+
'node_modules'
|
|
285
|
+
]
|
|
286
|
+
}${autoImportConfig}
|
|
287
|
+
)
|
|
288
|
+
`,
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
export async function writeStylelintConfig(targetDir, features) {
|
|
292
|
+
if (!features.has("stylelint")) return;
|
|
293
|
+
await writeFileEnsureDir(
|
|
294
|
+
path.join(targetDir, "stylelint.config.js"),
|
|
295
|
+
`export default {
|
|
296
|
+
extends: [
|
|
297
|
+
'stylelint-config-standard-scss',
|
|
298
|
+
'stylelint-config-standard-vue/scss',
|
|
299
|
+
'stylelint-config-recess-order',
|
|
300
|
+
'@stylistic/stylelint-config'
|
|
301
|
+
],
|
|
302
|
+
plugins: [
|
|
303
|
+
'stylelint-scss'
|
|
304
|
+
],
|
|
305
|
+
rules: {
|
|
306
|
+
'at-rule-no-unknown': null,
|
|
307
|
+
'no-descending-specificity': null,
|
|
308
|
+
'property-no-unknown': null,
|
|
309
|
+
'font-family-no-missing-generic-family-keyword': null,
|
|
310
|
+
'selector-class-pattern': null,
|
|
311
|
+
'function-no-unknown': [
|
|
312
|
+
true,
|
|
313
|
+
{
|
|
314
|
+
ignoreFunctions: [
|
|
315
|
+
'v-bind',
|
|
316
|
+
'map-get',
|
|
317
|
+
'lighten',
|
|
318
|
+
'darken'
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
],
|
|
322
|
+
'selector-pseudo-element-no-unknown': [
|
|
323
|
+
true,
|
|
324
|
+
{
|
|
325
|
+
ignorePseudoElements: [
|
|
326
|
+
'/^view-transition/'
|
|
327
|
+
]
|
|
328
|
+
}
|
|
329
|
+
],
|
|
330
|
+
'scss/double-slash-comment-empty-line-before': null,
|
|
331
|
+
'scss/no-global-function-names': null,
|
|
332
|
+
'@stylistic/max-line-length': null,
|
|
333
|
+
'@stylistic/block-closing-brace-newline-after': [
|
|
334
|
+
'always',
|
|
335
|
+
{
|
|
336
|
+
ignoreAtRules: [
|
|
337
|
+
'if',
|
|
338
|
+
'else'
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
},
|
|
343
|
+
allowEmptyInput: true,
|
|
344
|
+
ignoreFiles: [
|
|
345
|
+
'node_modules/**/*',
|
|
346
|
+
'dist*/**/*'
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
export async function patchMainFile(mainPath, patched) {
|
|
353
|
+
await fs.writeFile(mainPath, patched, "utf8");
|
|
354
|
+
}
|
|
355
|
+
export async function loadPackageJson(projectPkgPath) {
|
|
356
|
+
const pkg = await readJson(projectPkgPath);
|
|
357
|
+
pkg.scripts ??= {};
|
|
358
|
+
pkg.dependencies ??= {};
|
|
359
|
+
pkg.devDependencies ??= {};
|
|
360
|
+
return pkg;
|
|
361
|
+
}
|
|
362
|
+
export function addDep(obj, name, version) {
|
|
363
|
+
if (!obj[name]) obj[name] = version;
|
|
364
|
+
}
|
|
365
|
+
export async function finalizePackageJson(pkg, projectDir) {
|
|
366
|
+
if (pkg.scripts) pkg.scripts = sortObjectKeys(pkg.scripts);
|
|
367
|
+
if (pkg.dependencies) pkg.dependencies = sortObjectKeys(pkg.dependencies);
|
|
368
|
+
if (pkg.devDependencies)
|
|
369
|
+
pkg.devDependencies = sortObjectKeys(pkg.devDependencies);
|
|
370
|
+
await applyLatestStableRanges(pkg, projectDir);
|
|
371
|
+
if (pkg.dependencies) pkg.dependencies = sortObjectKeys(pkg.dependencies);
|
|
372
|
+
if (pkg.devDependencies)
|
|
373
|
+
pkg.devDependencies = sortObjectKeys(pkg.devDependencies);
|
|
374
|
+
}
|
|
375
|
+
export async function writePackageJson(projectPkgPath, pkg) {
|
|
376
|
+
await writeJson(projectPkgPath, pkg);
|
|
377
|
+
}
|
|
378
|
+
export async function readTextFile(filePath) {
|
|
379
|
+
return fs.readFile(filePath, "utf8");
|
|
380
|
+
}
|
|
381
|
+
export async function writeTextFile(filePath, content) {
|
|
382
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
383
|
+
}
|
|
384
|
+
export function renderStoreFile(language, features) {
|
|
385
|
+
return renderStore(language, features.has("piniaPersist"));
|
|
386
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { patchMain } from "./patchMain.js";
|
|
2
|
+
export { renderAppWithRouter } from "./renderAppWithRouter.js";
|
|
3
|
+
export { renderEditorConfig } from "./renderEditorConfig.js";
|
|
4
|
+
export { renderEnv } from "./renderEnv.js";
|
|
5
|
+
export { renderHomeView } from "./renderHomeView.js";
|
|
6
|
+
export { renderJsConfig } from "./renderJsConfig.js";
|
|
7
|
+
export { renderMainJs } from "./renderMainJs.js";
|
|
8
|
+
export { renderPagesIndex } from "./renderPagesIndex.js";
|
|
9
|
+
export { renderRouter } from "./renderRouter.js";
|
|
10
|
+
export { renderStore } from "./renderStore.js";
|
|
11
|
+
export { renderUnoConfig } from "./renderUnoConfig.js";
|
|
12
|
+
export {
|
|
13
|
+
renderVsCodeExtensions,
|
|
14
|
+
renderVsCodeSettings,
|
|
15
|
+
} from "./renderVsCodeSettings.js";
|
|
16
|
+
export { renderViteConfig } from "./renderViteConfig.js";
|
|
17
|
+
export { renderViteConfigJs } from "./renderViteConfigJs.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function patchMain(content, options) {
|
|
2
|
+
const mainImports = [];
|
|
3
|
+
const usesCreateApp = content.includes("createApp(");
|
|
4
|
+
if (!usesCreateApp) return content;
|
|
5
|
+
if (options.useUno && !content.includes("virtual:uno.css"))
|
|
6
|
+
mainImports.push(`import 'virtual:uno.css'`);
|
|
7
|
+
if (options.useVant && !content.includes("vant/lib/index.css"))
|
|
8
|
+
mainImports.push(`import 'vant/lib/index.css'`);
|
|
9
|
+
if (
|
|
10
|
+
options.useElementPlus &&
|
|
11
|
+
!content.includes("element-plus/dist/index.css")
|
|
12
|
+
)
|
|
13
|
+
mainImports.push(`import 'element-plus/dist/index.css'`);
|
|
14
|
+
if (options.useRouter && !content.includes("from './router'"))
|
|
15
|
+
mainImports.push(`import router from './router'`);
|
|
16
|
+
if (options.useStore && !content.includes("from './stores'"))
|
|
17
|
+
mainImports.push(`import store from './stores'`);
|
|
18
|
+
const importBlock = mainImports.length ? `${mainImports.join("\n")}\n` : "";
|
|
19
|
+
const useBlock = [
|
|
20
|
+
options.useStore ? "app.use(store)" : "",
|
|
21
|
+
options.useRouter ? "app.use(router)" : "",
|
|
22
|
+
]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join("\n");
|
|
25
|
+
const withUse = useBlock ? `\n${useBlock}\n` : "\n";
|
|
26
|
+
const replaced = content.replace(
|
|
27
|
+
/import\s+\{\s*createApp\s*\}\s+from\s+'vue'\s*\n/,
|
|
28
|
+
(match) => `${match}${importBlock}`,
|
|
29
|
+
);
|
|
30
|
+
if (useBlock) {
|
|
31
|
+
return replaced
|
|
32
|
+
.replace(/app\.mount\('#app'\)\s*\n?/, `app.mount('#app')\n`)
|
|
33
|
+
.replace(
|
|
34
|
+
/const\s+app\s*=\s*createApp\(App\)\s*\n([\s\S]*?)app\.mount\('#app'\)/,
|
|
35
|
+
(m, between) => {
|
|
36
|
+
if (between.includes("app.use(")) return m;
|
|
37
|
+
return m.replace("app.mount('#app')", `${withUse}app.mount('#app')`);
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return replaced;
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function renderEditorConfig() {
|
|
2
|
+
return `root = true
|
|
3
|
+
|
|
4
|
+
[*]
|
|
5
|
+
charset = utf-8
|
|
6
|
+
indent_style = space
|
|
7
|
+
indent_size = 2
|
|
8
|
+
end_of_line = lf
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
insert_final_newline = true
|
|
11
|
+
|
|
12
|
+
[*.md]
|
|
13
|
+
max_line_length = off
|
|
14
|
+
trim_trailing_whitespace = false
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function renderJsConfig() {
|
|
2
|
+
return `{
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"baseUrl": "./",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "Bundler",
|
|
8
|
+
"paths": {
|
|
9
|
+
"@/*": ["src/*"]
|
|
10
|
+
},
|
|
11
|
+
"allowJs": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/*.js", "src/**/*.js", "src/**/*.vue", "src/**/*.d.ts"],
|
|
14
|
+
"exclude": ["node_modules"]
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function renderMainJs(featureSet) {
|
|
2
|
+
const lines = [];
|
|
3
|
+
lines.push(`import { createApp } from 'vue'`);
|
|
4
|
+
lines.push("");
|
|
5
|
+
lines.push(`import App from './App.vue'`);
|
|
6
|
+
if (featureSet.has("router")) lines.push(`import Router from './router'`);
|
|
7
|
+
if (featureSet.has("pinia")) lines.push(`import Pinia from './stores/index'`);
|
|
8
|
+
if (featureSet.has("vant")) lines.push(`import 'vant/lib/index.css'`);
|
|
9
|
+
if (featureSet.has("elementPlus"))
|
|
10
|
+
lines.push(`import 'element-plus/dist/index.css'`);
|
|
11
|
+
if (featureSet.has("sassEmbedded"))
|
|
12
|
+
lines.push(`import './assets/styles/main.scss'`);
|
|
13
|
+
lines.push("");
|
|
14
|
+
lines.push(`const app = createApp(App)`);
|
|
15
|
+
lines.push("");
|
|
16
|
+
if (featureSet.has("router")) lines.push(`app.use(Router)`);
|
|
17
|
+
if (featureSet.has("pinia")) lines.push(`app.use(Pinia)`);
|
|
18
|
+
lines.push("");
|
|
19
|
+
lines.push(`app.mount('#app')`);
|
|
20
|
+
lines.push("");
|
|
21
|
+
return `${lines.join("\n")}`;
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function renderRouter(language, usePages) {
|
|
2
|
+
const ext = language === "ts" ? "ts" : "js";
|
|
3
|
+
if (usePages) {
|
|
4
|
+
return {
|
|
5
|
+
fileName: `src/router/index.${ext}`,
|
|
6
|
+
content: `import { createRouter, createWebHistory } from 'vue-router'
|
|
7
|
+
import routes from '~pages'
|
|
8
|
+
|
|
9
|
+
const router = createRouter({
|
|
10
|
+
history: createWebHistory(),
|
|
11
|
+
routes
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export default router
|
|
15
|
+
`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const importRoutes = `import IndexView from '../views/index.vue'`;
|
|
19
|
+
const routesDecl = `[
|
|
20
|
+
{ name: 'Index', path: '/', component: IndexView }
|
|
21
|
+
]`;
|
|
22
|
+
return {
|
|
23
|
+
fileName: `src/router/index.${ext}`,
|
|
24
|
+
content: `import { createRouter, createWebHistory } from 'vue-router'
|
|
25
|
+
${importRoutes}
|
|
26
|
+
|
|
27
|
+
const router = createRouter({
|
|
28
|
+
history: createWebHistory(),
|
|
29
|
+
routes: ${routesDecl}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export default router
|
|
33
|
+
`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function renderStore(language, persisted) {
|
|
2
|
+
const ext = language === "ts" ? "ts" : "js";
|
|
3
|
+
const lines = [];
|
|
4
|
+
lines.push(`import { createPinia } from 'pinia'`);
|
|
5
|
+
if (persisted)
|
|
6
|
+
lines.push(
|
|
7
|
+
`import { createPersistedState } from 'pinia-plugin-persistedstate'`,
|
|
8
|
+
);
|
|
9
|
+
lines.push("");
|
|
10
|
+
lines.push("const store = createPinia()");
|
|
11
|
+
if (persisted) lines.push("store.use(createPersistedState())");
|
|
12
|
+
lines.push("");
|
|
13
|
+
lines.push("export default store");
|
|
14
|
+
lines.push("");
|
|
15
|
+
return {
|
|
16
|
+
fileName: `src/stores/index.${ext}`,
|
|
17
|
+
content: `${lines.join("\n")}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function renderUnoConfig(language) {
|
|
2
|
+
return `import { defineConfig, presetAttributify, presetWind3, transformerDirectives } from 'unocss'
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
presets: [
|
|
6
|
+
presetAttributify(),
|
|
7
|
+
presetWind3()
|
|
8
|
+
],
|
|
9
|
+
transformers: [
|
|
10
|
+
transformerDirectives()
|
|
11
|
+
],
|
|
12
|
+
layers: {
|
|
13
|
+
components: -1,
|
|
14
|
+
default: 1,
|
|
15
|
+
utilities: 2
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
`;
|
|
19
|
+
}
|