From 86e4aa9118a8fdc88022abaa4f8f9a03e6ffaa72 Mon Sep 17 00:00:00 2001 From: jkarthid Date: Fri, 29 May 2026 20:15:13 +0530 Subject: [PATCH] Make getTranscripts cross-platform (remove Unix find dependency) format.js discovered transcripts via `find **/*.md`, which fails on Windows (find is a text-search tool there) and relied on sh glob semantics. Replace it with a pure-Node fs.readdir walk that collects transcripts one directory deep, skipping hidden/node_modules/scripts folders. Also add assertions to the previously empty getTranscripts test. --- scripts/format.js | 32 ++++++++++++++++++++++++-------- scripts/format.test.js | 6 +++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index b7d96c40c..345d88dda 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -1,6 +1,5 @@ -const util = require('util'); -const exec = util.promisify(require('child_process').exec); const fs = require('fs').promises +const path = require('path') const REPLACES = [ [/([^/])\bjavascript/gi, '$1JavaScript'], // stylise javascript to JavaScript @@ -37,12 +36,29 @@ function applyReplaces(text) { return REPLACES.reduce((prev, [a, b]) => prev.replace(a, b), text) } -// Returns an array of the filenames of all the episodes -async function getTranscripts() { - const { stdout } = await exec('find **/*.md') - return stdout - .split('\n') // make an array - .filter(x => x.endsWith('.md')) // remove blanks +// Returns an array of the filenames of all the episodes. +// Transcripts live one directory deep (e.g. afk/away-from-keyboard-1.md), so we +// read each top-level podcast directory and collect its Markdown files. This is +// cross-platform (no reliance on a Unix `find`) and skips hidden/tooling folders. +async function getTranscripts(dir = '.') { + const entries = await fs.readdir(dir, { withFileTypes: true }) + const perDirectory = await Promise.all( + entries + .filter(entry => + entry.isDirectory() && + !entry.name.startsWith('.') && + entry.name !== 'node_modules' && + entry.name !== 'scripts' + ) + .map(async entry => { + const subdir = path.join(dir, entry.name) + const files = await fs.readdir(subdir) + return files + .filter(name => name.endsWith('.md')) + .map(name => path.join(subdir, name)) + }) + ) + return perDirectory.flat() } // Read a textfile to a string, pass the string through processor, and write the results out to a file diff --git a/scripts/format.test.js b/scripts/format.test.js index 82798b8e3..16581fa89 100644 --- a/scripts/format.test.js +++ b/scripts/format.test.js @@ -89,7 +89,11 @@ test("WebAssembly is a single word proper noun", () => { test('getTranscripts works as expected', async () => { const transcripts = await getTranscripts() - // TODO: What are good ways to test this function? + expect(Array.isArray(transcripts)).toBe(true) + expect(transcripts.length).toBeGreaterThan(0) + expect(transcripts.every(name => name.endsWith('.md'))).toBe(true) + // Transcripts live one directory deep, never at the repo root + expect(transcripts.every(name => name.includes(path.sep))).toBe(true) })