|
| 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")); |
0 commit comments