dufu1991 3 rokov pred
rodič
commit
f30b5457d0

+ 1 - 1
packages/create-stdf/package.json

@@ -1,6 +1,6 @@
 {
     "name": "create-stdf",
-    "version": "0.0.43",
+    "version": "0.0.44",
     "description": "A CLI for creating new STDF projects",
     "bin": {
         "create-stdf": "index.js"

+ 58 - 72
packages/create-stdf/src/index.js

@@ -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)}
     `
             );
         })

+ 21 - 2
packages/create-stdf/src/lang.js

@@ -1,5 +1,7 @@
 // 英语 english
 export const en_US = {
+    sort: 0,
+    name: 'English',
     hnay: 'Has not adapted yet',
     pn: 'Please enter the project name',
     pncbne: 'Project name cannot be empty',
@@ -18,6 +20,8 @@ export const en_US = {
 
 // 简体中文 chinese
 export const zh_CN = {
+    sort: 1,
+    name: '简体中文',
     hnay: '暂未适配',
     pn: '请输入项目名称',
     pncbne: '项目名称不能为空',
@@ -36,6 +40,8 @@ export const zh_CN = {
 
 // 繁體中文 chinese traditional
 export const zh_TW = {
+    sort: 2,
+    name: '繁體中文',
     hnay: '暫未適配',
     pn: '請輸入項目名稱',
     pncbne: '項目名稱不能為空',
@@ -54,6 +60,8 @@ export const zh_TW = {
 
 // 日语 japanese
 export const ja_JP = {
+    sort: 3,
+    name: '日本語',
     hnay: 'まだ適応されていません',
     pn: 'プロジェクト名を入力してください',
     pncbne: 'プロジェクト名は空にできません',
@@ -72,6 +80,8 @@ export const ja_JP = {
 
 // 韩语 korean
 export const ko_KR = {
+    sort: 4,
+    name: '한국어',
     hnay: '아직 적응하지 못했습니다',
     pn: '프로젝트 이름을 입력하십시오',
     pncbne: '프로젝트 이름은 비워 둘 수 없습니다',
@@ -90,6 +100,8 @@ export const ko_KR = {
 
 // 西班牙语 spanish
 export const es_ES = {
+    sort: 5,
+    name: 'Español',
     hnay: 'Aún no se ha adaptado',
     pn: 'Por favor ingrese el nombre del proyecto',
     pncbne: 'El nombre del proyecto no puede estar vacío',
@@ -108,6 +120,8 @@ export const es_ES = {
 
 // 俄语 russian
 export const ru_RU = {
+    sort: 6,
+    name: 'Русский',
     hnay: 'Еще не адаптировано',
     pn: 'Пожалуйста, введите название проекта',
     pncbne: 'Название проекта не может быть пустым',
@@ -126,7 +140,9 @@ export const ru_RU = {
 
 // 法语 french
 export const fr_FR = {
-    hnay: 'N\'a pas encore adapté',
+    sort: 7,
+    name: 'Français',
+    hnay: "N'a pas encore adapté",
     pn: 'Veuillez saisir le nom du projet',
     pncbne: 'Le nom du projet ne peut pas être vide',
     pane: 'Le nom du projet existe déjà',
@@ -144,6 +160,8 @@ export const fr_FR = {
 
 // 德语 german
 export const de_DE = {
+    sort: 8,
+    name: 'Deutsch',
     hnay: 'Noch nicht angepasst',
     pn: 'Bitte geben Sie den Projektnamen ein',
     pncbne: 'Projektname darf nicht leer sein',
@@ -162,6 +180,8 @@ export const de_DE = {
 
 // 意大利语 italian
 export const it_IT = {
+    sort: 9,
+    name: 'Italiano',
     hnay: 'Non ancora adattato',
     pn: 'Inserisci il nome del progetto',
     pncbne: 'Il nome del progetto non può essere vuoto',
@@ -177,4 +197,3 @@ export const it_IT = {
     cferror: 'Impossibile creare il file',
     pectn: 'Inserisci il nome del modello corretto!',
 };
-