@synchronized-studio/cmsassets-agent 0.3.7 → 0.3.9

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/cli.js CHANGED
@@ -9,21 +9,21 @@ import {
9
9
  saveReport,
10
10
  scan,
11
11
  verify
12
- } from "./chunk-6B2ZEEDF.js";
12
+ } from "./chunk-WXCGZDUK.js";
13
13
  import "./chunk-KYRW5D2O.js";
14
14
  import "./chunk-E74TGIFQ.js";
15
15
  import "./chunk-QGM4M3NI.js";
16
16
 
17
17
  // src/cli.ts
18
18
  import { existsSync as existsSync5 } from "fs";
19
- import { dirname as pathDirname, resolve as resolve6 } from "path";
19
+ import { dirname as pathDirname, resolve as resolve7 } from "path";
20
20
  import { fileURLToPath } from "url";
21
21
  import { defineCommand as defineCommand8, runMain } from "citty";
22
22
  import { config as dotenvConfig } from "dotenv";
23
23
 
24
24
  // src/commands/init.ts
25
25
  import { createInterface } from "readline";
26
- import { resolve } from "path";
26
+ import { resolve as resolve2 } from "path";
27
27
  import { defineCommand } from "citty";
28
28
  import consola3 from "consola";
29
29
  import pc from "picocolors";
@@ -60,7 +60,7 @@ function injectNpmScript(projectRoot) {
60
60
 
61
61
  // src/patcher/injectNuxtRuntimeConfig.ts
62
62
  import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
63
- import { join as join2 } from "path";
63
+ import { join as join2, dirname, resolve } from "path";
64
64
  import consola2 from "consola";
65
65
  function injectNuxtRuntimeConfig(projectRoot) {
66
66
  const candidates = ["nuxt.config.ts", "nuxt.config.js", "nuxt.config.mjs"];
@@ -69,59 +69,141 @@ function injectNuxtRuntimeConfig(projectRoot) {
69
69
  return { added: false, reason: "No nuxt.config found" };
70
70
  }
71
71
  const absPath = join2(projectRoot, configFile);
72
- let content = readFileSync2(absPath, "utf-8");
72
+ const content = readFileSync2(absPath, "utf-8");
73
73
  if (content.includes("cmsAssetsUrl")) {
74
74
  return { added: false, reason: "cmsAssetsUrl already present in nuxt.config" };
75
75
  }
76
+ const externalResult = tryInjectInExternalRuntimeConfig(absPath, content, projectRoot);
77
+ if (externalResult) return externalResult;
78
+ if (hasRuntimeConfigShorthand(content)) {
79
+ return {
80
+ added: false,
81
+ reason: "runtimeConfig appears as a shorthand property (likely imported as a variable) but source file could not be resolved. Add cmsAssetsUrl manually."
82
+ };
83
+ }
84
+ return injectInline(absPath, configFile, content);
85
+ }
86
+ var ENTRY = `cmsAssetsUrl: process.env.CMS_ASSETS_URL || ''`;
87
+ function hasRuntimeConfigShorthand(content) {
88
+ return /\bruntimeConfig\s*[,\n]/.test(content) && !/runtimeConfig\s*:/.test(content);
89
+ }
90
+ function tryInjectInExternalRuntimeConfig(nuxtConfigPath, content, projectRoot) {
91
+ const importRe = /import\s+runtimeConfig\s+from\s+["']([^"']+)["']/;
92
+ const requireRe = /(?:const|let|var)\s+runtimeConfig\s*=\s*require\s*\(\s*["']([^"']+)["']\s*\)/;
93
+ const importMatch = content.match(importRe) || content.match(requireRe);
94
+ if (!importMatch) return null;
95
+ const importPath = importMatch[1];
96
+ const configDir = dirname(nuxtConfigPath);
97
+ const extensions = ["", ".ts", ".js", ".mjs"];
98
+ let externalPath = null;
99
+ for (const ext of extensions) {
100
+ const candidate = resolve(configDir, importPath + ext);
101
+ if (existsSync2(candidate)) {
102
+ externalPath = candidate;
103
+ break;
104
+ }
105
+ }
106
+ if (!externalPath) {
107
+ return {
108
+ added: false,
109
+ reason: `runtimeConfig is imported from "${importPath}" but the file was not found`
110
+ };
111
+ }
112
+ let extContent = readFileSync2(externalPath, "utf-8");
113
+ if (extContent.includes("cmsAssetsUrl")) {
114
+ return { added: false, reason: "cmsAssetsUrl already present in external runtimeConfig file" };
115
+ }
116
+ const indentMatch = extContent.match(/^( +)\S/m);
117
+ const indent = indentMatch?.[1] ?? " ";
118
+ const i2 = indent.repeat(2);
119
+ const publicBlockRe = /(public\s*:\s*\{)(\s*)/;
120
+ if (publicBlockRe.test(extContent)) {
121
+ extContent = extContent.replace(publicBlockRe, `$1$2${i2}${ENTRY},
122
+ `);
123
+ writeFileSync2(externalPath, extContent, "utf-8");
124
+ const relPath = externalPath.replace(projectRoot + "/", "");
125
+ consola2.success(`Added cmsAssetsUrl to public block in ${relPath}`);
126
+ return { added: true, file: relPath };
127
+ }
128
+ const exportObjRe = /(export\s+default\s*\{)(\s*)/;
129
+ if (exportObjRe.test(extContent)) {
130
+ const block = `$1$2${indent}public: {
131
+ ${i2}${ENTRY},
132
+ ${indent}},
133
+ `;
134
+ extContent = extContent.replace(exportObjRe, block);
135
+ writeFileSync2(externalPath, extContent, "utf-8");
136
+ const relPath = externalPath.replace(projectRoot + "/", "");
137
+ consola2.success(`Added runtimeConfig.public.cmsAssetsUrl in ${relPath}`);
138
+ return { added: true, file: relPath };
139
+ }
140
+ const defineRe = /(defineNuxtConfig\s*\(\s*\{|(?:const|let)\s+\w+\s*=\s*\{)(\s*)/;
141
+ if (defineRe.test(extContent)) {
142
+ const block = `$1$2${indent}public: {
143
+ ${i2}${ENTRY},
144
+ ${indent}},
145
+ `;
146
+ extContent = extContent.replace(defineRe, block);
147
+ writeFileSync2(externalPath, extContent, "utf-8");
148
+ const relPath = externalPath.replace(projectRoot + "/", "");
149
+ consola2.success(`Added runtimeConfig.public.cmsAssetsUrl in ${relPath}`);
150
+ return { added: true, file: relPath };
151
+ }
152
+ return {
153
+ added: false,
154
+ reason: `runtimeConfig is imported from "${importPath}" but could not find insertion point in that file`
155
+ };
156
+ }
157
+ function injectInline(absPath, configFile, content) {
158
+ let modified = content;
76
159
  const indentMatch = content.match(/^( +)\S/m);
77
160
  const indent = indentMatch?.[1] ?? " ";
78
161
  const i2 = indent.repeat(2);
79
162
  const i3 = indent.repeat(3);
80
- const entry = `cmsAssetsUrl: process.env.CMS_ASSETS_URL || ''`;
81
163
  const publicBlockRe = /(runtimeConfig\s*:\s*\{[^}]*?public\s*:\s*\{)(\s*)/;
82
- if (publicBlockRe.test(content)) {
83
- content = content.replace(publicBlockRe, `$1$2${i3}${entry},
164
+ if (publicBlockRe.test(modified)) {
165
+ modified = modified.replace(publicBlockRe, `$1$2${i3}${ENTRY},
84
166
  `);
85
- writeFileSync2(absPath, content, "utf-8");
167
+ writeFileSync2(absPath, modified, "utf-8");
86
168
  consola2.success(`Added cmsAssetsUrl to runtimeConfig.public in ${configFile}`);
87
- return { added: true };
169
+ return { added: true, file: configFile };
88
170
  }
89
171
  const runtimeConfigRe = /(runtimeConfig\s*:\s*\{)(\s*)/;
90
- if (runtimeConfigRe.test(content)) {
172
+ if (runtimeConfigRe.test(modified)) {
91
173
  const publicBlock = `$1$2${i2}public: {
92
- ${i3}${entry},
174
+ ${i3}${ENTRY},
93
175
  ${i2}},
94
176
  `;
95
- content = content.replace(runtimeConfigRe, publicBlock);
96
- writeFileSync2(absPath, content, "utf-8");
177
+ modified = modified.replace(runtimeConfigRe, publicBlock);
178
+ writeFileSync2(absPath, modified, "utf-8");
97
179
  consola2.success(`Added runtimeConfig.public.cmsAssetsUrl in ${configFile}`);
98
- return { added: true };
180
+ return { added: true, file: configFile };
99
181
  }
100
182
  const defineConfigRe = /(defineNuxtConfig\s*\(\s*\{)(\s*)/;
101
- if (defineConfigRe.test(content)) {
183
+ if (defineConfigRe.test(modified)) {
102
184
  const block = `$1$2${indent}runtimeConfig: {
103
185
  ${i2}public: {
104
- ${i3}${entry},
186
+ ${i3}${ENTRY},
105
187
  ${i2}},
106
188
  ${indent}},
107
189
  `;
108
- content = content.replace(defineConfigRe, block);
109
- writeFileSync2(absPath, content, "utf-8");
190
+ modified = modified.replace(defineConfigRe, block);
191
+ writeFileSync2(absPath, modified, "utf-8");
110
192
  consola2.success(`Added runtimeConfig.public.cmsAssetsUrl in ${configFile}`);
111
- return { added: true };
193
+ return { added: true, file: configFile };
112
194
  }
113
195
  const exportRe = /(export\s+default\s*\{)(\s*)/;
114
- if (exportRe.test(content)) {
196
+ if (exportRe.test(modified)) {
115
197
  const block = `$1$2${indent}runtimeConfig: {
116
198
  ${i2}public: {
117
- ${i3}${entry},
199
+ ${i3}${ENTRY},
118
200
  ${i2}},
119
201
  ${indent}},
120
202
  `;
121
- content = content.replace(exportRe, block);
122
- writeFileSync2(absPath, content, "utf-8");
203
+ modified = modified.replace(exportRe, block);
204
+ writeFileSync2(absPath, modified, "utf-8");
123
205
  consola2.success(`Added runtimeConfig.public.cmsAssetsUrl in ${configFile}`);
124
- return { added: true };
206
+ return { added: true, file: configFile };
125
207
  }
126
208
  return { added: false, reason: "Could not find insertion point in nuxt.config" };
127
209
  }
@@ -129,10 +211,10 @@ ${indent}},
129
211
  // src/commands/init.ts
130
212
  function confirm(question) {
131
213
  const rl = createInterface({ input: process.stdin, output: process.stdout });
132
- return new Promise((resolve7) => {
214
+ return new Promise((resolve8) => {
133
215
  rl.question(question, (answer) => {
134
216
  rl.close();
135
- resolve7(answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes");
217
+ resolve8(answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes");
136
218
  });
137
219
  });
138
220
  }
@@ -232,7 +314,7 @@ var initCommand = defineCommand({
232
314
  }
233
315
  },
234
316
  async run({ args }) {
235
- const root = resolve(args.dir);
317
+ const root = resolve2(args.dir);
236
318
  consola3.log("");
237
319
  consola3.log(pc.bold(" CMS Assets Agent \u2014 Init"));
238
320
  consola3.log(pc.dim(" \u2500".repeat(25)));
@@ -388,9 +470,14 @@ var initCommand = defineCommand({
388
470
  }
389
471
  }
390
472
  let runtimeConfigAdded = false;
473
+ let runtimeConfigFile = "nuxt.config";
391
474
  if (scanResult.framework.name === "nuxt") {
392
475
  const rcResult = injectNuxtRuntimeConfig(root);
393
476
  runtimeConfigAdded = rcResult.added;
477
+ if (rcResult.file) runtimeConfigFile = rcResult.file;
478
+ if (!rcResult.added && rcResult.reason) {
479
+ consola3.warn(` ${pc.yellow("runtimeConfig:")} ${rcResult.reason}`);
480
+ }
394
481
  }
395
482
  let scriptAdded = false;
396
483
  if (!args["no-script"]) {
@@ -418,7 +505,7 @@ var initCommand = defineCommand({
418
505
  consola3.log(` ${pc.yellow("Skipped:")} ${skipped.length + manualReview.length} files`);
419
506
  }
420
507
  if (installed) consola3.log(` ${pc.green("Installed:")} @synchronized-studio/response-transformer`);
421
- if (runtimeConfigAdded) consola3.log(` ${pc.green("Config:")} Added runtimeConfig.public.cmsAssetsUrl to nuxt.config`);
508
+ if (runtimeConfigAdded) consola3.log(` ${pc.green("Config:")} Added runtimeConfig.public.cmsAssetsUrl to ${runtimeConfigFile}`);
422
509
  if (scriptAdded) consola3.log(` ${pc.green("Script:")} Added "cmsassets:transform" to package.json`);
423
510
  consola3.log("");
424
511
  for (const file of applied) {
@@ -596,7 +683,7 @@ var planCommand = defineCommand3({
596
683
 
597
684
  // src/commands/apply.ts
598
685
  import { existsSync as existsSync3 } from "fs";
599
- import { join as join3, resolve as resolve2 } from "path";
686
+ import { join as join3, resolve as resolve3 } from "path";
600
687
  import { defineCommand as defineCommand4 } from "citty";
601
688
  import consola6 from "consola";
602
689
  import pc4 from "picocolors";
@@ -706,7 +793,7 @@ var applyCommand = defineCommand4({
706
793
  }
707
794
  },
708
795
  async run({ args }) {
709
- const root = resolve2(args.dir);
796
+ const root = resolve3(args.dir);
710
797
  if (gitOps.isGitRepo(root) && !args["allow-dirty"] && !gitOps.isClean(root)) {
711
798
  consola6.error(
712
799
  "Git worktree is dirty. Commit or stash changes first, or use --allow-dirty."
@@ -715,7 +802,7 @@ var applyCommand = defineCommand4({
715
802
  }
716
803
  let plan;
717
804
  if (args.plan) {
718
- const planPath = resolve2(args.plan);
805
+ const planPath = resolve3(args.plan);
719
806
  const loaded = loadPlanFile(planPath);
720
807
  if (!loaded) {
721
808
  consola6.error(`Invalid plan file: ${planPath}`);
@@ -914,7 +1001,7 @@ function generatePlan(root, args) {
914
1001
  }
915
1002
 
916
1003
  // src/commands/verify.ts
917
- import { resolve as resolve3 } from "path";
1004
+ import { resolve as resolve4 } from "path";
918
1005
  import { defineCommand as defineCommand5 } from "citty";
919
1006
  import consola7 from "consola";
920
1007
  import pc5 from "picocolors";
@@ -936,7 +1023,7 @@ var verifyCommand = defineCommand5({
936
1023
  }
937
1024
  },
938
1025
  async run({ args }) {
939
- const root = resolve3(args.dir);
1026
+ const root = resolve4(args.dir);
940
1027
  const scanResult = scan(root);
941
1028
  consola7.log("");
942
1029
  consola7.log(pc5.bold(` CMS Assets Agent \u2014 Verify (${args.profile})`));
@@ -967,7 +1054,7 @@ var verifyCommand = defineCommand5({
967
1054
 
968
1055
  // src/commands/doctor.ts
969
1056
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
970
- import { resolve as resolve4, join as join4 } from "path";
1057
+ import { resolve as resolve5, join as join4 } from "path";
971
1058
  import { defineCommand as defineCommand6 } from "citty";
972
1059
  import consola8 from "consola";
973
1060
  import pc6 from "picocolors";
@@ -984,7 +1071,7 @@ var doctorCommand = defineCommand6({
984
1071
  }
985
1072
  },
986
1073
  async run({ args }) {
987
- const root = resolve4(args.dir);
1074
+ const root = resolve5(args.dir);
988
1075
  const checks = [];
989
1076
  checks.push({
990
1077
  label: "package.json",
@@ -1077,7 +1164,7 @@ var doctorCommand = defineCommand6({
1077
1164
  });
1078
1165
 
1079
1166
  // src/commands/rollback.ts
1080
- import { resolve as resolve5 } from "path";
1167
+ import { resolve as resolve6 } from "path";
1081
1168
  import { defineCommand as defineCommand7 } from "citty";
1082
1169
  import consola9 from "consola";
1083
1170
  import pc7 from "picocolors";
@@ -1098,7 +1185,7 @@ var rollbackCommand = defineCommand7({
1098
1185
  }
1099
1186
  },
1100
1187
  async run({ args }) {
1101
- const root = resolve5(args.dir);
1188
+ const root = resolve6(args.dir);
1102
1189
  if (!gitOps.isGitRepo(root)) {
1103
1190
  consola9.error("Not a git repository. Cannot rollback.");
1104
1191
  process.exit(1);
@@ -1154,9 +1241,9 @@ var main = defineCommand8({
1154
1241
  var cwd = process.cwd();
1155
1242
  var cliDir = typeof __dirname !== "undefined" ? __dirname : pathDirname(fileURLToPath(import.meta.url));
1156
1243
  function findProjectRootEnv(startDir) {
1157
- let dir = resolve6(startDir);
1244
+ let dir = resolve7(startDir);
1158
1245
  for (let i = 0; i < 6; i++) {
1159
- const envPath = resolve6(dir, ".env");
1246
+ const envPath = resolve7(dir, ".env");
1160
1247
  if (existsSync5(envPath)) return envPath;
1161
1248
  const parent = pathDirname(dir);
1162
1249
  if (parent === dir) break;
@@ -1166,8 +1253,8 @@ function findProjectRootEnv(startDir) {
1166
1253
  }
1167
1254
  var envPaths = [];
1168
1255
  var explicitEnv = process.env.DOTENV_CONFIG_PATH || process.env.CMSASSETS_ENV_FILE;
1169
- if (explicitEnv) envPaths.push(resolve6(cwd, explicitEnv));
1170
- envPaths.push(resolve6(cwd, ".env"));
1256
+ if (explicitEnv) envPaths.push(resolve7(cwd, explicitEnv));
1257
+ envPaths.push(resolve7(cwd, ".env"));
1171
1258
  var projectRootEnv = findProjectRootEnv(cliDir);
1172
1259
  if (projectRootEnv && !envPaths.includes(projectRootEnv)) envPaths.push(projectRootEnv);
1173
1260
  for (const p of envPaths) {
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  saveReport,
27
27
  scan,
28
28
  verify
29
- } from "./chunk-6B2ZEEDF.js";
29
+ } from "./chunk-WXCGZDUK.js";
30
30
  import {
31
31
  aiReviewAll
32
32
  } from "./chunk-Q3VHF32G.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synchronized-studio/cmsassets-agent",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "CLI agent that auto-integrates @synchronized-studio/response-transformer into any JS/TS project.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",