-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathsetPkgVersion.mjs
executable file
·38 lines (29 loc) · 1 KB
/
setPkgVersion.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
32
33
34
35
36
37
38
import path from 'path';
import chalk from 'chalk';
import fs from 'fs-extra';
import {fileURLToPath} from "url";
/**
* Sets the specified version in our three package.json files
*
* invoke via command-line: $ node setPkgVersion.mjs 0.4.3
*
*/
const modules = [
'./',
'./client',
'./server',
];
if (process.argv.length < 3) {
console.error(chalk.red.bold('Please specify version...'));
process.exit(1);
}
const versionToSet = process.argv[2];
const dirname = path.dirname(fileURLToPath(import.meta.url));
Promise.all(modules.map(setPkgVersionInModule)).then(() => console.log(chalk.green('done')));
async function setPkgVersionInModule(module) {
const absolutePkgJsonPath = path.resolve(dirname, path.join(module, 'package.json'));
console.log(chalk.blue(`setting Version in ${absolutePkgJsonPath} to ${versionToSet}`));
const pkgContent = await fs.readJson(absolutePkgJsonPath, 'utf-8');
pkgContent.version = versionToSet;
await fs.writeJson(absolutePkgJsonPath, pkgContent, {spaces: 2});
}