forked from tiampersian/kendo-jalali-date-inputs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade-version.js
58 lines (50 loc) · 1.42 KB
/
upgrade-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
53
54
55
56
57
58
var myArgs = process.argv.slice(2);
const fs = require('fs');
const { exec } = require("child_process");
const saveFile = fs.writeFileSync;
const pkgJsonPath = "./package.json";
const json = require(pkgJsonPath);
async function upgradeProjectPackage(){
console.info('go to upgradeProjectPackage()');
if (!fs.existsSync(pkgJsonPath)) {
console.log('update()');
return;
}
await updatePackages(json['dependencies']);
await updatePackages(json['devDependencies']);
}
async function updatePackages(dependencies) {
const p=new Promise((r)=>{
let counter2=0;
let counter=0;
for (const key in dependencies) {
counter++;
exec(`npm view ${key} version`, (err, stdout, stderr) => {
counter2++;
if(counter2>=counter){
setTimeout(() => {
r();
});
}
if (err) {
console.error(`npm view ${key} version`, err);
return;
}
console.log(`npm view ${key} version`, stdout);
dependencies[key] = stdout.replace('\n', '');
saveFile(pkgJsonPath, JSON.stringify(json, null, 2));
});
}
})
return p;
}
upgradeProjectPackage();
function setLibraryVersion(lib) {
const pkgJsonPath = libraryFolder + lib + "/package.json";
if (!fs.existsSync(pkgJsonPath)) {
return;
}
const json = require(pkgJsonPath);
json['version'] = version;
saveFile(pkgJsonPath, JSON.stringify(json, null, 2));
}