Prechádzať zdrojové kódy

Update cerate-stdf pack

杜府 3 rokov pred
rodič
commit
6708e4a0d9

+ 28 - 7
packages/create-stdf/package.json

@@ -1,25 +1,46 @@
 {
     "name": "create-stdf",
-    "version": "0.0.6",
+    "version": "0.0.7",
     "description": "A CLI for creating new STDF projects",
-    "main": "./index.js",
+    "main": "dist/index.js",
+    "module": "dist/index.mjs",
     "scripts": {
+        "build": "rollup -c",
         "test": "echo \"Error: no test specified\" && exit 1"
     },
-    "bin": "./bin.js",
+    "files": [
+        "dist/**",
+        "templates/**"
+    ],
+    "engines": {
+        "node": ">=14.14"
+    },
     "dependencies": {
         "@clack/prompts": "^0.6.3",
-        "kleur": "^4.1.5",
-        "fs-extra": "^11.1.1"
+        "fs-extra": "^11.1.1",
+        "kleur": "^4.1.5"
+    },
+    "devDependencies": {
+        "rollup": "^3.26.3",
+        "rollup-plugin-terser": "^7.0.2"
     },
     "keywords": [
         "svelte",
         "tailwind",
         "stdf",
         "cli",
-        "mobile"
+        "mobile",
+        "vite"
     ],
     "author": "dufu1991",
     "license": "MIT",
-    "type": "module"
+    "type": "module",
+    "homepage": "https://github.com/dufu1991/stdf/blob/main/packages/create-stdf/README.md",
+    "repository": {
+        "type": "git",
+        "url": "https://github.com/dufu1991/stdf/tree/main/packages/create-stdf"
+    },
+    "bugs": {
+        "url": "https://github.com/dufu1991/stdf/issues?q=is:issue+is:open+create-stdf"
+    }
 }

+ 11 - 0
packages/create-stdf/rollup.config.js

@@ -0,0 +1,11 @@
+import { terser } from 'rollup-plugin-terser';
+
+export default {
+    input: 'src/index.js',
+    output: [
+        { file: 'dist/index.js', format: 'es' },
+        { file: 'dist/index.mjs', format: 'esm' },
+    ],
+    external: ['path', 'fs-extra', '@clack/prompts', 'kleur/colors'],
+    plugins: [terser()],
+};

+ 22 - 16
packages/create-stdf/bin.js → packages/create-stdf/src/index.js

@@ -4,10 +4,13 @@ import fs from 'fs-extra';
 import path from 'node:path';
 import * as p from '@clack/prompts';
 import { bold, cyan, grey, red, blue } from 'kleur/colors';
-import * as langAll from './lang/index.mjs';
 
-const { version } = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
+import * as langAll from './lang';
 
+const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
+
+// 显示版本号
+// Display version number
 console.log(`
 ${grey(`create-stdf@${version}
 `)}`);
@@ -33,14 +36,14 @@ if (p.isCancel(languageType)) {
 }
 
 const templateOptions = [
-    { value: 'vt', label: 'Vite + Tailwind', template: './templates/vite-tailwind' },
-    { value: 'vu', label: `Vite + UnoCSS(${lang.hnay})`, template: './templates/vite-uno' },
-    { value: 'skt', label: `SvelteKit + Tailwind(${lang.hnay})`, template: './templates/sveltekit-tailwind' },
-    { value: 'sku', label: `SvelteKit + UnoCSS(${lang.hnay})`, template: './templates/sveltekit-uno' },
-    { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})`, template: './templates/vite-tailwind-typescript' },
-    { value: 'vut', label: `Vite + UnoCSS+TypeScript(${lang.hnay})`, template: './templates/vite-uno-typescript' },
-    { value: 'sktt', label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})`, template: './templates/sveltekit-tailwind-typescript' },
-    { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})`, template: './templates/sveltekit-uno-typescript' },
+    { value: 'vt', label: 'Vite + Tailwind', template: '../templates/vite-tailwind' },
+    { value: 'vu', label: `Vite + UnoCSS(${lang.hnay})`, template: '../templates/vite-uno' },
+    { value: 'skt', label: `SvelteKit + Tailwind(${lang.hnay})`, template: '../templates/sveltekit-tailwind' },
+    { value: 'sku', label: `SvelteKit + UnoCSS(${lang.hnay})`, template: '../templates/sveltekit-uno' },
+    { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})`, template: '../templates/vite-tailwind-typescript' },
+    { value: 'vut', label: `Vite + UnoCSS+TypeScript(${lang.hnay})`, template: '../templates/vite-uno-typescript' },
+    { value: 'sktt', label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})`, template: '../templates/sveltekit-tailwind-typescript' },
+    { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})`, template: '../templates/sveltekit-uno-typescript' },
 ];
 
 //  选择一个模板
@@ -119,11 +122,14 @@ templateOptions.forEach(async item => {
                 // 读取 package.json 文件,获得 vite svelte tailwind stdf 的版本号
                 // Read the package.json file to get the version number of vite svelte tailwind stdf
                 const packageJson = JSON.parse(fs.readFileSync(`${projectDir}/package.json`, 'utf-8'));
+
+                // packageJson 中的 devDependencies 里面的版本号去除 ^ 符号
+                // The version number in devDependencies in packageJson removes the ^ symbol
                 const versions = {
-                    vite: packageJson.devDependencies.vite,
-                    svelte: packageJson.devDependencies.svelte,
-                    tailwindcss: packageJson.devDependencies.tailwindcss,
-                    stdf: packageJson.devDependencies.stdf,
+                    vite: packageJson.devDependencies.vite.replace('^', ''),
+                    svelte: packageJson.devDependencies.svelte.replace('^', ''),
+                    tailwindcss: packageJson.devDependencies.tailwindcss.replace('^', ''),
+                    stdf: packageJson.devDependencies.stdf.replace('^', ''),
                 };
 
                 // 显示版本号
@@ -149,13 +155,13 @@ templateOptions.forEach(async item => {
                 // 显示配置主题色
                 // Display configuration theme color
                 console.log(
-                    `🎨 ${bold(lang.pcyt)}
+                    `🎨 ${grey(lang.pcyt)}
     `
                 );
             })
             .catch(err => {
                 spinner.stop();
-                console.error(111, err);
+                console.error(red(lang.cferror + '--' + err));
             });
     }
 });

+ 4 - 2
packages/create-stdf/lang/index.mjs → packages/create-stdf/src/lang.js

@@ -9,7 +9,8 @@ export const en_US = {
     cfsing: 'Creating file...',
     pcsucc: 'Project created successfully',
     tgs: 'To get started:',
-    pcyt: 'Please configure the theme color in the tailwind.config.js file',
+    pcyt: 'Tip: Please configure your color system in the tailwind.config.js file',
+    cferror: 'Failed to create file',
 };
 
 export const zh_CN = {
@@ -23,5 +24,6 @@ export const zh_CN = {
     cfsing: '正在创建文件...',
     pcsucc: '项目创建成功',
     tgs: '开始:',
-    pcyt: '请到 tailwind.config.js 文件内配置主题色',
+    pcyt: '提示:请到 tailwind.config.js 文件内配置你的颜色系统',
+    cferror: '创建文件失败',
 };