UNPKG

outsystems-design-tokens

Version:

Store the Design Tokens used on the Ionic Framework and Widgets Library

80 lines (61 loc) 2.5 kB
/* Summary: Script to bump the package version. Workflow: 1. Create new branch 'bump/${version}' 2. Bump version on package.json 3. Commit and push branch to GitHub 4. Create pull request in Github Arguments: releaseType - [major | minor | patch] isPreRelease - [pre] additionalIdentifiers - [pre-release identifier] */ import { execSync } from "child_process"; import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); function exec(cmd) { execSync(cmd, { stdio: "inherit", env: process.env }); } function execAndOutput(cmd) { return execSync(cmd, { env: process.env }).toString(); } function makeVersionCommand(releaseType, isPreRelease, additionalIdentifiers) { return `${isPreRelease && releaseType !== "prerelease" ? "pre" : ""}${releaseType} ${ isPreRelease ? `--preid=${additionalIdentifiers}` : "" }`; } const semVerReleaseTypes = ["major", "minor", "patch", "prerelease"]; const releaseType = process.argv[2]; const isPreRelease = releaseType === "prerelease" || process.argv[3] === "pre"; const additionalIdentifiers = process.argv[4] ?? process.argv[3]; if (!semVerReleaseTypes.some((el) => el === releaseType)) { console.log(`Invalid release type! Only ${semVerReleaseTypes.join(", ")} allowed.`); process.exit(); } if (isPreRelease && !additionalIdentifiers) { console.log( `Pre-releases require an additional identifier to be appended to the version number. Ex: 'alpha' or 'beta'.`, ); process.exit(); } exec("git pull"); const versionCommandArgument = makeVersionCommand(releaseType, isPreRelease, additionalIdentifiers); exec(`npm version ${versionCommandArgument} --no-git-tag-version`); const cwd = process.cwd(); const currentBranch = execAndOutput("git branch --no-color --show-current").replace(/[\r\n]+/, ""); const packageJsonPath = path.join(__dirname, './../package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const newVersionNumber = packageJson.version; const newBranch = `bump/${releaseType}-${newVersionNumber}`; exec(`git checkout -b ${newBranch}`); exec("git add -u"); exec(`git commit -m "Bump version to ${newVersionNumber}"`); exec(`git push -u origin ${newBranch}`); exec( `gh pr create --title "Bump version to ${newVersionNumber}" --body "Bump package version to ${newVersionNumber}" --base ${currentBranch}`, ); process.chdir(cwd);