|
|
@@ -35,15 +35,21 @@ const argvLanguage = argv.language || argv.l;
|
|
|
|
|
|
// 语言列表
|
|
|
// Language list
|
|
|
-const languages = [
|
|
|
- { value: 'en_US', label: 'English' },
|
|
|
- { value: 'zh_CN', label: '简体中文' },
|
|
|
- { value: 'zh_TW', label: '繁體中文' },
|
|
|
- { value: 'ja_JP', label: '日本語' },
|
|
|
- { value: 'ko_KR', label: '한국어' },
|
|
|
- { value: 'es_ES', label: 'Español' },
|
|
|
- { value: 'ru_RU', label: 'Русский' },
|
|
|
-];
|
|
|
+const languages = [];
|
|
|
+
|
|
|
+// 循环 langAll 对象,将语言列表中的语言名字替换为对应的语言名字,且按照 sort 排序
|
|
|
+// Loop through the langAll object and replace the language name in the language list with the corresponding language name, and sort by sort
|
|
|
+for (const key in langAll) {
|
|
|
+ languages.push({
|
|
|
+ value: key,
|
|
|
+ label: langAll[key].name,
|
|
|
+ sort: langAll[key].sort,
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+// 按照 sort 排序
|
|
|
+// Sort by sort
|
|
|
+languages.sort((a, b) => a.sort - b.sort);
|
|
|
|
|
|
// 如果命令行参数中有语言,且语言列表中有该语言,使用该语言,否则使用英语
|
|
|
// If there is a language in the command line parameters and the language list has the language, use the language, otherwise use English
|
|
|
@@ -51,39 +57,29 @@ lang = argvLanguage && languages.find(item => item.value === argvLanguage) ? lan
|
|
|
|
|
|
// 模板列表
|
|
|
// Template list
|
|
|
-const templateOptionsStart = [
|
|
|
- { value: 'vt', label: 'Vite + Tailwind', template: 'vite-tailwind', pcyt: lang.pcyt_vt },
|
|
|
- { value: 'vu', label: 'Vite + UnoCSS', template: 'vite-uno', pcyt: lang.pcyt_vu },
|
|
|
- { value: 'skt', label: 'SvelteKit + Tailwind', template: 'sveltekit-tailwind', pcyt: lang.pcyt_vt },
|
|
|
- { value: 'sku', label: 'SvelteKit + UnoCSS', template: 'sveltekit-uno', pcyt: lang.pcyt_vu },
|
|
|
- { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})`, template: 'vite-tailwind-typescript', pcyt: lang.pcyt_vt },
|
|
|
- { value: 'vut', label: `Vite + UnoCSS + TypeScript(${lang.hnay})`, template: 'vite-uno-typescript', pcyt: lang.pcyt_vu },
|
|
|
- {
|
|
|
- value: 'sktt',
|
|
|
- label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})`,
|
|
|
- template: 'sveltekit-tailwind-typescript',
|
|
|
- pcyt: lang.pcyt_vt,
|
|
|
- },
|
|
|
- { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})`, template: 'sveltekit-uno-typescript', pcyt: lang.pcyt_vu },
|
|
|
+const templateOptions = [
|
|
|
+ { value: 'vt', label: 'Vite + Tailwind', template: 'vite-tailwind', finish: true },
|
|
|
+ { value: 'vu', label: 'Vite + UnoCSS', template: 'vite-uno', finish: true },
|
|
|
+ { value: 'skt', label: 'SvelteKit + Tailwind', template: 'sveltekit-tailwind', finish: true },
|
|
|
+ { value: 'sku', label: 'SvelteKit + UnoCSS', template: 'sveltekit-uno', finish: true },
|
|
|
+ { value: 'vtt', label: 'Vite + Tailwind + TypeScript', template: 'vite-tailwind-typescript', finish: false },
|
|
|
+ { value: 'vut', label: 'Vite + UnoCSS + TypeScript', template: 'vite-uno-typescript', finish: false },
|
|
|
+ { value: 'sktt', label: 'SvelteKit + Tailwind + TypeScript', template: 'sveltekit-tailwind-typescript', finish: false },
|
|
|
+ { value: 'skut', label: 'SvelteKit + UnoCSS + TypeScript', template: 'sveltekit-uno-typescript', finish: false },
|
|
|
];
|
|
|
|
|
|
// 如果命令行参数中有项目名称,但没有模板名称,直接使用默认模板 vt
|
|
|
// If there is a project name in the command line parameters, but no template name, use the default template vt directly
|
|
|
if (argvProjectName && !argvTemplate) {
|
|
|
- createFunc(argvProjectName, templateOptionsStart[0]);
|
|
|
+ createFunc(argvProjectName, templateOptions[0]);
|
|
|
}
|
|
|
// 如果命令行参数中有项目名称和模板名称,直接使用命令行参数中的值
|
|
|
// If there is a project name and template name in the command line parameters, use the value in the command line parameters directly
|
|
|
else if (argvProjectName && argvTemplate) {
|
|
|
- const item = templateOptionsStart.find(item => item.value === argvTemplate);
|
|
|
+ const item = templateOptions.find(item => item.value === argvTemplate);
|
|
|
if (!item) {
|
|
|
p.intro(red(lang.pectn));
|
|
|
- } else if (
|
|
|
- item.value === 'vtt' ||
|
|
|
- item.value === 'vut' ||
|
|
|
- item.value === 'sktt' ||
|
|
|
- item.value === 'skut'
|
|
|
- ) {
|
|
|
+ } else if (!item.finish) {
|
|
|
p.intro(red(item.label + ' ' + lang.hnay));
|
|
|
} else {
|
|
|
createFunc(argvProjectName, item);
|
|
|
@@ -100,21 +96,6 @@ else if (argvProjectName && argvTemplate) {
|
|
|
process.exit(0);
|
|
|
}
|
|
|
lang = langAll[languageType];
|
|
|
- const templateOptions = [
|
|
|
- { value: 'vt', label: 'Vite + Tailwind', template: 'vite-tailwind', pcyt: lang.pcyt_vt },
|
|
|
- { value: 'vu', label: 'Vite + UnoCSS', template: 'vite-uno', pcyt: lang.pcyt_vu },
|
|
|
- { value: 'skt', label: 'SvelteKit + Tailwind', template: 'sveltekit-tailwind', pcyt: lang.pcyt_vt },
|
|
|
- { value: 'sku', label: 'SvelteKit + UnoCSS', template: 'sveltekit-uno', pcyt: lang.pcyt_vu },
|
|
|
- { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})`, template: 'vite-tailwind-typescript', pcyt: lang.pcyt_vt },
|
|
|
- { value: 'vut', label: `Vite + UnoCSS + TypeScript(${lang.hnay})`, template: 'vite-uno-typescript', pcyt: lang.pcyt_vu },
|
|
|
- {
|
|
|
- value: 'sktt',
|
|
|
- label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})`,
|
|
|
- template: 'sveltekit-tailwind-typescript',
|
|
|
- pcyt: lang.pcyt_vt,
|
|
|
- },
|
|
|
- { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})`, template: 'sveltekit-uno-typescript', pcyt: lang.pcyt_vu },
|
|
|
- ];
|
|
|
|
|
|
// 选择一个模板
|
|
|
// Select a template
|
|
|
@@ -123,26 +104,26 @@ else if (argvProjectName && argvTemplate) {
|
|
|
options: templateOptions,
|
|
|
});
|
|
|
|
|
|
- // 直到选择的 template 是 vt / vu / skt / sku 为止,否则一直重新选择
|
|
|
- // Until the selected template is vt or vu, otherwise keep reselecting
|
|
|
- while (template !== 'vt' && template !== 'vu' && template !== 'skt' && template !== 'sku') {
|
|
|
+ if (p.isCancel(template)) {
|
|
|
+ p.cancel(red('⛔ ') + lang.oc);
|
|
|
+ process.exit(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 直到选择的 template 所在项 的 finish 为 true 为止,否则一直重新选择
|
|
|
+ // Until the finish of the selected template is true, otherwise keep reselecting
|
|
|
+ while (!templateOptions.find(item => item.value === template)?.finish) {
|
|
|
if (p.isCancel(template)) {
|
|
|
p.cancel(red('⛔ ') + lang.oc);
|
|
|
process.exit(0);
|
|
|
}
|
|
|
|
|
|
- p.intro(red(templateOptions.find(item => item.value === template).label + ' ' + lang.pca));
|
|
|
+ p.intro(red(templateOptions.find(item => item.value === template).label + ' ' + lang.hnay + ' ' + lang.pca));
|
|
|
template = await p.select({
|
|
|
message: bold(lang.psat),
|
|
|
options: templateOptions,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (p.isCancel(template)) {
|
|
|
- p.cancel(red('⛔ ') + lang.oc);
|
|
|
- process.exit(0);
|
|
|
- }
|
|
|
-
|
|
|
// 输入项目名称
|
|
|
// Enter the project name
|
|
|
const projectName = await p.text({
|
|
|
@@ -214,24 +195,30 @@ function createFunc(projectName, item) {
|
|
|
// Write the modified packageJson to the package.json file in the project
|
|
|
fs.writeFileSync(`${projectDir}/package.json`, JSON.stringify(packageJson, null, 4), 'utf-8');
|
|
|
|
|
|
+ // 根据 item.value 的值,判断是否使用了 @sveltejs/kit
|
|
|
+ // According to the value of item.value, determine whether @sveltejs/kit is used
|
|
|
+ const isHasKit = item.value === 'skt' || item.value === 'sku' || item.value === 'sktt' || item.value === 'skut';
|
|
|
+
|
|
|
+ // 根据 item.value 的值,判断使用 Tailwind 还是 UnoCSS
|
|
|
+ // According to the value of item.value, determine whether to use Tailwind or UnoCSS
|
|
|
+ const isHasUno = item.value === 'vu' || item.value === 'sku' || item.value === 'vut' || item.value === 'skut';
|
|
|
+
|
|
|
// 获得依赖的版本号
|
|
|
// get the version number of the dependency
|
|
|
- let versions = {};
|
|
|
- if (item.value === 'vt') {
|
|
|
- versions = {
|
|
|
- vite: packageJson.devDependencies.vite.replace('^', ''),
|
|
|
- svelte: packageJson.devDependencies.svelte.replace('^', ''),
|
|
|
- tailwindcss: packageJson.devDependencies.tailwindcss.replace('^', ''),
|
|
|
- stdf: packageJson.devDependencies.stdf.replace('^', ''),
|
|
|
- };
|
|
|
+ const versions = {
|
|
|
+ vite: packageJson.devDependencies.vite.replace('^', ''),
|
|
|
+ svelte: packageJson.devDependencies.svelte.replace('^', ''),
|
|
|
+ stdf: packageJson.devDependencies.stdf.replace('^', ''),
|
|
|
+ };
|
|
|
+
|
|
|
+ if (isHasKit) {
|
|
|
+ versions['@sveltejs/kit'] = packageJson.devDependencies['@sveltejs/kit'].replace('^', '');
|
|
|
}
|
|
|
- if (item.value === 'vu') {
|
|
|
- versions = {
|
|
|
- vite: packageJson.devDependencies.vite.replace('^', ''),
|
|
|
- svelte: packageJson.devDependencies.svelte.replace('^', ''),
|
|
|
- unocss: packageJson.devDependencies.unocss.replace('^', ''),
|
|
|
- stdf: packageJson.devDependencies.stdf.replace('^', ''),
|
|
|
- };
|
|
|
+
|
|
|
+ if (isHasUno) {
|
|
|
+ versions['unocss'] = packageJson.devDependencies.unocss.replace('^', '');
|
|
|
+ } else {
|
|
|
+ versions['tailwindcss'] = packageJson.devDependencies.tailwindcss.replace('^', '');
|
|
|
}
|
|
|
|
|
|
// 将 versions 的键值拼接为 bold('Vite:') cyan(versions.vite) bold('Svelte:') cyan(versions.svelte) 的形式
|
|
|
@@ -256,11 +243,10 @@ function createFunc(projectName, item) {
|
|
|
${blue('npm run dev')}
|
|
|
`
|
|
|
);
|
|
|
-
|
|
|
// 显示配置主题色
|
|
|
// Display configuration theme color
|
|
|
console.log(
|
|
|
- `🎨 ${grey(item.pcyt)}
|
|
|
+ `🎨 ${grey(isHasUno ? lang.pcyt_vu : lang.pcyt_vt)}
|
|
|
`
|
|
|
);
|
|
|
})
|