pidgin/nest

9cec1f3e6b5d
Parents 329580335d86
Children 07a3269fd83d
Adds tracking tool, missed in #a7af424b56ba
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migrate-tracker.js Thu Jan 17 19:54:21 2019 +0000
@@ -0,0 +1,75 @@
+const fs = require("fs");
+const path = require("path");
+const front = require("front-matter");
+
+const paths = fs
+ .readFileSync(path.join(__dirname, "paths.txt"), "utf8")
+ .split("\r\n");
+const covered = new Set();
+
+function getFront(path) {
+ try {
+ const data = fs.readFileSync(path, "utf8");
+
+ const { attributes } = front(data);
+
+ return attributes;
+ } catch (error) {
+ console.log(error);
+ }
+}
+
+const mdRegex = /\.md$/;
+
+function getMdPaths(input) {
+ let output = [];
+ let items = fs.readdirSync(input).map(i => path.join(input, i));
+
+ while (items.length) {
+ const item = items.pop();
+ const stat = fs.statSync(item);
+
+ if (stat.isDirectory()) {
+ const nueveau = fs.readdirSync(item).map(i => path.join(item, i));
+ items.push(...nueveau);
+ } else if (stat.isFile() && mdRegex.test(item)) {
+ output.push(item);
+ }
+ }
+
+ return output.sort();
+}
+
+getMdPaths(path.join(__dirname, "../content/"))
+ .map(path => {
+ let replaces = getFront(path).replaces;
+
+ if (!replaces) {
+ replaces = [];
+ } else if (typeof replaces === "string") {
+ replaces = [replaces];
+ } else if (!Array.isArray(replaces)) {
+ throw new Error(
+ `expected replaces of ${path} to be falsey, string or an array`
+ );
+ }
+
+ return {
+ replaces,
+ path,
+ relative: path
+ .replace("/mnt/c/Users/J/code/pidgin-nest/content", "")
+ .replace(/\.md$/, "")
+ .replace(/_index(\.\w\w)?$/, "")
+ };
+ })
+ .forEach(page => page.replaces.forEach(path => covered.add(path)));
+
+const countOfCovered = paths.reduce(
+ (acc, path) => acc + (covered.has(path) ? 1 : 0),
+ 0
+);
+
+console.log(
+ `Currently there are ${countOfCovered} of ${paths.length} pages covered`
+);