forked from EOSIO/abieos
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate-version.mjs
31 lines (28 loc) · 1009 Bytes
/
update-version.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {promises} from "node:fs";
import {exec} from "node:child_process";
const oldPackageJson = await promises.readFile('package.json', 'utf8');
if (!oldPackageJson) {
console.error('Failed to read package.json');
process.exit(1);
}
const parsed = JSON.parse(oldPackageJson.toString());
const [version, hash] = parsed.version.split('-');
console.log(`Old version: ${version}`);
console.log(`Old hash: ${hash}`);
exec('git rev-parse --short HEAD', {
cwd: './abieos',
}, (error, stdout) => {
if (error) {
console.error('Failed to get git hash');
process.exit(1);
}
console.log(`New hash: ${stdout.trim()}`);
const newVersion = `${version}-${stdout.trim()}`;
console.log(`New version: ${newVersion}`);
parsed.version = newVersion;
const newPackageJson = JSON.stringify(parsed, null, 2);
promises.writeFile('package.json', newPackageJson).catch((err) => {
console.error('Failed to write package.json');
process.exit(1);
});
});