-
Notifications
You must be signed in to change notification settings - Fork 19
/
version.js
52 lines (43 loc) · 1.56 KB
/
version.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { argv } = require('yargs');
const { join } = require('path');
const { writeFileSync } = require('fs');
const { EOL } = require('os');
if (argv._.length !== 1) {
throw new Error('Provide version x.x.x to the argument');
}
const version = argv._[0];
const part = version.split('-')[0];
const format = part.split('.');
if (format.filter(f => f !== '').length !== 3) {
throw new Error('The version should be matched to the x.x.x format');
}
const projects = [
'./book/package.json',
'./next/api/package.json',
'./next/web-client/package.json',
'./packages/babel/package.json',
'./packages/codestyle/package.json',
'./packages/compiler/package.json',
'./packages/starter/package.json',
'./packages/tester/package.json',
'./packages/tsconfig/package.json',
'./packages/utils/package.json',
'./package.json'
];
for (let projectPath of projects) {
const pthPackageJson = join(__dirname, projectPath);
const file = require(pthPackageJson);
const { dependencies, devDependencies } = file;
const depKeys = dependencies ? Object.keys(dependencies) : [];
const devDepKeys = devDependencies ? Object.keys(devDependencies) : [];
const depKeysExisted = depKeys.filter(dep => dep.indexOf('@rockpack/') === 0);
const devDepKeysExisted = devDepKeys.filter(dep => dep.indexOf('@rockpack/') === 0);
file.version = version;
depKeysExisted.forEach(k => {
file.dependencies[k] = version;
});
devDepKeysExisted.forEach(k => {
file.devDependencies[k] = version;
});
writeFileSync(pthPackageJson, JSON.stringify(file, null, 2) + EOL, 'utf-8');
}