diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..f37188313 --- /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 --tag next + - run: cd ../util/ + - run: npm publish --tag next + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index ab7b103ad..99c095e23 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 && pnpm i" }, "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/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 new file mode 100644 index 000000000..b250f1510 --- /dev/null +++ b/scripts/upgrade-version.ts @@ -0,0 +1,36 @@ +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(); + 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 };