Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

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

Aakansha Doshi2e61fec7a604
diff --git a/scripts/release.js b/scripts/release.js
new file mode 100644
index 0000000000..56aab32383
--- /dev/null
+++ b/scripts/release.js
@@ -0,0 +1,39 @@
+const fs = require("fs");
+const util = require("util");
+const exec = util.promisify(require("child_process").exec);
+const updateReadme = require("./updateReadme");
+const updateChangelog = require("./updateChangelog");
+
+const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
+const excalidrawPackage = `${excalidrawDir}/package.json`;
+
+const updatePackageVersion = (nextVersion) => {
+ const pkg = require(excalidrawPackage);
+ pkg.version = nextVersion;
+ const content = `${JSON.stringify(pkg, null, 2)}\n`;
+ fs.writeFileSync(excalidrawPackage, content, "utf-8");
+};
+
+const release = async (nextVersion) => {
+ try {
+ updateReadme();
+ await updateChangelog(nextVersion);
+ updatePackageVersion();
+ await exec(`git add -u`);
+ await exec(
+ `git commit -m "docs: release excalidraw@excalidraw@${nextVersion} 🎉"`,
+ );
+ /* eslint-disable no-console */
+ console.log("Done!");
+ } catch (e) {
+ console.error(e);
+ process.exit(1);
+ }
+};
+
+const nextVersion = process.argv.slice(2)[0];
+if (!nextVersion) {
+ console.error("Pass the next version to release!");
+ process.exit(1);
+}
+release(nextVersion);
diff --git a/scripts/updateChangelog.js b/scripts/updateChangelog.js
index 6dca5b84ae..13da98bad6 100644
--- a/scripts/updateChangelog.js
+++ b/scripts/updateChangelog.js
@@ -91,4 +91,4 @@ const updateChangelog = async () => {
fs.writeFileSync(`${excalidrawDir}/CHANGELOG.md`, updatedContent, "utf8");
};
-updateChangelog();
+module.exports = updateChangelog;
diff --git a/scripts/updateReadme.js b/scripts/updateReadme.js
index 1c923b211b..46c8fad2ea 100644
--- a/scripts/updateReadme.js
+++ b/scripts/updateReadme.js
@@ -1,23 +1,27 @@
const fs = require("fs");
-const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
-let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
+const updateReadme = () => {
+ const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
+ let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
-// remove note for unstable release
-data = data.replace(
- /<!-- unstable-readme-start-->[\s\S]*?<!-- unstable-readme-end-->/,
- "",
-);
+ // remove note for unstable release
+ data = data.replace(
+ /<!-- unstable-readme-start-->[\s\S]*?<!-- unstable-readme-end-->/,
+ "",
+ );
-// replace "excalidraw-next" with "excalidraw"
-data = data.replace(/excalidraw-next/g, "excalidraw");
-data = data.trim();
+ // replace "excalidraw-next" with "excalidraw"
+ data = data.replace(/excalidraw-next/g, "excalidraw");
+ data = data.trim();
-const demoIndex = data.indexOf("### Demo");
-const excalidrawNextNote =
- "#### 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";
-// Add excalidraw next note to try out for unreleased changes
-data = data.slice(0, demoIndex) + excalidrawNextNote + data.slice(demoIndex);
+ const demoIndex = data.indexOf("### Demo");
+ const excalidrawNextNote =
+ "#### 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";
+ // Add excalidraw next note to try out for unreleased changes
+ data = data.slice(0, demoIndex) + excalidrawNextNote + data.slice(demoIndex);
-// update readme
-fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
+ // update readme
+ fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
+};
+
+module.exports = updateReadme;