From 85e87ab2d9e3ce510943848957f28b5ef973a84b Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Sun, 15 Oct 2023 11:33:48 +0800 Subject: [PATCH] chore: upgrade version to 0.4.0-alpha.1 --- package.json | 5 +++-- packages/board/package.json | 8 +++---- packages/core/package.json | 10 ++++----- packages/idraw/package.json | 8 +++---- packages/lab/package.json | 8 +++---- packages/renderer/package.json | 6 +++--- packages/types/package.json | 4 ++-- packages/util/package.json | 4 ++-- scripts/upgrade-version.ts | 38 ++++++++++++++++++++++++++++++++++ scripts/util/file.ts | 23 +++++++++++++++++--- scripts/util/project.ts | 25 ++++++++++++++++++---- 11 files changed, 106 insertions(+), 33 deletions(-) create mode 100644 scripts/upgrade-version.ts diff --git a/package.json b/package.json index ab7b103..19b081c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "root", "private": false, + "version": "0.4.0-alpha.1", "scripts": { "postinstall": "npm run build", "dev": "vite-node ./scripts/dev.ts", @@ -23,7 +23,8 @@ "prepush": "npm run lint", "clear:jest": "rm -rf ./packages/*/__tests__/__snapshots__", "pu": "pnpm i && npm run build && lerna publish --force-publish", - "pu2": "lerna version && npm run build && lerna publish from-git --force-publish" + "pu2": "lerna version && npm run build && lerna publish from-git --force-publish", + "upgrade:version": "vite-node ./scripts/upgrade-version.ts" }, "devDependencies": { "@babel/core": "^7.22.19", diff --git a/packages/board/package.json b/packages/board/package.json index 184b59b..23aa4ae 100644 --- a/packages/board/package.json +++ b/packages/board/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/board", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "description": "", "main": "dist/esm/index.js", "module": "dist/esm/index.js", @@ -24,11 +24,11 @@ "@idraw/types": "^0.4.0-alpha.0" }, "dependencies": { - "@idraw/util": "^0.4.0-alpha.0", - "@idraw/renderer": "^0.4.0-alpha.0" + "@idraw/util": "^0.4.0-alpha.1", + "@idraw/renderer": "^0.4.0-alpha.1" }, "publishConfig": { "access": "public" }, "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483" -} +} \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index 590dd5f..92ecd9a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/core", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "description": "", "main": "dist/esm/index.js", "module": "dist/esm/index.js", @@ -24,12 +24,12 @@ "@idraw/types": "^0.4.0-alpha.0" }, "dependencies": { - "@idraw/board": "^0.4.0-alpha.0", - "@idraw/renderer": "^0.4.0-alpha.0", - "@idraw/util": "^0.4.0-alpha.0" + "@idraw/board": "^0.4.0-alpha.1", + "@idraw/renderer": "^0.4.0-alpha.1", + "@idraw/util": "^0.4.0-alpha.1" }, "publishConfig": { "access": "public" }, "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483" -} +} \ No newline at end of file diff --git a/packages/idraw/package.json b/packages/idraw/package.json index 91a97ce..1cba3dd 100644 --- a/packages/idraw/package.json +++ b/packages/idraw/package.json @@ -1,6 +1,6 @@ { "name": "idraw", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "description": "", "main": "dist/esm/index.js", "module": "dist/esm/index.js", @@ -24,11 +24,11 @@ "@idraw/types": "^0.4.0-alpha.0" }, "dependencies": { - "@idraw/core": "^0.4.0-alpha.0", - "@idraw/util": "^0.4.0-alpha.0" + "@idraw/core": "^0.4.0-alpha.1", + "@idraw/util": "^0.4.0-alpha.1" }, "publishConfig": { "access": "public" }, "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483" -} +} \ No newline at end of file diff --git a/packages/lab/package.json b/packages/lab/package.json index 1f48f43..30abe32 100644 --- a/packages/lab/package.json +++ b/packages/lab/package.json @@ -1,10 +1,10 @@ { "name": "@idraw/lab", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "dependencies": { "@ant-design/icons": "^5.1.3", - "@idraw/core": "^0.4.0-alpha.0", - "@idraw/util": "^0.4.0-alpha.0", + "@idraw/core": "^0.4.0-alpha.1", + "@idraw/util": "^0.4.0-alpha.1", "antd": "^5.5.0", "classnames": "^2.3.2", "react": "^18.2.0", @@ -15,4 +15,4 @@ "@types/react": "^18.2.0", "@types/react-dom": "^18.2.1" } -} +} \ No newline at end of file diff --git a/packages/renderer/package.json b/packages/renderer/package.json index 3cd58a5..87ad1ec 100644 --- a/packages/renderer/package.json +++ b/packages/renderer/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/renderer", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "description": "", "main": "dist/esm/index.js", "module": "dist/esm/index.js", @@ -24,10 +24,10 @@ "@idraw/types": "^0.4.0-alpha.0" }, "dependencies": { - "@idraw/util": "^0.4.0-alpha.0" + "@idraw/util": "^0.4.0-alpha.1" }, "publishConfig": { "access": "public" }, "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483" -} +} \ No newline at end of file diff --git a/packages/types/package.json b/packages/types/package.json index d99ef6c..f4356a8 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/types", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "description": "", "main": "src/index.ts", "types": "src/index.ts", @@ -23,4 +23,4 @@ "access": "public" }, "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483" -} +} \ No newline at end of file diff --git a/packages/util/package.json b/packages/util/package.json index bed1042..19a614b 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/util", - "version": "0.4.0-alpha.0", + "version": "0.4.0-alpha.1", "description": "", "main": "dist/esm/index.js", "module": "dist/esm/index.js", @@ -27,4 +27,4 @@ "access": "public" }, "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483" -} +} \ No newline at end of file diff --git a/scripts/upgrade-version.ts b/scripts/upgrade-version.ts new file mode 100644 index 0000000..d447b6e --- /dev/null +++ b/scripts/upgrade-version.ts @@ -0,0 +1,38 @@ +import { readJSONFile, writeJSONFile } from './util/file'; +import { getRootPackageJSON, getAllSubPackageDirs } from './util/project'; +const pkg = getRootPackageJSON(); +const version = pkg.version; +async function run() { + const pkgDirs = getAllSubPackageDirs(); + console.log('version ===== ', version); + console.log('pkgDirs ===== ', pkgDirs); + const allPkgMap: Record = {}; + pkgDirs.forEach((dir) => { + const file = ['packages', dir, 'package.json'].join('/'); + const json = readJSONFile('packages', dir, 'package.json'); + allPkgMap[json.name] = { file, json }; + }); + for (const key in allPkgMap) { + if (allPkgMap.hasOwnProperty(key)) { + console.log(`Upgrade [${key}] from ${allPkgMap[key].json.version} to ${version}`); + allPkgMap[key].json.version = version; + if (allPkgMap[key]?.json?.dependencies) { + for (const depName in allPkgMap[key].json.dependencies) { + if (allPkgMap.hasOwnProperty(depName)) { + allPkgMap[key].json.dependencies[depName] = `^${version}`; + } + } + } + } + writeJSONFile(allPkgMap[key].file, allPkgMap[key].json); + } +} + +run() + .then(() => { + console.log(`[@idraw]: Upgrade all packages version ${version} success!`); + }) + .catch((err) => { + console.error(err); + throw err; + }); diff --git a/scripts/util/file.ts b/scripts/util/file.ts index 4f095e9..59b227b 100644 --- a/scripts/util/file.ts +++ b/scripts/util/file.ts @@ -1,10 +1,27 @@ import fs from 'fs'; -// import path from 'path'; +import path from 'path'; -function removeFullDir(dirPath: string) { +export function removeFullDir(dirPath: string) { if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) { fs.rmSync(dirPath, { recursive: true }); } } -export { removeFullDir }; +export function projectRootPath(...args: string[]) { + const pathList = Array.from(args); + const baseDir = path.join(__dirname, '..', '..'); + return path.join(baseDir, ...pathList); +} + +export function readJSONFile(...args: string[]) { + const filePath = projectRootPath(...args); + const jsonStr = fs.readFileSync(filePath, { encoding: 'utf8' }); + const json = JSON.parse(jsonStr); + return json; +} + +export function writeJSONFile(filePath: string, json: any) { + const fullPath = projectRootPath(filePath); + const jsonStr = JSON.stringify(json, null, 2); + fs.writeFileSync(fullPath, jsonStr); +} diff --git a/scripts/util/project.ts b/scripts/util/project.ts index 690b5b1..1d31a6b 100644 --- a/scripts/util/project.ts +++ b/scripts/util/project.ts @@ -1,5 +1,7 @@ import fs from 'fs'; import path from 'path'; +import { globSync } from 'glob'; +import { projectRootPath } from './file'; export function joinPackagePath(...args: string[]) { const pathList = Array.from(args); @@ -8,9 +10,7 @@ export function joinPackagePath(...args: string[]) { } export function joinProjectPath(...args: string[]) { - const pathList = Array.from(args); - const baseDir = path.join(__dirname, '..', '..'); - return path.join(baseDir, ...pathList); + return projectRootPath(...args); } export function getTsConfig() { @@ -20,8 +20,25 @@ export function getTsConfig() { return config; } +export function getRootPackageJSON() { + const configPath = joinProjectPath('package.json'); + const configStr = fs.readFileSync(configPath, { encoding: 'utf8' }); + const config = JSON.parse(configStr); + return config; +} + +export function getAllSubPackageDirs() { + const pkgDirs = globSync('*', { + cwd: joinProjectPath('packages'), + absolute: false + }); + return pkgDirs; +} + module.exports = { joinProjectPath, joinPackagePath, - getTsConfig + getTsConfig, + getRootPackageJSON, + getAllSubPackageDirs };