Skip to content

Commit 8f1e6b8

Browse files
committed
check for potentially obsolete frameworks
1 parent f9d52f8 commit 8f1e6b8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

checkObsolete.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var _ = require("lodash");
2+
var exec = require("child_process").execSync;
3+
var fs = require("fs");
4+
var path = require("path");
5+
const JSON5 = require("json5");
6+
7+
let args = process.argv.length <= 2 ? [] : process.argv.slice(2, process.argv.length);
8+
9+
var frameworks = [].concat(
10+
fs.readdirSync("./frameworks/keyed").map((f) => ["keyed", f]),
11+
fs.readdirSync("./frameworks/non-keyed").map((f) => ["non-keyed", f])
12+
);
13+
14+
let now = new Date();
15+
let obsoleteDate = new Date(now.getFullYear() - 1, now.getMonth(), now.getDay());
16+
17+
let warnings = [];
18+
let manually = [];
19+
20+
function maybeObsolete(package) {
21+
let output;
22+
try {
23+
let output = exec(`npm view ${package} time`, {
24+
stdio: ["ignore", "pipe", "ignore"],
25+
}).toString();
26+
let r = JSON5.parse(output);
27+
return [new Date(r.modified) < obsoleteDate, package, new Date(r.modified).toISOString().substring(0, 10)];
28+
} catch (error) {
29+
console.error(`Failed to execute npm view for ${package}. Error Code ${error.status} and message: ${error.message}`);
30+
return [false, package, null];
31+
}
32+
}
33+
34+
const DEBUG = false;
35+
36+
for (f of frameworks) {
37+
let [dir, name] = f;
38+
let path = `frameworks/${dir}/${name}`;
39+
if (!fs.existsSync(path + "/package.json")) {
40+
warnings.push(`WARN: skipping ${dir}/${name} since there's no package.json`);
41+
} else {
42+
let packageJSON = JSON.parse(fs.readFileSync(path + "/package.json"));
43+
let mainPackages = packageJSON?.["js-framework-benchmark"]?.frameworkVersionFromPackage;
44+
if (mainPackages) {
45+
if (DEBUG) console.log(`Checking ${dir}/${name} ${mainPackages}`);
46+
let packages = mainPackages.split(":");
47+
let maybeObsoleteResults = packages.map((p) => maybeObsolete(p));
48+
if (DEBUG) console.log(`Results for ${dir}/${name} ${maybeObsoleteResults}`);
49+
maybeObsoleteResult = maybeObsoleteResults.some((r) => r[0]);
50+
if (maybeObsoleteResult) {
51+
console.log(
52+
`Last npm update for ${dir}/${name} ${mainPackages} is older than a year: ${maybeObsoleteResults
53+
.map((a) => a.slice(1).join(":"))
54+
.join(", ")}`
55+
);
56+
} else {
57+
if (DEBUG) console.log(` Last npm update for ${dir}/${name} ${mainPackages} is newer than a year`);
58+
}
59+
} else {
60+
manually.push(`${dir}/${name} has no frameworkVersionFromPackage`);
61+
}
62+
}
63+
}
64+
65+
if (warnings.length > 0) console.log("\nWarnings:\n" + warnings.join("\n"));
66+
if (manually.length > 0) console.log("\nThe following frameworks must be checked manually\n" + manually.join("\n"));

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"command-exists": "^1.2.9",
5656
"cross-env": "^7.0.2",
5757
"fs-extra": "9.0.0",
58+
"json5": "^2.2.0",
5859
"local-web-server": "4.1.0",
5960
"lodash": "^4.17.15",
6061
"rimraf": "^3.0.2",

0 commit comments

Comments
 (0)