Skip to content

Commit

Permalink
creates cache2git script
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Jul 28, 2023
1 parent e155404 commit 0d20315
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/cache2git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#! /usr/bin/env node

const fs = require("fs");
const shell = require("shelljs");
const {nest} = require("d3-collection");

const folder = process.argv[2];

if (!folder) {
console.error("Please provide a folder of results as the first argument.");
shell.exit(1);
}

let txt = "";

fs.readdir(folder, (err, files) => {
files.forEach(file => {
if (!file.includes("results")) {
const profile = file.match(/profile_([a-z]{3})/)[1];
const results = JSON.parse(fs.readFileSync(`${folder}/${file}`));
console.log(profile, results.length);
if (results.length) txt += `## \`${profile}\` profile`;
nest()
.key(arr => arr[1][0])
.entries(results)
.sort((a, b) => b.values.length - a.values.length)
.forEach(group => {
const url = group.key;
const slug = url.match(/profile\/[a-z]+\/([a-z\-]+)/)[1];
const nas = group.values.length;
console.log(slug, nas);
txt += `\n - [ ] [${slug}](${url}) (${nas} N/A${nas > 1 ? "s" : ""})`;
})
if (results.length) txt += `\n\n---\n\n`;
}
});

fs.writeFile("./scripts/cache-result.md", txt, "utf8", err => {
if (err) {
console.log(err);
shell.exit(1);
}
else {
console.log("created scripts/cache-result.md");
shell.exit(0);
}
});

});

0 comments on commit 0d20315

Please sign in to comment.