forked from gregorwolf/SAP-NPM-API-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-package-json.js
55 lines (54 loc) · 1.67 KB
/
update-package-json.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
const search = require("libnpmsearch");
const fs = require("fs");
(async () => {
var packageDotJson = "package.json";
var packagesTxt = "";
let from = 0;
let limit = 50;
let total = 0;
let packagesSearchResult = [];
let packages = {};
do {
packagesSearchResult = await search("@sap", { from: from, limit: limit });
total += packagesSearchResult.length;
for (let i in packagesSearchResult) {
var package = packagesSearchResult[i];
if (
// No matching version found for [email protected]
package.name !== "@sap/wing-service-binding" &&
// Verification failed while extracting @sap/[email protected]
package.name !== "@sap/textbundle" &&
// Verification failed while extracting @sap/[email protected]:
package.name !== "@sap/logging"
) {
}
packages[package.name] = package.version;
}
from = from + limit;
} while (packagesSearchResult.length > 0);
console.log(`Found ${total} package(s)`);
// console.log(packages);
const ordered = {};
Object.keys(packages)
.sort()
.forEach(function (key) {
ordered[key] = packages[key];
packagesTxt += key + "\n";
});
fs.readFile(packageDotJson, function (err, packageData) {
var packageJson = JSON.parse(packageData);
packageJson.dependencies = ordered;
fs.writeFile(
"new-" + packageDotJson,
JSON.stringify(packageJson),
function (err) {
if (err) throw err;
console.log("The dependencies where updated");
}
);
fs.writeFile("packages.txt", packagesTxt, function (err) {
if (err) throw err;
console.log("The file packages.txt was updated");
});
});
})();