|
| 1 | +const assert = require("assert"); |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
| 4 | +const child_process = require("child_process"); |
| 5 | + |
| 6 | +let version = ""; |
| 7 | +function updateVersion(json, kind) { |
| 8 | + let [, major, minor, patch, rest] = json.version.match( |
| 9 | + /^(\d+)\.(\d+)\.(\d+)(.*)$/, |
| 10 | + ); |
| 11 | + |
| 12 | + switch (kind) { |
| 13 | + case "major": |
| 14 | + major = Number(major) + 1; |
| 15 | + break; |
| 16 | + case "minor": |
| 17 | + minor = Number(minor) + 1; |
| 18 | + break; |
| 19 | + case "patch": |
| 20 | + patch = Number(patch) + 1; |
| 21 | + break; |
| 22 | + } |
| 23 | + |
| 24 | + json.version = `${major}.${minor}.${patch}${rest}`; |
| 25 | + version = json.version; |
| 26 | +} |
| 27 | + |
| 28 | +function format(file) { |
| 29 | + child_process.execSync(`./node_modules/.bin/prettier --write ${file}`); |
| 30 | +} |
| 31 | + |
| 32 | +const shellPath = path.join(__dirname, "..", "src", "shells"); |
| 33 | +function updateManifest(name, kind) { |
| 34 | + assert(/edge|chrome|firefox/.test(name), "Unknown browser"); |
| 35 | + |
| 36 | + const file = path.join(shellPath, name, "manifest.json"); |
| 37 | + const json = JSON.parse(fs.readFileSync(file, "utf-8")); |
| 38 | + updateVersion(json, kind); |
| 39 | + |
| 40 | + fs.writeFileSync(file, JSON.stringify(json, null, "\t"), "utf-8"); |
| 41 | + format(file); |
| 42 | +} |
| 43 | + |
| 44 | +function updatePkgJson(kind) { |
| 45 | + const file = path.join(__dirname, "..", "package.json"); |
| 46 | + const json = JSON.parse(fs.readFileSync(file, "utf-8")); |
| 47 | + updateVersion(json, kind); |
| 48 | + |
| 49 | + fs.writeFileSync(file, JSON.stringify(json, null, "\t"), "utf-8"); |
| 50 | + format(file); |
| 51 | +} |
| 52 | + |
| 53 | +const [kind] = process.argv.slice(2); |
| 54 | + |
| 55 | +assert(/major|minor|patch/.test(kind), "Unknown version increase"); |
| 56 | + |
| 57 | +const r = child_process.execSync("git status --porcelain"); |
| 58 | +assert(r.toString() === "", `Working directory is dirty^`); |
| 59 | + |
| 60 | +updateManifest("edge", kind); |
| 61 | +updateManifest("chrome", kind); |
| 62 | +updateManifest("firefox", kind); |
| 63 | +updatePkgJson(kind); |
| 64 | + |
| 65 | +child_process.execSync(`git add package.json src/`); |
| 66 | +child_process.execSync(`git commit -m "Release ${version}"`); |
| 67 | +child_process.execSync(`git tag "v${version}"`); |
0 commit comments