Skip to content

Commit

Permalink
chore: update version script will update package.json too
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Oct 26, 2023
1 parent 461350c commit 4a4ce4d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/agora-rtc-react-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/agora-rtc-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion packages/agora-rtc-react/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default defineConfig([
clean: true,
treeshake: true,
dts: {
entry: "src/index.ts",
resolve: ["agora-rtc-sdk-ng"],
},
minify: true,
Expand Down
31 changes: 17 additions & 14 deletions scripts/release/update-version.ts
Original file line number Diff line number Diff line change
@@ -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:<package-name>@<new-version>");
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);
Expand Down

0 comments on commit 4a4ce4d

Please sign in to comment.