@vexblocks/cli 1.0.5 → 1.0.6
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.js +42 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -509,23 +509,7 @@ async function installBackendPackage(targetPath, sourcePath, spinner) {
|
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
|
-
|
|
513
|
-
// === VEXBLOCKS CMS ===
|
|
514
|
-
// Add the following imports and tables to your schema:
|
|
515
|
-
//
|
|
516
|
-
// import { cmsSchemaExports } from "./schema.cms"
|
|
517
|
-
//
|
|
518
|
-
// Then add to your defineSchema:
|
|
519
|
-
// export default defineSchema({
|
|
520
|
-
// ...yourExistingTables,
|
|
521
|
-
// ...cmsSchemaExports,
|
|
522
|
-
// })
|
|
523
|
-
// === END VEXBLOCKS CMS ===
|
|
524
|
-
`;
|
|
525
|
-
const existingContent = await fs4.readFile(existingSchemaPath, "utf-8");
|
|
526
|
-
if (!existingContent.includes("VEXBLOCKS CMS")) {
|
|
527
|
-
await fs4.appendFile(existingSchemaPath, schemaInstructions);
|
|
528
|
-
}
|
|
512
|
+
await mergeSchemaFile(existingSchemaPath, spinner);
|
|
529
513
|
} else {
|
|
530
514
|
await fs4.ensureDir(targetPath);
|
|
531
515
|
await downloadAndExtractPackage(sourcePath, targetPath, (file) => {
|
|
@@ -587,6 +571,47 @@ function getOptionalEnvVars(packages) {
|
|
|
587
571
|
}
|
|
588
572
|
return vars;
|
|
589
573
|
}
|
|
574
|
+
async function mergeSchemaFile(schemaPath, spinner) {
|
|
575
|
+
const content = await fs4.readFile(schemaPath, "utf-8");
|
|
576
|
+
if (content.includes('from "./schema.cms"')) {
|
|
577
|
+
spinner.text = "CMS schema already integrated";
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
spinner.text = "Merging CMS schema into existing schema.ts...";
|
|
581
|
+
let newContent = content;
|
|
582
|
+
const importStatement = 'import { cmsSchemaExports } from "./schema.cms"';
|
|
583
|
+
const hasImport = content.includes(importStatement);
|
|
584
|
+
if (!hasImport) {
|
|
585
|
+
const importRegex = /^import\s+.*from\s+['"].*['"];?\s*$/gm;
|
|
586
|
+
const imports = [...content.matchAll(importRegex)];
|
|
587
|
+
if (imports.length > 0) {
|
|
588
|
+
const lastImport = imports[imports.length - 1];
|
|
589
|
+
const insertPosition = lastImport.index + lastImport[0].length;
|
|
590
|
+
newContent = newContent.slice(0, insertPosition) + `
|
|
591
|
+
${importStatement}` + newContent.slice(insertPosition);
|
|
592
|
+
} else {
|
|
593
|
+
newContent = `${importStatement}
|
|
594
|
+
|
|
595
|
+
${newContent}`;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const hasSpread = /defineSchema\s*\(\s*\{[^}]*\.\.\.cmsSchemaExports/s.test(
|
|
599
|
+
newContent
|
|
600
|
+
);
|
|
601
|
+
if (!hasSpread) {
|
|
602
|
+
const defineSchemaRegex = /defineSchema\s*\(\s*\{(\s*)/;
|
|
603
|
+
if (defineSchemaRegex.test(newContent)) {
|
|
604
|
+
newContent = newContent.replace(
|
|
605
|
+
defineSchemaRegex,
|
|
606
|
+
(_match, whitespace) => {
|
|
607
|
+
return `defineSchema({${whitespace}// VexBlocks CMS tables${whitespace}...cmsSchemaExports,${whitespace}`;
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
await fs4.writeFile(schemaPath, newContent, "utf-8");
|
|
613
|
+
spinner.text = "Successfully merged CMS schema";
|
|
614
|
+
}
|
|
590
615
|
|
|
591
616
|
// src/commands/diff.ts
|
|
592
617
|
import path5 from "path";
|