2021-03-03 13:57:33 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/**
|
|
|
|
* @fileoverview
|
|
|
|
* Updates the version of this package to the CLI specified version.
|
|
|
|
*/
|
|
|
|
|
2021-12-25 17:22:56 +03:00
|
|
|
import fs from 'node:fs';
|
|
|
|
import path from 'node:path';
|
2023-04-19 16:23:13 +03:00
|
|
|
import { getDirnameFromImportMeta } from '../../sdk.mjs';
|
2021-12-25 17:22:56 +03:00
|
|
|
|
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
2021-03-03 13:57:33 +03:00
|
|
|
|
2021-10-25 22:13:10 +03:00
|
|
|
const rootDir = path.resolve(__dirname, '..', '..');
|
|
|
|
const packageJsonFile = path.resolve(rootDir, 'package.json');
|
2021-03-03 13:57:33 +03:00
|
|
|
|
2021-10-25 22:13:10 +03:00
|
|
|
const readManifest = (file) => {
|
2021-12-10 04:02:58 +03:00
|
|
|
const manifestRaw = fs.readFileSync(file, 'utf-8');
|
2021-03-03 13:57:33 +03:00
|
|
|
const manifestJson = JSON.parse(manifestRaw);
|
|
|
|
return manifestJson;
|
2021-10-25 22:13:10 +03:00
|
|
|
};
|
2021-03-03 13:57:33 +03:00
|
|
|
|
2021-10-25 22:13:10 +03:00
|
|
|
const writeManifest = (file, json) => {
|
|
|
|
const manifestRaw = JSON.stringify(json, null, 2) + '\n';
|
2021-03-03 13:57:33 +03:00
|
|
|
fs.writeFileSync(file, manifestRaw);
|
2021-10-25 22:13:10 +03:00
|
|
|
};
|
2021-03-03 13:57:33 +03:00
|
|
|
|
2021-10-25 22:13:10 +03:00
|
|
|
const main = (newVersion) => {
|
2021-03-03 13:57:33 +03:00
|
|
|
try {
|
2021-05-07 20:55:06 +03:00
|
|
|
const manifest = readManifest(packageJsonFile);
|
2021-03-03 13:57:33 +03:00
|
|
|
|
2021-10-25 22:13:10 +03:00
|
|
|
manifest.version = newVersion;
|
2021-03-03 13:57:33 +03:00
|
|
|
|
2021-05-07 20:55:06 +03:00
|
|
|
writeManifest(packageJsonFile, manifest);
|
2021-03-03 13:57:33 +03:00
|
|
|
} catch (error) {
|
|
|
|
console.error(`Failed to bump package version to ${newVersion}:`, error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2021-10-25 22:13:10 +03:00
|
|
|
};
|
2021-03-03 13:57:33 +03:00
|
|
|
|
|
|
|
main(process.argv[2]);
|