Move business logic out of App Router into module packages, add boundary validation scripts, and keep all routes as thin re-exports without changing URLs or API behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
2.0 KiB
JavaScript
51 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Bulk-update Beauty module import paths after migration to modules/beauty.
|
|
*/
|
|
import { readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
|
import { join, relative } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const ROOT = join(fileURLToPath(new URL(".", import.meta.url)), "..");
|
|
const EXT = new Set([".ts", ".tsx"]);
|
|
const SKIP = new Set(["node_modules", ".next"]);
|
|
|
|
const REPLACEMENTS = [
|
|
["@/components/beauty/design-system", "@/modules/beauty/design-system"],
|
|
["@/components/beauty/pages/", "@/modules/beauty/pages/"],
|
|
["@/components/beauty/BeautyPortalShell", "@/modules/beauty/components/BeautyPortalShell"],
|
|
["@/components/beauty/PublicBeautyLayout", "@/modules/beauty/components/PublicBeautyLayout"],
|
|
["@/components/beauty/createPortalLayout", "@/modules/beauty/components/createPortalLayout"],
|
|
["@/components/beauty/BeautyBusinessShell", "@/modules/beauty/components/BeautyBusinessShell"],
|
|
["@/lib/beauty-business-api", "@/modules/beauty/services/beauty-business-api"],
|
|
["@/lib/beauty-portals", "@/modules/beauty/constants/portals"],
|
|
["@/hooks/useBeautyLookups", "@/modules/beauty/hooks/useBeautyLookups"],
|
|
];
|
|
|
|
function walk(dir, files = []) {
|
|
for (const entry of readdirSync(dir)) {
|
|
if (SKIP.has(entry)) continue;
|
|
const full = join(dir, entry);
|
|
if (statSync(full).isDirectory()) walk(full, files);
|
|
else if (EXT.has(entry.slice(entry.lastIndexOf(".")))) files.push(full);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
let changed = 0;
|
|
for (const file of walk(ROOT)) {
|
|
const rel = relative(ROOT, file);
|
|
if (rel.startsWith("scripts/migrate-beauty-imports.mjs")) continue;
|
|
let content = readFileSync(file, "utf8");
|
|
const original = content;
|
|
for (const [from, to] of REPLACEMENTS) {
|
|
content = content.split(from).join(to);
|
|
}
|
|
if (content !== original) {
|
|
writeFileSync(file, content, "utf8");
|
|
changed++;
|
|
}
|
|
}
|
|
|
|
console.log(`Updated imports in ${changed} files.`);
|