forked from AMPATH/ng2-amrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-snapshot.js
33 lines (30 loc) · 1.06 KB
/
package-snapshot.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
var fs = require("fs");
var package = require('./package');
const execSync = require('child_process').execSync;
function main() {
fs.readdir("./node_modules", function (err, dirs) {
if (err) {
console.log(err);
return;
}
var dependencies = {};
index = 0;
for (let dir of dirs) {
if (dir.indexOf(".") !== 0) {
var packageJsonFile = "./node_modules/" + dir + "/package.json";
if (fs.existsSync(packageJsonFile)) {
var data = fs.readFileSync(packageJsonFile);
var json = JSON.parse(data);
//console.log('"' + json.name + '": "' + json.version + '",');
dependencies[json.name] = json.version;
}
}
index++
}
var newPackage = Object.assign({}, package);
newPackage.dependencies = dependencies;
fs.writeFileSync('package-snapshot.json', JSON.stringify(newPackage, null, 4));
execSync(`git add -A`);
});
}
main()