simple-icons/scripts/release/bump-version.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-03-03 13:57:33 +03:00
#!/usr/bin/env node
/**
* @fileoverview
* Updates the version of this package to the CLI specified version.
*/
const fs = require("fs");
const path = require("path");
2021-03-03 13:57:33 +03:00
const rootDir = path.resolve(__dirname, "..", "..");
const packageJsonFile = path.resolve(rootDir, "package.json");
const packageLockFile = path.resolve(rootDir, "package-lock.json");
2021-03-03 13:57:33 +03:00
function readManifest(file) {
const manifestRaw = fs.readFileSync(file).toString();
const manifestJson = JSON.parse(manifestRaw);
return manifestJson;
}
function writeManifest(file, json) {
const manifestRaw = JSON.stringify(json, null, 2) + "\n";
2021-03-03 13:57:33 +03:00
fs.writeFileSync(file, manifestRaw);
}
function main(newVersion) {
try {
const manifest = readManifest(packageJsonFile);
const manifestLock = readManifest(packageLockFile);
2021-03-03 13:57:33 +03:00
manifest.version = newVersion
manifestLock.version = newVersion
writeManifest(packageJsonFile, manifest);
writeManifest(packageLockFile, manifestLock);
2021-03-03 13:57:33 +03:00
} catch (error) {
console.error(`Failed to bump package version to ${newVersion}:`, error);
process.exit(1);
}
}
main(process.argv[2]);