|
|
@@ -1,7 +1,7 @@
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
-import fs from 'node:fs';
|
|
|
-import fsExtra from 'fs-extra';
|
|
|
+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';
|
|
|
@@ -33,14 +33,14 @@ if (p.isCancel(languageType)) {
|
|
|
}
|
|
|
|
|
|
const templateOptions = [
|
|
|
- { value: 'vt', label: 'Vite + Tailwind' },
|
|
|
- { value: 'vu', label: `Vite + UnoCSS(${lang.hnay})` },
|
|
|
- { value: 'skt', label: `SvelteKit + Tailwind(${lang.hnay})` },
|
|
|
- { value: 'sku', label: `SvelteKit + UnoCSS(${lang.hnay})` },
|
|
|
- { value: 'vtt', label: `Vite + Tailwind + TypeScript(${lang.hnay})` },
|
|
|
- { value: 'vut', label: `Vite + UnoCSS+TypeScript(${lang.hnay})` },
|
|
|
- { value: 'sktt', label: `SvelteKit + Tailwind + TypeScript(${lang.hnay})` },
|
|
|
- { value: 'skut', label: `SvelteKit + UnoCSS + TypeScript(${lang.hnay})` },
|
|
|
+ { 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' },
|
|
|
];
|
|
|
|
|
|
// 选择一个模板
|
|
|
@@ -72,7 +72,7 @@ if (p.isCancel(template)) {
|
|
|
|
|
|
// 输入项目名称
|
|
|
// Enter the project name
|
|
|
-let projectName = await p.text({
|
|
|
+const projectName = await p.text({
|
|
|
message: bold(lang.pn),
|
|
|
initialValue: 'stdf-project',
|
|
|
validate: value => {
|
|
|
@@ -96,76 +96,66 @@ if (p.isCancel(projectName)) {
|
|
|
|
|
|
// 项目目录
|
|
|
// Project directory
|
|
|
-const projectDir = `${process.cwd()}/${projectName}`;
|
|
|
-
|
|
|
-const templatePaths = [
|
|
|
- { template: 'vt', path: './templates/vite-tailwind' },
|
|
|
- { template: 'vu', path: './templates/vite-uno' },
|
|
|
- { template: 'skt', path: './templates/sveltekit-tailwind' },
|
|
|
- { template: 'sku', path: './templates/sveltekit-uno' },
|
|
|
- { template: 'vtt', path: './templates/vite-tailwind-typescript' },
|
|
|
- { template: 'vut', path: './templates/vite-uno-typescript' },
|
|
|
- { template: 'sktt', path: './templates/sveltekit-tailwind-typescript' },
|
|
|
- { template: 'skut', path: './templates/sveltekit-uno-typescript' },
|
|
|
-];
|
|
|
+const projectDir = path.join(path.resolve(), projectName);
|
|
|
|
|
|
spinner.start('🚀 ' + lang.cfsing);
|
|
|
|
|
|
// 根据 template 的值,复制对应目录下的所有文件到当前目录
|
|
|
// According to the value of template, copy all files under the corresponding directory to the current directory
|
|
|
-templatePaths.forEach(item => {
|
|
|
- if (item.template === template) {
|
|
|
+templateOptions.forEach(async item => {
|
|
|
+ if (item.value === template) {
|
|
|
fs.mkdirSync(projectDir);
|
|
|
// 获取模板目录的绝对路径
|
|
|
// Get the absolute path of the template directory
|
|
|
- const filePath = new URL(item.path, import.meta.url).pathname;
|
|
|
+ const filePath = new URL(item.template, import.meta.url).pathname;
|
|
|
// 将 filePath 目录下的所有文件复制到 projectDir 目录下
|
|
|
- // Copy all files under the filePath directory to the projectDir directory
|
|
|
- fsExtra.copySync(filePath, projectDir, {
|
|
|
- filter: (src, dest) => {
|
|
|
- return !src.endsWith('/pnpm-lock.yaml');
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-spinner.stop();
|
|
|
-console.log(`🎉 ${lang.pcsucc}
|
|
|
+ // Copy all files under the filePath directory to the projectDir directory\
|
|
|
+ fs.copy(filePath, projectDir)
|
|
|
+ .then(() => {
|
|
|
+ spinner.stop();
|
|
|
+ console.log(`🎉 ${lang.pcsucc}
|
|
|
`);
|
|
|
|
|
|
-// 读取 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'));
|
|
|
-const versions = {
|
|
|
- vite: packageJson.devDependencies.vite,
|
|
|
- svelte: packageJson.devDependencies.svelte,
|
|
|
- tailwindcss: packageJson.devDependencies.tailwindcss,
|
|
|
- stdf: packageJson.devDependencies.stdf,
|
|
|
-};
|
|
|
-
|
|
|
-// 显示版本号
|
|
|
-// Display version number
|
|
|
-console.log(
|
|
|
- `📦 ${bold('Vite:')} ${cyan(versions.vite)} ${bold('Svelte:')} ${cyan(versions.svelte)} ${bold('Tailwind:')} ${cyan(
|
|
|
- versions.tailwindcss
|
|
|
- )} ${bold('STDF:')} ${cyan(versions.stdf)}
|
|
|
+ // 读取 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'));
|
|
|
+ const versions = {
|
|
|
+ vite: packageJson.devDependencies.vite,
|
|
|
+ svelte: packageJson.devDependencies.svelte,
|
|
|
+ tailwindcss: packageJson.devDependencies.tailwindcss,
|
|
|
+ stdf: packageJson.devDependencies.stdf,
|
|
|
+ };
|
|
|
+
|
|
|
+ // 显示版本号
|
|
|
+ // Display version number
|
|
|
+ console.log(
|
|
|
+ `📦 ${bold('Vite:')} ${cyan(versions.vite)} ${bold('Svelte:')} ${cyan(versions.svelte)} ${bold('Tailwind:')} ${cyan(
|
|
|
+ versions.tailwindcss
|
|
|
+ )} ${bold('STDF:')} ${cyan(versions.stdf)}
|
|
|
`
|
|
|
-);
|
|
|
+ );
|
|
|
|
|
|
-// 显示提示信息
|
|
|
-// Display prompt information
|
|
|
-console.log(
|
|
|
- `👉 ${bold(lang.tgs)}
|
|
|
+ // 显示提示信息
|
|
|
+ // Display prompt information
|
|
|
+ console.log(
|
|
|
+ `👉 ${bold(lang.tgs)}
|
|
|
|
|
|
${blue(`cd ${projectName}`)}
|
|
|
- ${blue('pnpm i or npm i or yarn')}
|
|
|
+ ${blue('pnpm i / npm i / yarn')}
|
|
|
${blue('npm run dev')}
|
|
|
`
|
|
|
-);
|
|
|
+ );
|
|
|
|
|
|
-// 显示配置主题色
|
|
|
-// Display configuration theme color
|
|
|
-console.log(
|
|
|
- `🎨 ${bold(lang.pcyt)}
|
|
|
+ // 显示配置主题色
|
|
|
+ // Display configuration theme color
|
|
|
+ console.log(
|
|
|
+ `🎨 ${bold(lang.pcyt)}
|
|
|
`
|
|
|
-);
|
|
|
+ );
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ spinner.stop();
|
|
|
+ console.error(111, err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+});
|