feat: sort files based on order.json
Node.js CI / Lint and Test (push) Failing after 1m0s

This commit is contained in:
2025-10-08 10:28:12 -07:00
parent 706b9829b9
commit 6132aaef3e
5 changed files with 28 additions and 4 deletions
+1
View File
@@ -2,5 +2,6 @@ prod
node_modules node_modules
review.md review.md
content/**/* content/**/*
data/**/*
!.gitkeep !.gitkeep
fcc-review-pages.pdf fcc-review-pages.pdf
+3 -2
View File
@@ -6,8 +6,9 @@ This tool allows you to compile all of freeCodeCamp's review lessons into a sing
1. Clone the repo, `pnpm install`. 1. Clone the repo, `pnpm install`.
2. Go to the freeCodeCamp repo, copy all of the review blocks into the `content` directory here. Nested directories are fine, we walk the file tree recursively. Only markdown files will be parsed. 2. Go to the freeCodeCamp repo, copy all of the review blocks into the `content` directory here. Nested directories are fine, we walk the file tree recursively. Only markdown files will be parsed.
3. Run `pnpm start` to start reading the files, compiling them into a single doc, and turning that doc into a PDF. 3. Go to the freeCodeCamp repo, copy the Full Stack order in `/curriculum/structure/superblocks/fullstack.json` to the `data/order.json` here.
4. Profit. 4. Run `pnpm start` to start reading the files, compiling them into a single doc, and turning that doc into a PDF.
5. Profit.
## Feedback and Bugs ## Feedback and Bugs
+1
View File
@@ -0,0 +1 @@
This is where the superblock order goes.
+19 -1
View File
@@ -13,9 +13,16 @@ import {
} from "node:fs/promises"; } from "node:fs/promises";
import { join } from "node:path"; import { join } from "node:path";
import { mdToPdf } from "md-to-pdf"; import { mdToPdf } from "md-to-pdf";
import order from "../data/order.json" assert { type: "json" };
import { options } from "./config/options.js"; import { options } from "./config/options.js";
import { starterText } from "./config/text.js"; import { starterText } from "./config/text.js";
const flattenedOrder: Array<string> = order.chapters.flatMap((chapter) => {
return chapter.modules.flatMap((module) => {
return module.blocks;
});
});
const readDirectoryRecursively = async( const readDirectoryRecursively = async(
directory: string, directory: string,
): Promise<Array<string>> => { ): Promise<Array<string>> => {
@@ -31,6 +38,14 @@ const readDirectoryRecursively = async(
return files.flat(); return files.flat();
}; };
const sortFiles = (a: string, b: string): number => {
const aDashedName = a.split("/").at(1);
const bDashedName = b.split("/").at(1);
const aIndex = flattenedOrder.indexOf(aDashedName ?? "");
const bIndex = flattenedOrder.indexOf(bDashedName ?? "");
return aIndex - bIndex;
};
const rollupFiles = async( const rollupFiles = async(
inputDirectory: string, inputDirectory: string,
outputFile: string, outputFile: string,
@@ -39,7 +54,10 @@ const rollupFiles = async(
console.log("Process started..."); console.log("Process started...");
await writeFile(outputFile, `${starterText}\n`); await writeFile(outputFile, `${starterText}\n`);
console.log("Reading content directory..."); console.log("Reading content directory...");
const files = await readDirectoryRecursively(inputDirectory); const unsortedFiles = await readDirectoryRecursively(inputDirectory);
console.log(unsortedFiles);
const files = unsortedFiles.toSorted(sortFiles);
console.log("Files found, processing...");
for (const file of files) { for (const file of files) {
if (file === ".gitkeep") { if (file === ".gitkeep") {
continue; continue;
+4 -1
View File
@@ -2,6 +2,9 @@
"extends": "@nhcarrigan/typescript-config", "extends": "@nhcarrigan/typescript-config",
"compilerOptions": { "compilerOptions": {
"outDir": "./prod", "outDir": "./prod",
"rootDir": "./src" "rootDir": "./src",
"resolveJsonModule": true,
"module": "esnext",
"lib": ["es2024"]
}, },
} }