From 85e87ab2d9e3ce510943848957f28b5ef973a84b Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Sun, 15 Oct 2023 11:33:48 +0800 Subject: [PATCH 1/4] 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 ab7b103ad..19b081c9e 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 184b59b24..23aa4ae07 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 590dd5f33..92ecd9acf 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 91a97cee3..1cba3ddd0 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 1f48f43b9..30abe32f1 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 3cd58a56a..87ad1eca4 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 d99ef6c58..f4356a813 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 bed104281..19a614b5a 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 000000000..d447b6ee3 --- /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 4f095e981..59b227b9c 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 690b5b185..1d31a6b8f 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 }; From c1369efe0372aa587fc0b3fd5b66a7952fe81314 Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Sun, 15 Oct 2023 11:39:18 +0800 Subject: [PATCH 2/4] ci: update github action --- .github/workflows/release.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..45153b77a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +name: Publish Package to npmjs +on: + release: + types: [published] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v3 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + - run: npm run test + - run: npm run build + - run: cd packages/types/ + - run: npm publish + - run: cd ../util/ + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 6aae6d7c33b64d257ff38d560b541b742457952d Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Sun, 15 Oct 2023 11:40:46 +0800 Subject: [PATCH 3/4] ci: update github action --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45153b77a..f37188313 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,8 +15,8 @@ jobs: - run: npm run test - run: npm run build - run: cd packages/types/ - - run: npm publish + - run: npm publish --tag next - run: cd ../util/ - - run: npm publish + - run: npm publish --tag next env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 1b5f621e129834f929f7eaa214d03458ada75887 Mon Sep 17 00:00:00 2001 From: chenshenhai Date: Sun, 15 Oct 2023 11:44:15 +0800 Subject: [PATCH 4/4] chore: update pnpm lock file --- package.json | 2 +- pnpm-lock.yaml | 20 ++++++++++---------- scripts/upgrade-version.ts | 2 -- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 19b081c9e..99c095e23 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "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", - "upgrade:version": "vite-node ./scripts/upgrade-version.ts" + "upgrade:version": "vite-node ./scripts/upgrade-version.ts && pnpm i" }, "devDependencies": { "@babel/core": "^7.22.19", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84ebdfcdd..f834256c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -147,10 +147,10 @@ importers: packages/board: dependencies: '@idraw/renderer': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../renderer '@idraw/util': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../util devDependencies: '@idraw/types': @@ -160,13 +160,13 @@ importers: packages/core: dependencies: '@idraw/board': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../board '@idraw/renderer': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../renderer '@idraw/util': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../util devDependencies: '@idraw/types': @@ -176,10 +176,10 @@ importers: packages/idraw: dependencies: '@idraw/core': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../core '@idraw/util': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../util devDependencies: '@idraw/types': @@ -192,10 +192,10 @@ importers: specifier: ^5.1.3 version: 5.1.3(react-dom@18.2.0)(react@18.2.0) '@idraw/core': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../core '@idraw/util': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../util antd: specifier: ^5.5.0 @@ -223,7 +223,7 @@ importers: packages/renderer: dependencies: '@idraw/util': - specifier: ^0.4.0-alpha.0 + specifier: ^0.4.0-alpha.1 version: link:../util devDependencies: '@idraw/types': diff --git a/scripts/upgrade-version.ts b/scripts/upgrade-version.ts index d447b6ee3..b250f1510 100644 --- a/scripts/upgrade-version.ts +++ b/scripts/upgrade-version.ts @@ -4,8 +4,6 @@ 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('/');