38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/**
|
|
* `wrnexus eject <name...>` — copy a Wire UI component's `.wrn` source into the
|
|
* app's `app/components/`, so you fully own and can edit it. The auto-discovered
|
|
* library version is shadowed by the app copy (same name → app wins).
|
|
*/
|
|
|
|
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
import { join, resolve } from "node:path";
|
|
import { uiComponentsDir, uiComponentNames } from "@wrnexus/ui";
|
|
|
|
export function runEject(appRoot: string, names: string[]): void {
|
|
const root = resolve(appRoot);
|
|
const dest = join(root, "app", "components");
|
|
const available = uiComponentNames();
|
|
|
|
if (names.length === 0) {
|
|
console.log("Usage: wrnexus eject <name...>\n\nAvailable components:");
|
|
console.log(" " + available.join(", "));
|
|
return;
|
|
}
|
|
|
|
mkdirSync(dest, { recursive: true });
|
|
for (const name of names) {
|
|
if (!available.includes(name)) {
|
|
console.error(`✗ Unknown component "${name}". Available: ${available.join(", ")}`);
|
|
continue;
|
|
}
|
|
const src = join(uiComponentsDir(), `${name}.wrn`);
|
|
const out = join(dest, `${name}.wrn`);
|
|
if (existsSync(out)) {
|
|
console.error(`✗ ${name}: app/components/${name}.wrn already exists — skipped`);
|
|
continue;
|
|
}
|
|
copyFileSync(src, out);
|
|
console.log(`✓ Ejected ${name} -> app/components/${name}.wrn`);
|
|
}
|
|
}
|