浏览代码

build: Add release script to update relevant files and commit for next release (#3805)

* build: Add script to update package.json and commit for next release

* fix
vanilla_orig
Aakansha Doshi 4 年前
父节点
当前提交
2e61fec7a6
没有帐户链接到提交者的电子邮件
共有 3 个文件被更改,包括 61 次插入18 次删除
  1. 39
    0
      scripts/release.js
  2. 1
    1
      scripts/updateChangelog.js
  3. 21
    17
      scripts/updateReadme.js

+ 39
- 0
scripts/release.js 查看文件

1
+const fs = require("fs");
2
+const util = require("util");
3
+const exec = util.promisify(require("child_process").exec);
4
+const updateReadme = require("./updateReadme");
5
+const updateChangelog = require("./updateChangelog");
6
+
7
+const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
8
+const excalidrawPackage = `${excalidrawDir}/package.json`;
9
+
10
+const updatePackageVersion = (nextVersion) => {
11
+  const pkg = require(excalidrawPackage);
12
+  pkg.version = nextVersion;
13
+  const content = `${JSON.stringify(pkg, null, 2)}\n`;
14
+  fs.writeFileSync(excalidrawPackage, content, "utf-8");
15
+};
16
+
17
+const release = async (nextVersion) => {
18
+  try {
19
+    updateReadme();
20
+    await updateChangelog(nextVersion);
21
+    updatePackageVersion();
22
+    await exec(`git add -u`);
23
+    await exec(
24
+      `git commit -m "docs: release excalidraw@excalidraw@${nextVersion}  🎉"`,
25
+    );
26
+    /* eslint-disable no-console */
27
+    console.log("Done!");
28
+  } catch (e) {
29
+    console.error(e);
30
+    process.exit(1);
31
+  }
32
+};
33
+
34
+const nextVersion = process.argv.slice(2)[0];
35
+if (!nextVersion) {
36
+  console.error("Pass the next version to release!");
37
+  process.exit(1);
38
+}
39
+release(nextVersion);

+ 1
- 1
scripts/updateChangelog.js 查看文件

91
   fs.writeFileSync(`${excalidrawDir}/CHANGELOG.md`, updatedContent, "utf8");
91
   fs.writeFileSync(`${excalidrawDir}/CHANGELOG.md`, updatedContent, "utf8");
92
 };
92
 };
93
 
93
 
94
-updateChangelog();
94
+module.exports = updateChangelog;

+ 21
- 17
scripts/updateReadme.js 查看文件

1
 const fs = require("fs");
1
 const fs = require("fs");
2
 
2
 
3
-const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
4
-let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
3
+const updateReadme = () => {
4
+  const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
5
+  let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
5
 
6
 
6
-// remove note for unstable release
7
-data = data.replace(
8
-  /<!-- unstable-readme-start-->[\s\S]*?<!-- unstable-readme-end-->/,
9
-  "",
10
-);
7
+  // remove note for unstable release
8
+  data = data.replace(
9
+    /<!-- unstable-readme-start-->[\s\S]*?<!-- unstable-readme-end-->/,
10
+    "",
11
+  );
11
 
12
 
12
-// replace "excalidraw-next" with "excalidraw"
13
-data = data.replace(/excalidraw-next/g, "excalidraw");
14
-data = data.trim();
13
+  // replace "excalidraw-next" with "excalidraw"
14
+  data = data.replace(/excalidraw-next/g, "excalidraw");
15
+  data = data.trim();
15
 
16
 
16
-const demoIndex = data.indexOf("### Demo");
17
-const excalidrawNextNote =
18
-  "#### Note\n\n**If you don't want to wait for the next stable release and try out the unreleased changes you can use [@excalidraw/excalidraw-next](https://www.npmjs.com/package/@excalidraw/excalidraw-next).**\n\n";
19
-// Add excalidraw next note to try out for unreleased changes
20
-data = data.slice(0, demoIndex) + excalidrawNextNote + data.slice(demoIndex);
17
+  const demoIndex = data.indexOf("### Demo");
18
+  const excalidrawNextNote =
19
+    "#### Note\n\n**If you don't want to wait for the next stable release and try out the unreleased changes you can use [@excalidraw/excalidraw-next](https://www.npmjs.com/package/@excalidraw/excalidraw-next).**\n\n";
20
+  // Add excalidraw next note to try out for unreleased changes
21
+  data = data.slice(0, demoIndex) + excalidrawNextNote + data.slice(demoIndex);
21
 
22
 
22
-// update readme
23
-fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
23
+  // update readme
24
+  fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
25
+};
26
+
27
+module.exports = updateReadme;

正在加载...
取消
保存