Pārlūkot izejas kodu

[create]更新 create-stdf 版本至 0.2.7,优化 README 文件中的命令示例,修正命令行参数描述,添加获取最新版本号的功能。

dufu1991 1 gadu atpakaļ
vecāks
revīzija
11e6ae2726

+ 13 - 37
packages/create-stdf/README.md

@@ -34,7 +34,7 @@ yarn create stdf@latest
 
 ...and follow the prompts.
 
-You can also directly specify the project name and the template you want to use via additional command line options. For example, to create a new project named my-app using the **SvelteKit & Tailwind & TypeScript & STDF** template, run:
+You can also directly specify the project name and the template you want to use via additional command line options. For example: create a new project named my-app using the **SvelteKit & Tailwind & TypeScript & STDF** template, run:
 
 <!-- :::code-groups -->
 <!-- pnpm -->
@@ -58,35 +58,35 @@ yarn create stdf@latest my-app
 ```
 <!-- ::: -->
 
-If you want to use the **SvelteKit & Tailwind & STDF** template, run:
+Prompt language is Simplified Chinese, use **SvelteKit & Tailwind & STDF** template, use Iconify to manage icons, create a new project named my-app, run:
 
 <!-- :::code-groups -->
 <!-- pnpm -->
 ```sh
-pnpm create stdf@latest my-app --template skt
+pnpm create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # or
-pnpm create stdf@latest my-app -t skt
+pnpm create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- :: -->
 <!-- npm -->
 ```sh
-npm create stdf@latest my-app --template skt
+npm create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # or
-npm create stdf@latest my-app -t skt
+npm create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- :: -->
 <!-- bun -->
 ```sh
-bun create stdf@latest my-app --template skt
+bun create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # or
-bun create stdf@latest my-app -t skt
+bun create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- :: -->
 <!-- yarn -->
 ```sh
-yarn create stdf@latest my-app --template skt
+yarn create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # or
-yarn create stdf@latest my-app -t skt
+yarn create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- ::: -->
 
@@ -95,9 +95,9 @@ yarn create stdf@latest my-app -t skt
 | Option          | Optional values   | Default | Description                                    |
 | --------------- | ------ | ------- | ---------------------------------------------- |
 | -               | -       | -       | The name of the project, you can direct input. |
-| -t / --template | sktt/skt/skut/sku | sktt | The template to use.                           |
-| -l / --language | en_US/zh_CN/zh_TW/ja_JP/ko_KR/es_ES/ru_RU/fr_FR/de_DE/it_IT | en_US | The language of the prompts.                   |
-| -i / --icon-usage | stdf-icon/iconify/both/none | stdf-icon | The icon usage method.                         |
+| --t / --template | sktt/skt/skut/sku | sktt | The template to use.                           |
+| --l / --language | en_US/zh_CN/zh_TW/ja_JP/ko_KR/es_ES/ru_RU/fr_FR/de_DE/it_IT | en_US | The language of the prompts.                   |
+| --i / --icon-usage | stdf-icon/iconify/both/none | stdf-icon | The icon usage method.                         |
 
 # Template presets
 
@@ -132,30 +132,6 @@ yarn create stdf@latest my-app -t skt
 | both      | Use both rollup-plugin-stdf-icon and iconify to manage icons. |
 | none      | Do not use any tool to manage icons.                                       |
 
-For example:
-
-<!-- :::code-groups -->
-<!-- pnpm -->
-```sh
-pnpm create stdf@latest my-app -l zh_CN
-```
-<!-- :: -->
-<!-- npm -->
-```sh
-npm create stdf@latest my-app -l zh_CN
-```
-<!-- :: -->
-<!-- bun -->
-```sh
-bun create stdf@latest my-app -l zh_CN
-```
-<!-- :: -->
-<!-- yarn -->
-```sh
-yarn create stdf@latest my-app -l zh_CN
-```
-<!-- ::: -->
-
 # License
 
 This project is licensed under the [MIT License](https://github.com/any-tdf/stdf/blob/main/LICENSE).

+ 12 - 36
packages/create-stdf/README_CN.md

@@ -34,7 +34,7 @@ yarn create stdf@latest
 
 ...然后按照提示进行操作。
 
-你也可以通过额外的命令行选项直接指定项目名称和要使用的模板。例如,如果要使用 **SvelteKit & Tailwind & TypeScript & STDF** 模板创建一个名为 my-app 的新项目,请运行:
+你也可以通过额外的命令行选项直接指定项目名称与默认参数。例如,如果要使用 **SvelteKit & Tailwind & TypeScript & STDF** 模板创建一个名为 my-app 的新项目,请运行:
 
 <!-- :::code-groups -->
 <!-- pnpm -->
@@ -63,30 +63,30 @@ yarn create stdf@latest my-app
 <!-- :::code-groups -->
 <!-- pnpm -->
 ```sh
-pnpm create stdf@latest my-app --template skt -l zh_CN -i iconify
+pnpm create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # 或
-pnpm create stdf@latest my-app -t skt -l zh_CN -i iconify
+pnpm create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- :: -->
 <!-- npm -->
 ```sh
-npm create stdf@latest my-app --template skt -l zh_CN -i iconify
+npm create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # 或
-npm create stdf@latest my-app -t skt -l zh_CN -i iconify
+npm create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- :: -->
 <!-- bun -->
 ```sh
-bun create stdf@latest my-app --template skt -l zh_CN -i iconify
+bun create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # 或
-bun create stdf@latest my-app -t skt -l zh_CN -i iconify
+bun create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- :: -->
 <!-- yarn -->
 ```sh
-yarn create stdf@latest my-app --template skt -l zh_CN -i iconify
+yarn create stdf@latest my-app --template skt --language zh_CN --icon-usage iconify
 # 或
-yarn create stdf@latest my-app -t skt -l zh_CN -i iconify
+yarn create stdf@latest my-app --t skt --l zh_CN --i iconify
 ```
 <!-- ::: -->
 
@@ -95,9 +95,9 @@ yarn create stdf@latest my-app -t skt -l zh_CN -i iconify
 | 命令              | 可选值                                                                                       | 默认          | 描述                     |
 | ----------------- | ------------------------------------------------------------------------------------------ | ------------- | ------------------------ |
 | -                 | -                                                                                     | -             | 项目名称,可以直接输入。 |
-| -t / --template   | sktt/skt/skut/sku                                                                         | sktt          | 要使用的模板。           |
-| -l / --language   | en_US/zh_CN/zh_TW/ja_JP/ko_KR/es_ES/ru_RU/fr_FR/de_DE/it_IT                             | en_US         | 提示语言。               |
-| -i / --icon-usage | stdf-icon/iconify/both/none                                                               | stdf-icon     | 图标使用方式。           |
+| --t / --template   | sktt/skt/skut/sku                                                                         | sktt          | 要使用的模板。           |
+| --l / --language   | en_US/zh_CN/zh_TW/ja_JP/ko_KR/es_ES/ru_RU/fr_FR/de_DE/it_IT                             | en_US         | 提示语言。               |
+| --i / --icon-usage | stdf-icon/iconify/both/none                                                               | stdf-icon     | 图标使用方式。           |
 
 # 模板预设
 
@@ -132,30 +132,6 @@ yarn create stdf@latest my-app -t skt -l zh_CN -i iconify
 | both      | 同时使用 rollup-plugin-stdf-icon 和 iconify 插件管理图标。 |
 | none      | 不使用任何工具管理图标。                                       |
 
-例如:
-
-<!-- :::code-groups -->
-<!-- pnpm -->
-```sh
-pnpm create stdf@latest my-app -l zh_CN
-```
-<!-- :: -->
-<!-- npm -->
-```sh
-npm create stdf@latest my-app -l zh_CN
-```
-<!-- :: -->
-<!-- bun -->
-```sh
-bun create stdf@latest my-app -l zh_CN
-```
-<!-- :: -->
-<!-- yarn -->
-```sh
-yarn create stdf@latest my-app -l zh_CN
-```
-<!-- ::: -->
-
 # 许可证
 
 本项目基于 [MIT 许可证](https://github.com/any-tdf/stdf/blob/main/LICENSE)。

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

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

+ 1 - 1
packages/create-stdf/rollup.config.js

@@ -3,6 +3,6 @@ import terser from '@rollup/plugin-terser';
 export default {
 	input: 'src/index.js',
 	output: [{ file: 'dist/index.js', format: 'es' }],
-	external: ['path', 'fs-extra', '@clack/prompts', 'kleur/colors', 'minimist'],
+	external: ['node:path', 'node:url', 'fs-extra', '@clack/prompts', 'kleur/colors', 'minimist', 'pacote'],
 	plugins: [terser()],
 };

+ 48 - 60
packages/create-stdf/src/index.js

@@ -10,15 +10,32 @@ import pacote from 'pacote';
 
 import * as langAll from './lang';
 
-// 获取版本号
-// Get version
+// 获取最新版本号
+// Get the latest version number
+const getLatestVersion = async packageName => {
+	const manifest = await pacote.manifest(`${packageName}@latest`);
+	return manifest.version;
+};
+
+// 获取 create 当前版本
+// Get create-stdf current version
 const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
 
+// 获取 create-stdf 的最新版本号
+// Get the latest version number of create-stdf
+const createStdfV = await getLatestVersion('create-stdf');
+
 // 显示版本号
 // Display version number
 console.log(`
-${grey(`create-stdf@${version}
-`)}`);
+${grey(`create-stdf@${version}`)}`);
+
+if (version != createStdfV) {
+	console.log(
+		red(`😢 Recommended to use the latest version: ${createStdfV}
+		`)
+	);
+}
 
 const spinner = p.spinner();
 
@@ -44,11 +61,7 @@ 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,
-	});
+	languages.push({ value: key, label: langAll[key].name, sort: langAll[key].sort });
 }
 
 // 按照 sort 排序
@@ -86,48 +99,34 @@ const iconUsageOptions = [
 	{ value: 'none', label: 'none' },
 ];
 
-// 如果命令行参数中仅有项目名称
-// If there is only a project name in the command line parameters
-if (argvProjectName && !argvTemplate && !argvIconUsage) {
-	createFunc(argvProjectName, templateOptions[0], iconUsageOptions[0], packageManagerOptions[0]);
-	process.exit(0);
-}
-// 如果命令行参数中仅有项目名称和模板名称
-// If there is a project name and template name in the command line parameters
-else if (argvProjectName && argvTemplate && !argvIconUsage) {
-	const item = templateOptions.find(item => item.value === argvTemplate);
-	if (!item) {
-		p.intro(red(lang.pectn));
-	} else if (!item.finish) {
-		p.intro(red(item.label + ' ' + lang.hnay));
-	} else {
-		createFunc(argvProjectName, item, iconUsageOptions[0], packageManagerOptions[0]);
-	}
-	// 如果命令行参数中仅有项目名称和图标使用方式
-	// If there is a project name and icon usage method in the command line parameters
-} else if (argvProjectName && !argvTemplate && argvIconUsage) {
-	const item = iconUsageOptions.find(item => item.value === argvIconUsage);
-	if (!item) {
-		p.intro(red(lang.pic));
+// 如果命令行参数中有项目名称
+// If there is project name in command line parameters
+if (argvProjectName) {
+	let itemTemplate = null;
+	if (argvTemplate) {
+		itemTemplate = templateOptions.find(item => item.value === argvTemplate);
+		if (!itemTemplate) {
+			p.intro(red(lang.pectn + ' (' + templateOptions.map(item => item.value).join(', ') + ')'));
+			process.exit(0);
+		}
+		if (!itemTemplate.finish) {
+			p.intro(red(itemTemplate.label + ' ' + lang.hnay));
+			process.exit(0);
+		}
 	} else {
-		createFunc(argvProjectName, templateOptions[0], item, packageManagerOptions[0]);
+		itemTemplate = templateOptions[0];
 	}
-	// 如果命令行参数中有项目名称和模板名称和图标使用方式
-	// If there is a project name and template name and icon usage method in the command line parameters
-} else if (argvProjectName && argvTemplate && argvIconUsage) {
-	const itemTemplate = templateOptions.find(item => item.value === argvTemplate);
-	const itemIconUsage = iconUsageOptions.find(item => item.value === argvIconUsage);
-	if (!itemTemplate) {
-		p.intro(red(lang.pectn));
-	} else if (!itemTemplate.finish) {
-		p.intro(red(item.label + ' ' + lang.hnay));
-	} else if (!itemIconUsage) {
-		p.intro(red(lang.pic));
+	let itemIconUsage = null;
+	if (argvIconUsage) {
+		itemIconUsage = iconUsageOptions.find(item => item.value === argvIconUsage);
+		if (!itemIconUsage) {
+			p.intro(red(lang.pic + ' (' + iconUsageOptions.map(item => item.value).join(', ') + ')'));
+			process.exit(0);
+		}
 	} else {
-		createFunc(argvProjectName, itemTemplate, itemIconUsage, packageManagerOptions[0]);
+		itemIconUsage = iconUsageOptions[0];
 	}
-	// 如果命令行参数中没有项目名称,则进入交互式创建项目
-	// If there is no project name in the command line parameters, enter the interactive creation project
+	createFunc(argvProjectName, itemTemplate, itemIconUsage, packageManagerOptions[0]);
 } else {
 	(async () => {
 		// 选择一种语言
@@ -258,7 +257,7 @@ function createFunc(projectName, templateItem, iconUsageItem, packageManagerItem
 	const templatePath = path.resolve(fileURLToPath(import.meta.url), '../..', `templates/${templateItem.template}`);
 
 	// 将 templatePath 目录下的所有文件复制到 projectDir 目录下
-	// Copy all files under the templatePath directory to the projectDir directory\
+	// Copy all files under the templatePath directory to the projectDir directory
 	fs.copy(templatePath, projectDir)
 		.then(async () => {
 			// 读取 package.json 文件
@@ -269,13 +268,6 @@ function createFunc(projectName, templateItem, iconUsageItem, packageManagerItem
 			// Modify the name attribute in package.json in the project to projectName
 			packageJson.name = projectName;
 
-			// 获取最新版本号
-			// Get the latest version number
-			const getLatestVersion = async packageName => {
-				const manifest = await pacote.manifest(`${packageName}@latest`);
-				return manifest.version;
-			};
-
 			// 获取 stdf 的最新版本号
 			// Get the latest version number of stdf
 			const stdfV = await getLatestVersion('stdf');
@@ -399,7 +391,6 @@ function createFunc(projectName, templateItem, iconUsageItem, packageManagerItem
 			// Display prompt information
 			console.log(
 				`👉 ${bold(lang.tgs)}
-
     ${blue(`1. cd ${projectName}`)}
     ${blue(`2. git init && git add -A && git commit -m "Initial commit"`)}
     ${blue(`3. ${packageManagerItem.install}`)}
@@ -408,10 +399,7 @@ function createFunc(projectName, templateItem, iconUsageItem, packageManagerItem
 			);
 			// 提示配置主题色
 			// Prompt configuration theme color
-			console.log(
-				`🎨 ${grey(isHasUno ? lang.pcyt_vu : lang.pcyt_vt)}
-    `
-			);
+			console.log(`🎨 ${grey(isHasUno ? lang.pcyt_vu : lang.pcyt_vt)}`);
 		})
 		.catch(err => {
 			spinner.stop();

+ 10 - 10
packages/create-stdf/src/lang.js

@@ -12,7 +12,7 @@ export const en_US = {
 	psai: 'Please select icon usage',
 	pm: 'Please select package manager',
 	cfsing: 'Creating file...',
-	pcsucc: 'Project created successfully',
+	pcsucc: 'Project created successfully!',
 	tgs: 'To get started:',
 	pcyt_vt: 'Tip: please configure Initial Color System in src/app.css, reference https://stdf.design/guide/theme',
 	pcyt_vu: 'Tip: please configure Initial Color System in src/app.css, reference https://stdf.design/guide/theme',
@@ -35,7 +35,7 @@ export const zh_CN = {
 	psai: '请选择图标使用方式',
 	pm: '请选择包管理工具',
 	cfsing: '正在创建文件...',
-	pcsucc: '项目创建成功',
+	pcsucc: '项目创建成功!',
 	tgs: '开始:',
 	pcyt_vt: '提示:请到 src/app.css 配置初始主题色,参考 https://stdf.design/guide/theme',
 	pcyt_vu: '提示:请到 src/app.css 配置初始主题色,参考 https://stdf.design/guide/theme',
@@ -58,7 +58,7 @@ export const zh_TW = {
 	psai: '請選擇圖標使用方式',
 	pm: '請選擇包管理工具',
 	cfsing: '正在創建文件...',
-	pcsucc: '項目創建成功',
+	pcsucc: '項目創建成功!',
 	tgs: '開始:',
 	pcyt_vt: '提示:請到 src/app.css 配置初始主題色,參考 https://stdf.design/guide/theme',
 	pcyt_vu: '提示:請到 src/app.css 配置初始主題色,參考 https://stdf.design/guide/theme',
@@ -81,7 +81,7 @@ export const ja_JP = {
 	psai: 'アイコンの使用方法を選択してください',
 	pm: 'パッケージマネージャーを選択してください',
 	cfsing: 'ファイルを作成しています...',
-	pcsucc: 'プロジェクトが正常に作成されました',
+	pcsucc: 'プロジェクトが正常に作成されました!',
 	tgs: '開始:',
 	pcyt_vt: 'ヒント:src/app.css ファイルで初期カラーシステムを設定し、参考 https://stdf.design/guide/theme',
 	pcyt_vu: 'ヒント:src/app.css ファイルで初期カラーシステムを設定し、参考 https://stdf.design/guide/theme',
@@ -104,7 +104,7 @@ export const ko_KR = {
 	psai: '아이콘 사용 방법을 선택하십시오',
 	pm: '패키지 관리자를 선택하십시오',
 	cfsing: '파일을 만드는 중입니다...',
-	pcsucc: '프로젝트가 성공적으로 생성되었습니다',
+	pcsucc: '프로젝트가 성공적으로 생성되었습니다!',
 	tgs: '시작:',
 	pcyt_vt: '팁: src/app.css 파일에서 초기 색상 시스템을 구성하고 참조 https://stdf.design/guide/theme',
 	pcyt_vu: '팁: src/app.css 파일에서 초기 색상 시스템을 구성하고 참조 https://stdf.design/guide/theme',
@@ -127,7 +127,7 @@ export const es_ES = {
 	psai: 'Por favor seleccione el uso de iconos',
 	pm: 'Por favor seleccione un administrador de paquetes',
 	cfsing: 'Creando archivo...',
-	pcsucc: 'Proyecto creado con éxito',
+	pcsucc: 'Proyecto creado con éxito!',
 	tgs: 'Para empezar:',
 	pcyt_vt: 'Consejo: configure su sistema de colores en reference https://stdf.design/guide/theme',
 	pcyt_vu: 'Consejo: configure su sistema de colores en reference https://stdf.design/guide/theme',
@@ -150,7 +150,7 @@ export const ru_RU = {
 	psai: 'Пожалуйста, выберите использование иконок',
 	pm: 'Пожалуйста, выберите пакетный менеджер',
 	cfsing: 'Создание файла...',
-	pcsucc: 'Проект успешно создан',
+	pcsucc: 'Проект успешно создан!',
 	tgs: 'Чтобы начать:',
 	pcyt_vt: 'Совет: настройте свой цветовой систему в ссылке https://stdf.design/guide/theme',
 	pcyt_vu: 'Совет: настройте свой цветовой систему в ссылке https://stdf.design/guide/theme',
@@ -173,7 +173,7 @@ export const fr_FR = {
 	psai: "Veuillez sélectionner le mode d'utilisation des icônes",
 	pm: 'Veuillez sélectionner un gestionnaire de paquets',
 	cfsing: 'Création de fichier...',
-	pcsucc: 'Projet créé avec succès',
+	pcsucc: 'Projet créé avec succès!',
 	tgs: 'Pour commencer:',
 	pcyt_vt: 'Conseil: veuillez configurer votre système de couleurs dans reference https://stdf.design/guide/theme',
 	pcyt_vu: 'Conseil: veuillez configurer votre système de couleurs dans reference https://stdf.design/guide/theme',
@@ -196,7 +196,7 @@ export const de_DE = {
 	psai: 'Bitte wählen Sie die Verwendung von Icons',
 	pm: 'Bitte wählen Sie einen Paketmanager aus',
 	cfsing: 'Erstelle Datei...',
-	pcsucc: 'Projekt erfolgreich erstellt',
+	pcsucc: 'Projekt erfolgreich erstellt!',
 	tgs: 'Um zu beginnen:',
 	pcyt_vt: 'Tip: please configure your color system in reference https://stdf.design/guide/theme',
 	pcyt_vu: 'Tip: please configure your color system in reference https://stdf.design/guide/theme',
@@ -219,7 +219,7 @@ export const it_IT = {
 	psai: 'Seleziona il modo di utilizzo delle icone',
 	pm: 'Seleziona un gestore di pacchetti',
 	cfsing: 'Creazione del file in corso...',
-	pcsucc: 'Progetto creato con successo',
+	pcsucc: 'Progetto creato con successo!',
 	tgs: 'Per iniziare:',
 	pcyt_vt: 'Consiglio: configura il tuo sistema di colori in https://stdf.design/guide/theme',
 	pcyt_vu: 'Consiglio: configura il tuo sistema di colori in https://stdf.design/guide/theme',