From 2e61fec7a604d242d859b206dc6d5e750d4baf57 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Mon, 5 Jul 2021 22:29:35 +0530 Subject: [PATCH] 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 --- scripts/release.js | 39 ++++++++++++++++++++++++++++++++++++++ scripts/updateChangelog.js | 2 +- scripts/updateReadme.js | 38 ++++++++++++++++++++----------------- 3 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 scripts/release.js diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 00000000..56aab323 --- /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 6dca5b84..13da98ba 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 1c923b21..46c8fad2 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( - /[\s\S]*?/, - "", -); + // remove note for unstable release + data = data.replace( + /[\s\S]*?/, + "", + ); -// 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;