@vexblocks/cli 1.0.4 → 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.
Files changed (2) hide show
  1. package/dist/index.js +57 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -29,6 +29,11 @@ var PACKAGE_NAMES = {
29
29
  types: "Type Generator"
30
30
  };
31
31
  var MANAGED_PACKAGES = ["cms", "shared", "types"];
32
+ var PROTECTED_FILES = [
33
+ "packages/backend/vexblocks.config.ts",
34
+ "packages/backend/.env",
35
+ "packages/backend/.env.local"
36
+ ];
32
37
  var PACKAGE_DEPENDENCIES = {
33
38
  cms: ["backend", "shared"],
34
39
  backend: [],
@@ -110,7 +115,10 @@ async function fetchFile(filePath) {
110
115
  }
111
116
  return response.text();
112
117
  }
113
- async function downloadFile(remotePath, localPath) {
118
+ async function downloadFile(remotePath, localPath, options) {
119
+ if (options?.skipIfExists && await fs2.pathExists(localPath)) {
120
+ return;
121
+ }
114
122
  const url = `${GITHUB_RAW_URL}/${remotePath}`;
115
123
  const response = await fetch(url);
116
124
  if (!response.ok) {
@@ -138,8 +146,13 @@ async function downloadAndExtractPackage(packagePath, targetDir, onProgress) {
138
146
  for (const file of files) {
139
147
  const relativePath = file.path.slice(packagePath.length + 1);
140
148
  const localPath = path2.join(targetDir, relativePath);
149
+ const isProtectedFile = PROTECTED_FILES.some(
150
+ (protectedPath) => file.path.endsWith(protectedPath)
151
+ );
141
152
  onProgress?.(relativePath);
142
- await downloadFile(file.path, localPath);
153
+ await downloadFile(file.path, localPath, {
154
+ skipIfExists: isProtectedFile
155
+ });
143
156
  }
144
157
  }
145
158
  async function getPackageFiles(packagePath) {
@@ -496,23 +509,7 @@ async function installBackendPackage(targetPath, sourcePath, spinner) {
496
509
  }
497
510
  }
498
511
  }
499
- const schemaInstructions = `
500
- // === VEXBLOCKS CMS ===
501
- // Add the following imports and tables to your schema:
502
- //
503
- // import { cmsSchemaExports } from "./schema.cms"
504
- //
505
- // Then add to your defineSchema:
506
- // export default defineSchema({
507
- // ...yourExistingTables,
508
- // ...cmsSchemaExports,
509
- // })
510
- // === END VEXBLOCKS CMS ===
511
- `;
512
- const existingContent = await fs4.readFile(existingSchemaPath, "utf-8");
513
- if (!existingContent.includes("VEXBLOCKS CMS")) {
514
- await fs4.appendFile(existingSchemaPath, schemaInstructions);
515
- }
512
+ await mergeSchemaFile(existingSchemaPath, spinner);
516
513
  } else {
517
514
  await fs4.ensureDir(targetPath);
518
515
  await downloadAndExtractPackage(sourcePath, targetPath, (file) => {
@@ -574,6 +571,47 @@ function getOptionalEnvVars(packages) {
574
571
  }
575
572
  return vars;
576
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
+ }
577
615
 
578
616
  // src/commands/diff.ts
579
617
  import path5 from "path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexblocks/cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "CLI for adding VexBlocks Headless CMS to your Turborepo project",
5
5
  "keywords": [
6
6
  "cms",