diff --git a/scripts/rename-sim.ts b/scripts/rename-sim.ts index 5058c73..fab8aa2 100644 --- a/scripts/rename-sim.ts +++ b/scripts/rename-sim.ts @@ -29,7 +29,7 @@ */ import { execFileSync } from "node:child_process"; -import { readdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs"; +import { readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; // ── Argument parsing ────────────────────────────────────────────────────────── @@ -202,15 +202,14 @@ function updatePackageJson(): void { // ── Pass 1: update file contents ────────────────────────────────────────────── function processContents(dir: string): void { - for (const entry of readdirSync(dir)) { - if (SKIP_DIRS.has(entry)) { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + if (SKIP_DIRS.has(entry.name)) { continue; } - const full = join(dir, entry); - const stat = statSync(full); - if (stat.isDirectory()) { + const full = join(dir, entry.name); + if (entry.isDirectory()) { processContents(full); - } else if (TEXT_EXTS.has(fileExtension(entry))) { + } else if (entry.isFile() && TEXT_EXTS.has(fileExtension(entry.name))) { const original = readFileSync(full, "utf8"); const transformed = applyReplacements(original); if (transformed !== original) { @@ -229,16 +228,16 @@ interface RenameOp { } function collectRenames(dir: string, renameOps: RenameOp[]): void { - for (const entry of readdirSync(dir)) { - if (SKIP_DIRS.has(entry)) { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + if (SKIP_DIRS.has(entry.name)) { continue; } - const full = join(dir, entry); - if (statSync(full).isDirectory()) { + const full = join(dir, entry.name); + if (entry.isDirectory()) { collectRenames(full, renameOps); } - const newEntry = applyReplacements(entry); - if (newEntry !== entry) { + const newEntry = applyReplacements(entry.name); + if (newEntry !== entry.name) { renameOps.push({ from: full, to: join(dir, newEntry) }); } } diff --git a/scripts/scaffold-screens.ts b/scripts/scaffold-screens.ts index ad1169e..8254bb0 100644 --- a/scripts/scaffold-screens.ts +++ b/scripts/scaffold-screens.ts @@ -22,7 +22,7 @@ * --shared-model Emit src/common/model/SharedModel.ts; each screen model composes it */ -import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { basename, dirname, join, relative, resolve } from "node:path"; // ── Argument parsing ────────────────────────────────────────────────────────── @@ -234,11 +234,11 @@ function findPrototypeDir(): string { return preferred; } // Legacy post-rename layout: {id}-screen/ - for (const entry of readdirSync(SRC)) { - const full = join(SRC, entry); - if (!(statSync(full).isDirectory() && entry.endsWith("-screen"))) { + for (const entry of readdirSync(SRC, { withFileTypes: true })) { + if (!(entry.isDirectory() && entry.name.endsWith("-screen"))) { continue; } + const full = join(SRC, entry.name); const screens = readdirSync(full).filter((f) => f.endsWith("Screen.ts") && !f.includes("View")); if (screens.length === 1) { return full; @@ -250,11 +250,11 @@ function findPrototypeDir(): string { function walkFiles(dir: string): string[] { const out: string[] = []; - for (const entry of readdirSync(dir)) { - const full = join(dir, entry); - if (statSync(full).isDirectory()) { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + const full = join(dir, entry.name); + if (entry.isDirectory()) { out.push(...walkFiles(full)); - } else { + } else if (entry.isFile()) { out.push(full); } } @@ -556,10 +556,12 @@ function updateDocs(screens: ScreenSpec[], simPrefix: string): void { ]; for (const path of paths) { - if (!existsSync(path)) { + let original: string; + try { + original = readFileSync(path, "utf8"); + } catch { continue; } - const original = readFileSync(path, "utf8"); let text = original; if (basename(path) === "multi-screen.md") { for (const [from, to] of prose) {