From 4a4ce4d4642494fcb4235bbbaad7b43cd5f5ebd6 Mon Sep 17 00:00:00 2001 From: gxz Date: Thu, 26 Oct 2023 14:24:55 +0800 Subject: [PATCH] chore: update version script will update package.json too --- package.json | 4 ++- packages/agora-rtc-react-ui/package.json | 3 ++- packages/agora-rtc-react/package.json | 3 ++- packages/agora-rtc-react/tsup.config.ts | 1 - scripts/release/update-version.ts | 31 +++++++++++++----------- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index eaebfef2..994d1a4b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "copy-docs": "esbuild-dev ./scripts/copy-docs.ts", "gene-docs": "pnpm -r run gene-docs", "typedoc": "pnpm -r run typedoc", - "release": "release-it" + "release": "release-it", + "rtc-version": "pnpm -F agora-rtc-react run version", + "rtc-ui-version": "pnpm -F agora-rtc-react-ui run version" }, "devDependencies": { "@commitlint/config-conventional": "^17.6.7", diff --git a/packages/agora-rtc-react-ui/package.json b/packages/agora-rtc-react-ui/package.json index ea42f976..e1159417 100644 --- a/packages/agora-rtc-react-ui/package.json +++ b/packages/agora-rtc-react-ui/package.json @@ -45,7 +45,8 @@ "storybook-docs": "storybook dev --docs", "build-storybook-docs": "storybook build --docs", "test": "vitest run --coverage", - "test:watch": "vitest --ui" + "test:watch": "vitest --ui", + "version": "esbuild-dev ../../scripts/release/update-version.ts agora-rtc-react-ui" }, "peerDependencies": { "agora-rtc-react": ">=2", diff --git a/packages/agora-rtc-react/package.json b/packages/agora-rtc-react/package.json index 7fa4a18f..49e88c4c 100644 --- a/packages/agora-rtc-react/package.json +++ b/packages/agora-rtc-react/package.json @@ -47,7 +47,8 @@ "update-readme": "pnpm esbuild-dev ../../scripts/docs/update-readme.ts", "gene-comment": "esbuild-dev ../../scripts/docs/api.ts && esbuild-dev ../../scripts/docs/component.ts && esbuild-dev ../../scripts/docs/data-types.ts", "gene-docs": "pnpm run gene-md && pnpm run gene-stories && pnpm run gene-comment && pnpm run update-readme", - "typedoc": "typedoc src" + "typedoc": "typedoc src", + "version": "esbuild-dev ../../scripts/release/update-version.ts agora-rtc-react" }, "peerDependencies": { "react": ">=16.8" diff --git a/packages/agora-rtc-react/tsup.config.ts b/packages/agora-rtc-react/tsup.config.ts index 2e680b93..2f5f5776 100644 --- a/packages/agora-rtc-react/tsup.config.ts +++ b/packages/agora-rtc-react/tsup.config.ts @@ -31,7 +31,6 @@ export default defineConfig([ clean: true, treeshake: true, dts: { - entry: "src/index.ts", resolve: ["agora-rtc-sdk-ng"], }, minify: true, diff --git a/scripts/release/update-version.ts b/scripts/release/update-version.ts index 3cf17582..b2f9e494 100644 --- a/scripts/release/update-version.ts +++ b/scripts/release/update-version.ts @@ -1,25 +1,28 @@ import fs from "node:fs"; import path from "node:path"; -const args = process.argv.slice(2); - -for (let i = 0; i < args.length; i++) { - if (args[i].startsWith("-")) { - args.splice(args.indexOf(args[i]), 1); - i--; - } -} +import rtc_PKG from "../../packages/agora-rtc-react/package.json"; +import rtcUI_PKG from "../../packages/agora-rtc-react-ui/package.json"; -if (args.length < 2 || !args[0].startsWith("target:") || !args[1].includes("@")) { - console.log("Usage: node update-version.ts target:@"); - process.exit(1); -} +const args = process.argv.slice(2); -const targetName = args[0].substring(7); -const newVersion = args[1].substring(args[1].lastIndexOf("@") + 1); +const targetName = args[0]; +const newVersion = args[1]; const targetPath = path.join(__dirname, "..", "..", "packages", targetName, "src", "rtc.ts"); +let targetPackageJson; +if (targetName === "agora-rtc-react") { + targetPackageJson = rtc_PKG; +} else if (targetName === "agora-rtc-react-ui") { + targetPackageJson = rtcUI_PKG; +} +targetPackageJson.version = newVersion; +fs.writeFileSync( + path.join(__dirname, "..", "..", "packages", targetName, "package.json"), + JSON.stringify(targetPackageJson, null, 2) + "\n", +); + fs.readFile(targetPath, "utf8", (err, data) => { if (err) { console.error(err);