Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions scripts/rename-sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ──────────────────────────────────────────────────────────
Expand Down Expand Up @@ -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) {
Expand All @@ -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) });
}
}
Expand Down
22 changes: 12 additions & 10 deletions scripts/scaffold-screens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ──────────────────────────────────────────────────────────
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down