@bravostudioai/react 0.1.32 → 0.1.34

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.
@@ -1,10 +1,10 @@
1
- import { mkdir as c, writeFile as d } from "fs/promises";
2
- import { join as p } from "path";
3
- import { existsSync as f } from "fs";
1
+ import { mkdir as a, writeFile as c } from "fs/promises";
2
+ import { join as f } from "path";
3
+ import { existsSync as d } from "fs";
4
4
  import m from "../../_virtual/main.js";
5
- import { CONST_APPS_SERVICE_URL as u, CONST_COMPONENTS_CDN_URL as E } from "../../packages/encore-lib/constants.js";
5
+ import { CONST_APPS_SERVICE_URL as u, CONST_COMPONENTS_CDN_URL as $ } from "../../packages/encore-lib/constants.js";
6
6
  m.config();
7
- const i = process.env.VITE_APPS_SERVICE_URL || u, h = E;
7
+ const l = process.env.VITE_APPS_SERVICE_URL || u, p = $;
8
8
  async function w(e, r) {
9
9
  const o = await fetch(e, {
10
10
  headers: r || {}
@@ -15,68 +15,51 @@ async function w(e, r) {
15
15
  );
16
16
  return await o.text();
17
17
  }
18
- async function $({
18
+ async function E({
19
19
  appId: e,
20
20
  pageId: r,
21
21
  targetPath: o
22
22
  }) {
23
- console.log(`Downloading Encore files for app: ${e}, page: ${r}`), console.log(`Target path: ${o}`), f(o) || (await c(o, { recursive: !0 }), console.log(`Created directory: ${o}`));
23
+ console.log(`Downloading Encore files for app: ${e}, page: ${r}`), console.log(`Target path: ${o}`), d(o) || (await a(o, { recursive: !0 }), console.log(`Created directory: ${o}`));
24
24
  const s = [
25
25
  {
26
- url: `${i}/devices/apps/${e}`,
26
+ url: `${l}/devices/apps/${e}`,
27
27
  filename: "app.json",
28
28
  headers: { "x-app-clientrendered": "true" }
29
29
  },
30
30
  {
31
- url: `${i}/devices/apps/${e}/node/${r}`,
31
+ url: `${l}/devices/apps/${e}/node/${r}`,
32
32
  filename: "page.json",
33
33
  headers: { "x-app-clientrendered": "true" }
34
34
  },
35
35
  {
36
- url: `${h}/${e}/draft/components/${r}.js`,
36
+ url: `${p}/${e}/draft/components/${r}.js`,
37
37
  filename: "component.js"
38
38
  }
39
39
  ];
40
40
  for (const n of s)
41
41
  try {
42
42
  console.log(`Downloading ${n.filename} from ${n.url}...`);
43
- const a = await w(n.url, n.headers), t = p(o, n.filename);
44
- await d(t, a, "utf-8"), console.log(`✓ Saved ${n.filename} to ${t}`);
45
- } catch (a) {
46
- throw console.error(`✗ Failed to download ${n.filename} at :`, a), a;
43
+ const i = await w(n.url, n.headers), t = f(o, n.filename);
44
+ await c(t, i, "utf-8"), console.log(`✓ Saved ${n.filename} to ${t}`);
45
+ } catch (i) {
46
+ throw console.error(`✗ Failed to download ${n.filename} at :`, i), i;
47
47
  }
48
48
  console.log(`
49
49
  ✓ All files downloaded successfully!`);
50
50
  }
51
- function l() {
52
- console.log(`
53
- Usage: download-bravo.ts <appId> <pageId> <targetPath>
54
-
55
- Arguments:
56
- appId The Encore app ID
57
- pageId The Encore page ID
58
- targetPath Path where files should be saved
59
-
60
- Environment variables:
61
- APPS_SERVICE_URL Base URL for the apps service
62
-
63
- Example:
64
- download-bravo.ts my-app-id my-page-id ./bravo-files
65
- APPS_SERVICE_URL=https://api.example.com download-bravo.ts my-app-id my-page-id ./bravo-files
66
- `);
67
- }
68
- async function R(e) {
69
- (e.length < 3 || e.includes("--help") || e.includes("-h")) && (l(), process.exit(e.includes("--help") || e.includes("-h") ? 0 : 1));
70
- const [r, o, s] = e;
71
- (!r || !o || !s) && (console.error("Error: Missing required arguments"), l(), process.exit(1));
51
+ async function y(e, r, o) {
52
+ (!e || !r || !o) && (console.error(
53
+ "Error: Missing required arguments. Usage: download <appId> <pageId> <targetPath>"
54
+ ), process.exit(1));
72
55
  try {
73
- await $({ appId: r, pageId: o, targetPath: s });
74
- } catch (n) {
56
+ await E({ appId: e, pageId: r, targetPath: o });
57
+ } catch (s) {
75
58
  console.error(`
76
- Error:`, n instanceof Error ? n.message : n), process.exit(1);
59
+ Error:`, s instanceof Error ? s.message : s), process.exit(1);
77
60
  }
78
61
  }
79
62
  export {
80
- R as runDownload
63
+ y as runDownload
81
64
  };
82
65
  //# sourceMappingURL=download.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"download.js","sources":["../../../src/cli/commands/download.ts"],"sourcesContent":["import { writeFile, mkdir } from \"fs/promises\";\nimport { join } from \"path\";\nimport { existsSync } from \"fs\";\nimport dotenv from \"dotenv\";\nimport {\n CONST_APPS_SERVICE_URL,\n CONST_COMPONENTS_CDN_URL,\n} from \"../../../constants\";\n\ndotenv.config();\n\n// Default apps service URL (can be overridden with APPS_SERVICE_URL env var)\nconst APPS_SERVICE_URL =\n process.env.VITE_APPS_SERVICE_URL || CONST_APPS_SERVICE_URL;\nconst COMPONENTS_CDN_URL = CONST_COMPONENTS_CDN_URL;\n\ninterface DownloadOptions {\n appId: string;\n pageId: string;\n targetPath: string;\n}\n\nasync function downloadFile(\n url: string,\n headers?: Record<string, string>\n): Promise<string> {\n const response = await fetch(url, {\n headers: headers || {},\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to download ${url}: ${response.status} ${response.statusText}`\n );\n }\n\n return await response.text();\n}\n\nasync function downloadEncoreFiles({\n appId,\n pageId,\n targetPath,\n}: DownloadOptions) {\n console.log(`Downloading Encore files for app: ${appId}, page: ${pageId}`);\n console.log(`Target path: ${targetPath}`);\n\n // Ensure target directory exists\n if (!existsSync(targetPath)) {\n await mkdir(targetPath, { recursive: true });\n console.log(`Created directory: ${targetPath}`);\n }\n\n const files: Array<{\n url: string;\n filename: string;\n headers?: Record<string, string>;\n }> = [\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}`,\n filename: \"app.json\",\n headers: { \"x-app-clientrendered\": \"true\" },\n },\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}/node/${pageId}`,\n filename: \"page.json\",\n headers: { \"x-app-clientrendered\": \"true\" },\n },\n {\n url: `${COMPONENTS_CDN_URL}/${appId}/draft/components/${pageId}.js`,\n filename: \"component.js\",\n },\n ];\n\n for (const file of files) {\n try {\n console.log(`Downloading ${file.filename} from ${file.url}...`);\n const content = await downloadFile(file.url, file.headers);\n const filePath = join(targetPath, file.filename);\n await writeFile(filePath, content, \"utf-8\");\n console.log(`✓ Saved ${file.filename} to ${filePath}`);\n } catch (error) {\n console.error(`✗ Failed to download ${file.filename} at :`, error);\n throw error;\n }\n }\n\n console.log(\"\\n✓ All files downloaded successfully!\");\n}\n\nfunction printUsage() {\n console.log(`\nUsage: download-bravo.ts <appId> <pageId> <targetPath>\n\nArguments:\n appId The Encore app ID\n pageId The Encore page ID\n targetPath Path where files should be saved\n\nEnvironment variables:\n APPS_SERVICE_URL Base URL for the apps service\n\nExample:\n download-bravo.ts my-app-id my-page-id ./bravo-files\n APPS_SERVICE_URL=https://api.example.com download-bravo.ts my-app-id my-page-id ./bravo-files\n`);\n}\n\nexport async function runDownload(args: string[]) {\n if (args.length < 3 || args.includes(\"--help\") || args.includes(\"-h\")) {\n printUsage();\n process.exit(args.includes(\"--help\") || args.includes(\"-h\") ? 0 : 1);\n }\n\n const [appId, pageId, targetPath] = args;\n\n if (!appId || !pageId || !targetPath) {\n console.error(\"Error: Missing required arguments\");\n printUsage();\n process.exit(1);\n }\n\n try {\n await downloadEncoreFiles({ appId, pageId, targetPath });\n } catch (error) {\n console.error(\"\\nError:\", error instanceof Error ? error.message : error);\n process.exit(1);\n }\n}\n"],"names":["dotenv","APPS_SERVICE_URL","CONST_APPS_SERVICE_URL","COMPONENTS_CDN_URL","CONST_COMPONENTS_CDN_URL","downloadFile","url","headers","response","downloadEncoreFiles","appId","pageId","targetPath","existsSync","mkdir","files","file","content","filePath","join","writeFile","error","printUsage","runDownload","args"],"mappings":";;;;;AASAA,EAAO,OAAA;AAGP,MAAMC,IACJ,QAAQ,IAAI,yBAAyBC,GACjCC,IAAqBC;AAQ3B,eAAeC,EACbC,GACAC,GACiB;AACjB,QAAMC,IAAW,MAAM,MAAMF,GAAK;AAAA,IAChC,SAASC,KAAW,CAAA;AAAA,EAAC,CACtB;AAED,MAAI,CAACC,EAAS;AACZ,UAAM,IAAI;AAAA,MACR,sBAAsBF,CAAG,KAAKE,EAAS,MAAM,IAAIA,EAAS,UAAU;AAAA,IAAA;AAIxE,SAAO,MAAMA,EAAS,KAAA;AACxB;AAEA,eAAeC,EAAoB;AAAA,EACjC,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AACF,GAAoB;AAClB,UAAQ,IAAI,qCAAqCF,CAAK,WAAWC,CAAM,EAAE,GACzE,QAAQ,IAAI,gBAAgBC,CAAU,EAAE,GAGnCC,EAAWD,CAAU,MACxB,MAAME,EAAMF,GAAY,EAAE,WAAW,IAAM,GAC3C,QAAQ,IAAI,sBAAsBA,CAAU,EAAE;AAGhD,QAAMG,IAID;AAAA,IACH;AAAA,MACE,KAAK,GAAGd,CAAgB,iBAAiBS,CAAK;AAAA,MAC9C,UAAU;AAAA,MACV,SAAS,EAAE,wBAAwB,OAAA;AAAA,IAAO;AAAA,IAE5C;AAAA,MACE,KAAK,GAAGT,CAAgB,iBAAiBS,CAAK,SAASC,CAAM;AAAA,MAC7D,UAAU;AAAA,MACV,SAAS,EAAE,wBAAwB,OAAA;AAAA,IAAO;AAAA,IAE5C;AAAA,MACE,KAAK,GAAGR,CAAkB,IAAIO,CAAK,qBAAqBC,CAAM;AAAA,MAC9D,UAAU;AAAA,IAAA;AAAA,EACZ;AAGF,aAAWK,KAAQD;AACjB,QAAI;AACF,cAAQ,IAAI,eAAeC,EAAK,QAAQ,SAASA,EAAK,GAAG,KAAK;AAC9D,YAAMC,IAAU,MAAMZ,EAAaW,EAAK,KAAKA,EAAK,OAAO,GACnDE,IAAWC,EAAKP,GAAYI,EAAK,QAAQ;AAC/C,YAAMI,EAAUF,GAAUD,GAAS,OAAO,GAC1C,QAAQ,IAAI,WAAWD,EAAK,QAAQ,OAAOE,CAAQ,EAAE;AAAA,IACvD,SAASG,GAAO;AACd,oBAAQ,MAAM,wBAAwBL,EAAK,QAAQ,SAASK,CAAK,GAC3DA;AAAA,IACR;AAGF,UAAQ,IAAI;AAAA,qCAAwC;AACtD;AAEA,SAASC,IAAa;AACpB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAcb;AACD;AAEA,eAAsBC,EAAYC,GAAgB;AAChD,GAAIA,EAAK,SAAS,KAAKA,EAAK,SAAS,QAAQ,KAAKA,EAAK,SAAS,IAAI,OAClEF,EAAA,GACA,QAAQ,KAAKE,EAAK,SAAS,QAAQ,KAAKA,EAAK,SAAS,IAAI,IAAI,IAAI,CAAC;AAGrE,QAAM,CAACd,GAAOC,GAAQC,CAAU,IAAIY;AAEpC,GAAI,CAACd,KAAS,CAACC,KAAU,CAACC,OACxB,QAAQ,MAAM,mCAAmC,GACjDU,EAAA,GACA,QAAQ,KAAK,CAAC;AAGhB,MAAI;AACF,UAAMb,EAAoB,EAAE,OAAAC,GAAO,QAAAC,GAAQ,YAAAC,GAAY;AAAA,EACzD,SAASS,GAAO;AACd,YAAQ,MAAM;AAAA,SAAYA,aAAiB,QAAQA,EAAM,UAAUA,CAAK,GACxE,QAAQ,KAAK,CAAC;AAAA,EAChB;AACF;"}
1
+ {"version":3,"file":"download.js","sources":["../../../src/cli/commands/download.ts"],"sourcesContent":["import { writeFile, mkdir } from \"fs/promises\";\nimport { join } from \"path\";\nimport { existsSync } from \"fs\";\nimport dotenv from \"dotenv\";\nimport {\n CONST_APPS_SERVICE_URL,\n CONST_COMPONENTS_CDN_URL,\n} from \"../../../constants\";\n\ndotenv.config();\n\n// Default apps service URL (can be overridden with APPS_SERVICE_URL env var)\nconst APPS_SERVICE_URL =\n process.env.VITE_APPS_SERVICE_URL || CONST_APPS_SERVICE_URL;\nconst COMPONENTS_CDN_URL = CONST_COMPONENTS_CDN_URL;\n\ninterface DownloadOptions {\n appId: string;\n pageId: string;\n targetPath: string;\n}\n\nasync function downloadFile(\n url: string,\n headers?: Record<string, string>\n): Promise<string> {\n const response = await fetch(url, {\n headers: headers || {},\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to download ${url}: ${response.status} ${response.statusText}`\n );\n }\n\n return await response.text();\n}\n\nasync function downloadEncoreFiles({\n appId,\n pageId,\n targetPath,\n}: DownloadOptions) {\n console.log(`Downloading Encore files for app: ${appId}, page: ${pageId}`);\n console.log(`Target path: ${targetPath}`);\n\n // Ensure target directory exists\n if (!existsSync(targetPath)) {\n await mkdir(targetPath, { recursive: true });\n console.log(`Created directory: ${targetPath}`);\n }\n\n const files: Array<{\n url: string;\n filename: string;\n headers?: Record<string, string>;\n }> = [\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}`,\n filename: \"app.json\",\n headers: { \"x-app-clientrendered\": \"true\" },\n },\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}/node/${pageId}`,\n filename: \"page.json\",\n headers: { \"x-app-clientrendered\": \"true\" },\n },\n {\n url: `${COMPONENTS_CDN_URL}/${appId}/draft/components/${pageId}.js`,\n filename: \"component.js\",\n },\n ];\n\n for (const file of files) {\n try {\n console.log(`Downloading ${file.filename} from ${file.url}...`);\n const content = await downloadFile(file.url, file.headers);\n const filePath = join(targetPath, file.filename);\n await writeFile(filePath, content, \"utf-8\");\n console.log(`✓ Saved ${file.filename} to ${filePath}`);\n } catch (error) {\n console.error(`✗ Failed to download ${file.filename} at :`, error);\n throw error;\n }\n }\n\n console.log(\"\\n✓ All files downloaded successfully!\");\n}\n\nexport async function runDownload(\n appId: string,\n pageId: string,\n targetPath: string\n) {\n if (!appId || !pageId || !targetPath) {\n console.error(\n \"Error: Missing required arguments. Usage: download <appId> <pageId> <targetPath>\"\n );\n process.exit(1);\n }\n\n try {\n await downloadEncoreFiles({ appId, pageId, targetPath });\n } catch (error) {\n console.error(\"\\nError:\", error instanceof Error ? error.message : error);\n process.exit(1);\n }\n}\n"],"names":["dotenv","APPS_SERVICE_URL","CONST_APPS_SERVICE_URL","COMPONENTS_CDN_URL","CONST_COMPONENTS_CDN_URL","downloadFile","url","headers","response","downloadEncoreFiles","appId","pageId","targetPath","existsSync","mkdir","files","file","content","filePath","join","writeFile","error","runDownload"],"mappings":";;;;;AASAA,EAAO,OAAA;AAGP,MAAMC,IACJ,QAAQ,IAAI,yBAAyBC,GACjCC,IAAqBC;AAQ3B,eAAeC,EACbC,GACAC,GACiB;AACjB,QAAMC,IAAW,MAAM,MAAMF,GAAK;AAAA,IAChC,SAASC,KAAW,CAAA;AAAA,EAAC,CACtB;AAED,MAAI,CAACC,EAAS;AACZ,UAAM,IAAI;AAAA,MACR,sBAAsBF,CAAG,KAAKE,EAAS,MAAM,IAAIA,EAAS,UAAU;AAAA,IAAA;AAIxE,SAAO,MAAMA,EAAS,KAAA;AACxB;AAEA,eAAeC,EAAoB;AAAA,EACjC,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AACF,GAAoB;AAClB,UAAQ,IAAI,qCAAqCF,CAAK,WAAWC,CAAM,EAAE,GACzE,QAAQ,IAAI,gBAAgBC,CAAU,EAAE,GAGnCC,EAAWD,CAAU,MACxB,MAAME,EAAMF,GAAY,EAAE,WAAW,IAAM,GAC3C,QAAQ,IAAI,sBAAsBA,CAAU,EAAE;AAGhD,QAAMG,IAID;AAAA,IACH;AAAA,MACE,KAAK,GAAGd,CAAgB,iBAAiBS,CAAK;AAAA,MAC9C,UAAU;AAAA,MACV,SAAS,EAAE,wBAAwB,OAAA;AAAA,IAAO;AAAA,IAE5C;AAAA,MACE,KAAK,GAAGT,CAAgB,iBAAiBS,CAAK,SAASC,CAAM;AAAA,MAC7D,UAAU;AAAA,MACV,SAAS,EAAE,wBAAwB,OAAA;AAAA,IAAO;AAAA,IAE5C;AAAA,MACE,KAAK,GAAGR,CAAkB,IAAIO,CAAK,qBAAqBC,CAAM;AAAA,MAC9D,UAAU;AAAA,IAAA;AAAA,EACZ;AAGF,aAAWK,KAAQD;AACjB,QAAI;AACF,cAAQ,IAAI,eAAeC,EAAK,QAAQ,SAASA,EAAK,GAAG,KAAK;AAC9D,YAAMC,IAAU,MAAMZ,EAAaW,EAAK,KAAKA,EAAK,OAAO,GACnDE,IAAWC,EAAKP,GAAYI,EAAK,QAAQ;AAC/C,YAAMI,EAAUF,GAAUD,GAAS,OAAO,GAC1C,QAAQ,IAAI,WAAWD,EAAK,QAAQ,OAAOE,CAAQ,EAAE;AAAA,IACvD,SAASG,GAAO;AACd,oBAAQ,MAAM,wBAAwBL,EAAK,QAAQ,SAASK,CAAK,GAC3DA;AAAA,IACR;AAGF,UAAQ,IAAI;AAAA,qCAAwC;AACtD;AAEA,eAAsBC,EACpBZ,GACAC,GACAC,GACA;AACA,GAAI,CAACF,KAAS,CAACC,KAAU,CAACC,OACxB,QAAQ;AAAA,IACN;AAAA,EAAA,GAEF,QAAQ,KAAK,CAAC;AAGhB,MAAI;AACF,UAAMH,EAAoB,EAAE,OAAAC,GAAO,QAAAC,GAAQ,YAAAC,GAAY;AAAA,EACzD,SAASS,GAAO;AACd,YAAQ,MAAM;AAAA,SAAYA,aAAiB,QAAQA,EAAM,UAAUA,CAAK,GACxE,QAAQ,KAAK,CAAC;AAAA,EAChB;AACF;"}
@@ -1,17 +1,17 @@
1
- import { promises as k, existsSync as v } from "fs";
2
- import { join as i, dirname as W } from "path";
3
- import { m as Y } from "../../_virtual/main.js";
4
- import { CONST_APPS_SERVICE_URL as q, CONST_COMPONENTS_CDN_URL as z } from "../../packages/encore-lib/constants.js";
5
- import { findSlidersAndDataBindings as X, findStandaloneComponents as Z, findInputGroups as H, findForms as Q, qualifyFormInputs as ee, findStandaloneSelectInputs as te, findActionButtons as oe, sanitizePropName as A } from "../../codegen/parser.js";
6
- import { generateComponentCode as ne, generateReadme as ae } from "../../codegen/generator.js";
7
- const { writeFile: P, mkdir: G, readFile: R } = k;
8
- Y.config();
9
- const E = process.env.APPS_SERVICE_URL || process.env.VITE_APPS_SERVICE_URL || q;
10
- console.log(`Using APPS_SERVICE_URL: ${E}`);
11
- const se = z;
12
- async function U(o, s) {
1
+ import { promises as z, existsSync as P } from "fs";
2
+ import { join as c, dirname as H } from "path";
3
+ import { m as K } from "../../_virtual/main.js";
4
+ import { CONST_APPS_SERVICE_URL as Q, CONST_COMPONENTS_CDN_URL as X } from "../../packages/encore-lib/constants.js";
5
+ import { findSlidersAndDataBindings as Y, findStandaloneComponents as Z, findInputGroups as I, findForms as ee, qualifyFormInputs as te, findStandaloneSelectInputs as oe, findActionButtons as ne, sanitizePropName as _ } from "../../codegen/parser.js";
6
+ import { generateComponentCode as ae, generateReadme as se } from "../../codegen/generator.js";
7
+ const { writeFile: C, mkdir: L, readFile: N } = z;
8
+ K.config();
9
+ const S = process.env.APPS_SERVICE_URL || process.env.VITE_APPS_SERVICE_URL || Q;
10
+ console.log(`Using APPS_SERVICE_URL: ${S}`);
11
+ const re = X;
12
+ async function O(o, n) {
13
13
  const t = await fetch(o, {
14
- headers: s || {}
14
+ headers: n || {}
15
15
  });
16
16
  if (!t.ok)
17
17
  throw new Error(
@@ -19,255 +19,234 @@ async function U(o, s) {
19
19
  );
20
20
  return await t.text();
21
21
  }
22
- function re(o, s) {
23
- const t = A(o), p = A(s), u = t.charAt(0).toUpperCase() + t.slice(1), f = p.charAt(0).toUpperCase() + p.slice(1);
22
+ function ie(o, n) {
23
+ const t = _(o), i = _(n), a = t.charAt(0).toUpperCase() + t.slice(1), d = i.charAt(0).toUpperCase() + i.slice(1);
24
24
  return {
25
- directoryPath: i(u, f),
26
- componentName: f
25
+ directoryPath: c(a, d),
26
+ componentName: d
27
27
  };
28
28
  }
29
- async function ie(o) {
30
- const s = `${E}/devices/apps/${o}`;
31
- console.log(`Fetching app data from ${s}...`);
29
+ async function ce(o) {
30
+ const n = `${S}/devices/apps/${o}`;
31
+ console.log(`Fetching app data from ${n}...`);
32
32
  try {
33
- const t = await U(s), p = JSON.parse(t);
34
- return { pages: p?.app?.data?.pages || [], appData: p };
33
+ const t = await O(n), i = JSON.parse(t);
34
+ return { pages: i?.app?.data?.pages || [], appData: i };
35
35
  } catch (t) {
36
36
  throw console.error("Failed to fetch app data:", t), t;
37
37
  }
38
38
  }
39
- async function b({
39
+ async function G({
40
40
  appId: o,
41
- pageId: s,
41
+ pageId: n,
42
42
  outputPath: t,
43
- cachedAppData: p,
44
- isProduction: u,
45
- usedNames: f
43
+ cachedAppData: i,
44
+ mode: a = "dynamic",
45
+ usedNames: d
46
46
  }) {
47
- console.log(`Generating wrapper for app: ${o}, page: ${s}`);
48
- let n = t, h = !1;
49
- const l = t.split(".").pop()?.toLowerCase();
50
- if (l !== "tsx" && l !== "ts" && l !== "jsx" && l !== "js") {
47
+ console.log(
48
+ `Generating wrapper for app: ${o}, page: ${n}, mode: ${a}`
49
+ );
50
+ let l = t, m = !1;
51
+ const f = t.split(".").pop()?.toLowerCase();
52
+ if (f !== "tsx" && f !== "ts" && f !== "jsx" && f !== "js") {
51
53
  const { stat: e } = await import("fs/promises");
52
54
  try {
53
- (await e(t)).isDirectory() && (h = !0);
55
+ (await e(t)).isDirectory() && (m = !0);
54
56
  } catch {
55
- (!l || t.endsWith("/")) && (h = !0);
57
+ (!f || t.endsWith("/")) && (m = !0);
56
58
  }
57
59
  }
58
- h && console.log(
60
+ m && console.log(
59
61
  "Output path is a directory, will generate filename from app/page names"
60
62
  ), console.log(`Output path: ${t}`);
61
- const d = i(process.cwd(), ".temp-bravo", o, s);
62
- v(d) || await G(d, { recursive: !0 });
63
- const _ = [
63
+ const g = c(process.cwd(), ".temp-bravo", o, n);
64
+ P(g) || await L(g, { recursive: !0 });
65
+ const T = [
64
66
  {
65
- url: `${E}/devices/apps/${o}`,
67
+ url: `${S}/devices/apps/${o}`,
66
68
  filename: "app.json",
67
69
  skipIfCached: !0
68
70
  },
69
71
  {
70
- url: `${E}/devices/apps/${o}/node/${s}`,
72
+ url: `${S}/devices/apps/${o}/node/${n}`,
71
73
  filename: "page.json"
72
74
  },
73
75
  {
74
- url: `${se}/${o}/draft/components/${s}.js`,
76
+ url: `${re}/${o}/draft/components/${n}.js`,
75
77
  filename: "component.js"
76
78
  }
77
79
  ];
78
- for (const e of _) {
79
- if (e.skipIfCached && p) {
80
+ for (const e of T) {
81
+ if (e.skipIfCached && i) {
80
82
  console.log(`Using cached ${e.filename} (skipping download)`);
81
- const r = i(d, e.filename);
82
- await P(
83
+ const r = c(g, e.filename);
84
+ await C(
83
85
  r,
84
- JSON.stringify(p, null, 2),
86
+ JSON.stringify(i, null, 2),
85
87
  "utf-8"
86
88
  ), console.log(`✓ Saved ${e.filename} from cache`);
87
89
  continue;
88
90
  }
89
91
  try {
90
92
  console.log(`Downloading ${e.filename} from ${e.url}...`);
91
- const r = await U(e.url, e.headers), c = i(d, e.filename);
92
- await P(c, r, "utf-8"), console.log(`✓ Saved ${e.filename}`);
93
+ const r = await O(e.url, e.headers), p = c(g, e.filename);
94
+ await C(p, r, "utf-8"), console.log(`✓ Saved ${e.filename}`);
93
95
  } catch (r) {
94
96
  throw console.error(`✗ Failed to download ${e.filename}:`, r), r;
95
97
  }
96
98
  }
97
- const w = i(d, "page.json"), C = await R(w, "utf-8"), x = JSON.parse(C);
98
- let a = x.data || x;
99
- if (!a.body && !a.data?.body) {
99
+ const V = c(g, "page.json"), k = await N(V, "utf-8"), R = JSON.parse(k);
100
+ let s = R.data || R;
101
+ if (!s.body && !s.data?.body) {
100
102
  console.log("Page data doesn't have body, trying app.json...");
101
103
  try {
102
- let e = p;
104
+ let e = i;
103
105
  if (!e) {
104
- const g = `${E}/devices/apps/${o}`, y = await U(g);
106
+ const h = `${S}/devices/apps/${o}`, y = await O(h);
105
107
  e = JSON.parse(y);
106
108
  }
107
- const c = (e?.app?.data?.pages || []).find((g) => g.id === s);
108
- c && (a = c, console.log("✓ Found page data in app.json"));
109
+ const p = (e?.app?.data?.pages || []).find((h) => h.id === n);
110
+ p && (s = p, console.log("✓ Found page data in app.json"));
109
111
  } catch (e) {
110
112
  console.warn("Could not load app.json:", e);
111
113
  }
112
114
  }
113
- const O = X(a), j = Z(a), D = H(a), $ = Q(a);
114
- ee($);
115
- const F = te(a, $), J = oe(a);
116
- let S = "Encore App", N = "Page";
115
+ const j = Y(s), x = Z(s), v = I(s), $ = ee(s);
116
+ te($);
117
+ const J = oe(s, $), U = ne(s);
118
+ let w = "Encore App", E = "Page";
117
119
  try {
118
- let e = p;
120
+ let e = i;
119
121
  if (!e) {
120
- const r = i(d, "app.json");
121
- if (v(r)) {
122
- const c = await R(r, "utf-8");
123
- e = JSON.parse(c);
122
+ const r = c(g, "app.json");
123
+ if (P(r)) {
124
+ const p = await N(r, "utf-8");
125
+ e = JSON.parse(p);
124
126
  }
125
127
  }
126
- e && (S = e?.app?.store?.name || S);
128
+ e && (w = e?.app?.store?.name || w);
127
129
  } catch {
128
130
  }
129
- N = a.name || a.id || N;
130
- let { directoryPath: L, componentName: m } = re(S, N);
131
- if (f) {
132
- let e = m, r = 2;
133
- for (; f.has(e); )
134
- e = `${m}${r}`, r++;
135
- if (e !== m) {
136
- m = e;
137
- const c = A(S), g = c.charAt(0).toUpperCase() + c.slice(1);
138
- L = i(g, m);
131
+ E = s.name || s.id || E;
132
+ let { directoryPath: D, componentName: u } = ie(w, E);
133
+ if (d) {
134
+ let e = u, r = 2;
135
+ for (; d.has(e); )
136
+ e = `${u}${r}`, r++;
137
+ if (e !== u) {
138
+ u = e;
139
+ const p = _(w), h = p.charAt(0).toUpperCase() + p.slice(1);
140
+ D = c(h, u);
139
141
  }
140
- f.add(m);
142
+ d.add(u);
141
143
  }
142
- const T = L;
143
- if (h)
144
- n = i(t, T);
144
+ const F = D;
145
+ if (m)
146
+ l = c(t, F);
145
147
  else {
146
- const e = W(n);
147
- n = i(e, T);
148
+ const e = H(l);
149
+ l = c(e, F);
148
150
  }
149
- const K = ne(
151
+ const M = a === "production" || a === "optimistic", b = ae(
150
152
  o,
151
- s,
152
- m,
153
- O,
153
+ n,
154
+ u,
154
155
  j,
155
- D,
156
+ x,
157
+ v,
156
158
  $,
157
- F,
158
159
  J,
159
- !!u,
160
+ U,
161
+ a,
160
162
  {
161
- width: a.style?.width,
162
- height: a.style?.height,
163
- aspectRatio: a.style?.width && a.style?.height ? a.style.width / a.style.height : void 0
163
+ width: s.style?.width,
164
+ height: s.style?.height,
165
+ aspectRatio: s.style?.width && s.style?.height ? s.style.width / s.style.height : void 0
164
166
  }
165
- ), V = ae(
167
+ ), B = se(
166
168
  o,
167
- s,
168
- S,
169
- N,
170
- m,
171
- O,
169
+ n,
170
+ w,
171
+ E,
172
+ u,
172
173
  j,
173
- D,
174
+ x,
175
+ v,
174
176
  $,
175
- F,
176
- J
177
+ J,
178
+ U
177
179
  );
178
- if (v(n) || await G(n, { recursive: !0 }), u) {
179
- const e = i(d, "component.js");
180
+ if (P(l) || await L(l, { recursive: !0 }), M) {
181
+ const e = c(g, "component.js");
180
182
  let r = "";
181
183
  try {
182
- r = await R(e, "utf-8");
184
+ r = await N(e, "utf-8");
183
185
  } catch {
184
186
  }
185
- let c = p;
186
- if (!c)
187
+ let p = i;
188
+ if (!p)
187
189
  try {
188
- const y = i(d, "app.json"), M = await R(y, "utf-8");
189
- c = JSON.parse(M);
190
+ const y = c(g, "app.json"), W = await N(y, "utf-8");
191
+ p = JSON.parse(W);
190
192
  } catch {
191
193
  }
192
- const g = {
193
- app: c,
194
- page: a,
194
+ const h = {
195
+ app: p,
196
+ page: s,
195
197
  componentCode: r
196
198
  };
197
- await P(
198
- i(n, "data.json"),
199
- JSON.stringify(g, null, 2),
199
+ await C(
200
+ c(l, "data.json"),
201
+ JSON.stringify(h, null, 2),
200
202
  "utf-8"
201
203
  );
202
204
  }
203
- const I = i(n, "index.tsx"), B = i(n, "README.md");
204
- await P(I, K, "utf-8"), await P(B, V, "utf-8"), console.log(`✓ Generated wrapper component at: ${I}`);
205
+ const A = c(l, "index.tsx"), q = c(l, "README.md");
206
+ await C(A, b, "utf-8"), await C(q, B, "utf-8"), console.log(`✓ Generated wrapper component at: ${A}`);
205
207
  }
206
- function pe() {
207
- console.log(`
208
- Usage: generate-wrapper.ts <appId> [pageId] <outputPath>
209
-
210
- Arguments:
211
- appId The Encore app ID
212
- pageId The Encore page ID (optional - if omitted, generates wrappers for ALL pages)
213
- outputPath Path where the generated TSX file(s) should be saved
214
- --production Generate for production (bundles data)
215
- --preseed Alias for --production (bundles data)
216
-
217
- Environment variables:
218
- APPS_SERVICE_URL Base URL for the apps service
219
-
220
- Example:
221
- generate-wrapper.ts 01KA964B1T6KCKSKCNMYSTKRKZ 01KA964B2F42MN4WGCYDTG1Y70 ./src/components/MyEncoreApp.tsx
222
- `);
223
- }
224
- async function ge(o) {
225
- const s = o.includes("--production") || o.includes("--preseed"), t = o.filter(
226
- (n) => n !== "--production" && n !== "--preseed"
227
- );
228
- if ((t.length < 2 || t.includes("--help") || t.includes("-h")) && (pe(), process.exit(
229
- t.includes("--help") || t.includes("-h") ? 0 : 1
230
- )), t.length === 2) {
231
- const [n, h] = t;
208
+ async function ue(o, n, t, i) {
209
+ if ((!o || !n && !t) && (console.error(
210
+ "Error: Missing required arguments. Usage: generate <appId> [pageId] <outputPath>"
211
+ ), process.exit(1)), t || (console.error("Error: Missing output path."), process.exit(1)), !n) {
232
212
  try {
233
- const { pages: l, appData: d } = await ie(n);
234
- if (l.length === 0) {
213
+ const { pages: a, appData: d } = await ce(o);
214
+ if (a.length === 0) {
235
215
  console.warn("No pages found for this app.");
236
216
  return;
237
217
  }
238
- const _ = /* @__PURE__ */ new Set();
239
- for (const w of l)
240
- if (w.id)
218
+ const l = /* @__PURE__ */ new Set();
219
+ for (const m of a)
220
+ if (m.id)
241
221
  try {
242
- await b({
243
- appId: n,
244
- pageId: w.id,
245
- outputPath: h,
222
+ await G({
223
+ appId: o,
224
+ pageId: m.id,
225
+ outputPath: t,
246
226
  cachedAppData: d,
247
- isProduction: s,
248
- usedNames: _
227
+ mode: i,
228
+ usedNames: l
249
229
  });
250
- } catch (C) {
230
+ } catch (f) {
251
231
  console.warn(
252
- `Error with page ${w.id}:`,
253
- C instanceof Error ? C.message : C
232
+ `Error with page ${m.id}:`,
233
+ f instanceof Error ? f.message : f
254
234
  );
255
235
  }
256
- } catch (l) {
236
+ } catch (a) {
257
237
  console.error(`
258
- Error:`, l instanceof Error ? l.message : l), process.exit(1);
238
+ Error:`, a instanceof Error ? a.message : a), process.exit(1);
259
239
  }
260
240
  return;
261
241
  }
262
- const [p, u, f] = t;
263
242
  try {
264
- await b({ appId: p, pageId: u, outputPath: f, isProduction: s });
265
- } catch (n) {
243
+ await G({ appId: o, pageId: n, outputPath: t, mode: i });
244
+ } catch (a) {
266
245
  console.error(`
267
- Error:`, n instanceof Error ? n.message : n), process.exit(1);
246
+ Error:`, a instanceof Error ? a.message : a), process.exit(1);
268
247
  }
269
248
  }
270
249
  export {
271
- ge as runGenerate
250
+ ue as runGenerate
272
251
  };
273
252
  //# sourceMappingURL=generate.js.map