@getcoherent/core 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3580,6 +3580,8 @@ interface GenerateSharedComponentInput {
|
|
|
3580
3580
|
description?: string;
|
|
3581
3581
|
/** Files that will use this component (e.g. ["app/layout.tsx"]). */
|
|
3582
3582
|
usedIn?: string[];
|
|
3583
|
+
/** If true, overwrite an existing component with the same name instead of creating a uniquely-named copy. */
|
|
3584
|
+
overwrite?: boolean;
|
|
3583
3585
|
}
|
|
3584
3586
|
interface GenerateSharedComponentResult {
|
|
3585
3587
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -6261,6 +6261,15 @@ function getDefaultTemplate(componentName, type, name) {
|
|
|
6261
6261
|
}
|
|
6262
6262
|
async function generateSharedComponent(projectRoot, input) {
|
|
6263
6263
|
const manifest = await loadManifest(projectRoot);
|
|
6264
|
+
const existing = input.overwrite ? manifest.shared.find((e) => e.name === input.name) : void 0;
|
|
6265
|
+
if (existing) {
|
|
6266
|
+
const fullPath2 = join2(projectRoot, existing.file);
|
|
6267
|
+
const componentName2 = existing.name.replace(/[^a-zA-Z0-9]/g, "") || "Block";
|
|
6268
|
+
const code2 = input.code ?? getDefaultTemplate(componentName2, input.type, existing.name);
|
|
6269
|
+
await mkdir2(dirname2(fullPath2), { recursive: true });
|
|
6270
|
+
await writeFile3(fullPath2, code2, "utf-8");
|
|
6271
|
+
return { id: existing.id, name: existing.name, file: existing.file };
|
|
6272
|
+
}
|
|
6264
6273
|
const uniqueName = resolveUniqueName(manifest, input.name);
|
|
6265
6274
|
const fileName = toSharedFileName(uniqueName);
|
|
6266
6275
|
const filePath = `components/shared/${fileName}.tsx`;
|