Bläddra i källkod

[create]Fix stdf and icon lastest version

dufu1991 3 år sedan
förälder
incheckning
a9800c111e
2 ändrade filer med 42 tillägg och 23 borttagningar
  1. 1 1
      packages/create-stdf/package.json
  2. 41 22
      packages/create-stdf/scripts/update.js

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

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

+ 41 - 22
packages/create-stdf/scripts/update.js

@@ -1,14 +1,5 @@
 import fs from 'node:fs';
-
-// 读取 ../stdf/package.json 中的 version 字段,作为最新版本号
-// Read the version field in ../stdf/package.json as the latest version number
-const version = JSON.parse(fs.readFileSync('../stdf/package.json', 'utf-8')).version;
-console.log(`stdf 最新版本:${version}`);
-
-// 读取 ../rollup-plugin-stdf-icon/package.json 中的 version 字段,作为最新版本号
-// Read the version field in ../rollup-plugin-stdf-icon/package.json as the latest version number
-const iconVersion = JSON.parse(fs.readFileSync('../rollup-plugin-stdf-icon/package.json', 'utf-8')).version;
-console.log(`rollup-plugin-stdf-icon 最新版本:${iconVersion}`);
+import { exec } from 'child_process';
 
 // 封装函数,传入版本号,需要修改的 package.json 中的 devDependencies 的 key 值,需要修改的文件路径,直接修改 package.json 并重新写入
 // Encapsulate the function, pass in the version number, the key value of devDependencies in package.json that needs to be modified, the file path that needs to be modified, and directly modify package.json and rewrite
@@ -19,16 +10,44 @@ const updatePackageJson = (version, key, path) => {
 	console.log(`🎉 ${path} 更新成功`);
 };
 
-// 更新模板中的 package.json 的 stdf 版本号
-// Update the stdf version number in the template package.json
-updatePackageJson(version, 'stdf', 'templates/vite-tailwind/package.json');
-updatePackageJson(version, 'stdf', 'templates/vite-uno/package.json');
-updatePackageJson(version, 'stdf', 'templates/sveltekit-tailwind/package.json');
-updatePackageJson(version, 'stdf', 'templates/sveltekit-uno/package.json');
+// 获取 stdf 最新版本
+// Get the latest version of stdf
+exec(`npm show stdf version`, (error, stdout, stderr) => {
+	if (error) {
+		console.error(`执行命令出错: ${error.message}`);
+		return;
+	}
+	if (stderr) {
+		console.error(`命令错误: ${stderr}`);
+		return;
+	}
+	const version = stdout.trim();
+	console.log(`👉 stdf 最新版本: ${version}`);
+	// 更新模板中的 package.json 的 stdf 版本号
+	// Update the stdf version number in the template package.json
+	updatePackageJson(version, 'stdf', 'templates/vite-tailwind/package.json');
+	updatePackageJson(version, 'stdf', 'templates/vite-uno/package.json');
+	updatePackageJson(version, 'stdf', 'templates/sveltekit-tailwind/package.json');
+	updatePackageJson(version, 'stdf', 'templates/sveltekit-uno/package.json');
+});
 
-// 更新模板中的 package.json 的 rollup-plugin-stdf-icon 版本号
-// Update the rollup-plugin-stdf-icon version number in the template package.json
-updatePackageJson(iconVersion, 'rollup-plugin-stdf-icon', 'templates/vite-tailwind/package.json');
-updatePackageJson(iconVersion, 'rollup-plugin-stdf-icon', 'templates/vite-uno/package.json');
-updatePackageJson(iconVersion, 'rollup-plugin-stdf-icon', 'templates/sveltekit-tailwind/package.json');
-updatePackageJson(iconVersion, 'rollup-plugin-stdf-icon', 'templates/sveltekit-uno/package.json');
+// 获取 rollup-plugin-stdf-icon 最新版本
+// Get the latest version of rollup-plugin-stdf-icon
+exec(`npm show rollup-plugin-stdf-icon version`, (errorIcon, stdoutIcon, stderrIcon) => {
+	if (errorIcon) {
+		console.error(`执行命令出错: ${errorIcon.message}`);
+		return;
+	}
+	if (stderrIcon) {
+		console.error(`命令错误: ${stderrIcon}`);
+		return;
+	}
+	const version = stdoutIcon.trim();
+	console.log(`👉 rollup-plugin-stdf-icon 最新版本: ${version}`);
+	// 更新模板中的 package.json 的 rollup-plugin-stdf-icon 版本号
+	// Update the rollup-plugin-stdf-icon version number in the template package.json
+	updatePackageJson(version, 'rollup-plugin-stdf-icon', 'templates/vite-tailwind/package.json');
+	updatePackageJson(version, 'rollup-plugin-stdf-icon', 'templates/vite-uno/package.json');
+	updatePackageJson(version, 'rollup-plugin-stdf-icon', 'templates/sveltekit-tailwind/package.json');
+	updatePackageJson(version, 'rollup-plugin-stdf-icon', 'templates/sveltekit-uno/package.json');
+});