-
Notifications
You must be signed in to change notification settings - Fork 252
/
Copy pathversionsUpdater.js
60 lines (49 loc) · 1.84 KB
/
versionsUpdater.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
53
54
55
56
57
58
59
60
const fs = require('fs'),
path = require('path');
let exec = require('child_process').exec;
const newVersion = process.argv[2] || "1.0.0",
scope = process.argv[3] || '@nodeart';
const blackListDirs = [
'.git',
'nodeart-component-loader'
];
let getDirectories = () => {
return fs.readdirSync(path.join(__dirname, 'modules'))
.filter( item => fs.statSync(path.join(__dirname, 'modules', item)).isDirectory() && blackListDirs.indexOf(item) === -1);
};
let changeVersions = (directories) => {
directories.forEach( (directory) => {
let packageJsonFile = fs.readFileSync(path.join(__dirname, 'modules', directory, 'package.json'));
let packageJsonObj = JSON.parse(packageJsonFile);
packageJsonObj.version = newVersion;
if(packageJsonObj.dependencies) {
let dependencies = packageJsonObj.dependencies;
Object.keys(dependencies).map((dependency) => {
if(dependency.indexOf(scope) !== -1){
dependencies[dependency] = newVersion;
}
});
}
fs.writeFile(path.join(__dirname, 'modules', directory, 'package.json'), JSON.stringify(packageJsonObj, null, 2));
});
};
let publishOnline = (directories) => {
directories.forEach( (directory) => {
exec(`cd modules/${directory} && npm publish --access=public `, (err, stdout, stderr) => {
if(stderr){
console.log(stderr);
} else {
console.log(stdout);
}
});
});
};
let updateVersions = (newVersion, scope) => {
let directories = getDirectories();
changeVersions(directories);
publishOnline(directories);
};
updateVersions(newVersion, scope);
module.exports = {
updateVersions: updateVersions
}