@bravostudioai/react 0.1.32 → 0.1.35
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/README.md +84 -35
- package/dist/cli/commands/download.js +22 -39
- package/dist/cli/commands/download.js.map +1 -1
- package/dist/cli/commands/generate.js +140 -161
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli.js +21 -24
- package/dist/cli.js.map +1 -1
- package/dist/codegen/generator.js +126 -125
- package/dist/codegen/generator.js.map +1 -1
- package/dist/components/EncoreApp.js +157 -133
- package/dist/components/EncoreApp.js.map +1 -1
- package/dist/src/cli/commands/download.d.ts +1 -1
- package/dist/src/cli/commands/download.d.ts.map +1 -1
- package/dist/src/cli/commands/generate.d.ts +1 -1
- package/dist/src/cli/commands/generate.d.ts.map +1 -1
- package/dist/src/codegen/generator.d.ts +1 -1
- package/dist/src/codegen/generator.d.ts.map +1 -1
- package/dist/src/components/EncoreApp.d.ts +3 -1
- package/dist/src/components/EncoreApp.d.ts.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -1
- package/src/cli/commands/download.ts +8 -28
- package/src/cli/commands/generate.ts +44 -45
- package/src/cli/index.ts +49 -32
- package/src/codegen/generator.ts +6 -3
- package/src/components/EncoreApp.tsx +111 -21
- package/src/version.ts +1 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { promises as
|
|
2
|
-
import { join as
|
|
3
|
-
import { m as
|
|
4
|
-
import { CONST_APPS_SERVICE_URL as
|
|
5
|
-
import { findSlidersAndDataBindings as
|
|
6
|
-
import { generateComponentCode as
|
|
7
|
-
const { writeFile:
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
console.log(`Using APPS_SERVICE_URL: ${
|
|
11
|
-
const
|
|
12
|
-
async function
|
|
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:
|
|
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
|
|
23
|
-
const t =
|
|
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:
|
|
26
|
-
componentName:
|
|
25
|
+
directoryPath: c(a, d),
|
|
26
|
+
componentName: d
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
async function
|
|
30
|
-
const
|
|
31
|
-
console.log(`Fetching app data from ${
|
|
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
|
|
34
|
-
return { pages:
|
|
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
|
|
39
|
+
async function G({
|
|
40
40
|
appId: o,
|
|
41
|
-
pageId:
|
|
41
|
+
pageId: n,
|
|
42
42
|
outputPath: t,
|
|
43
|
-
cachedAppData:
|
|
44
|
-
|
|
45
|
-
usedNames:
|
|
43
|
+
cachedAppData: i,
|
|
44
|
+
mode: a = "dynamic",
|
|
45
|
+
usedNames: d
|
|
46
46
|
}) {
|
|
47
|
-
console.log(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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() && (
|
|
55
|
+
(await e(t)).isDirectory() && (m = !0);
|
|
54
56
|
} catch {
|
|
55
|
-
(!
|
|
57
|
+
(!f || t.endsWith("/")) && (m = !0);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
|
|
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
|
|
62
|
-
|
|
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: `${
|
|
67
|
+
url: `${S}/devices/apps/${o}`,
|
|
66
68
|
filename: "app.json",
|
|
67
69
|
skipIfCached: !0
|
|
68
70
|
},
|
|
69
71
|
{
|
|
70
|
-
url: `${
|
|
72
|
+
url: `${S}/devices/apps/${o}/node/${n}`,
|
|
71
73
|
filename: "page.json"
|
|
72
74
|
},
|
|
73
75
|
{
|
|
74
|
-
url: `${
|
|
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 &&
|
|
80
|
+
for (const e of T) {
|
|
81
|
+
if (e.skipIfCached && i) {
|
|
80
82
|
console.log(`Using cached ${e.filename} (skipping download)`);
|
|
81
|
-
const r =
|
|
82
|
-
await
|
|
83
|
+
const r = c(g, e.filename);
|
|
84
|
+
await C(
|
|
83
85
|
r,
|
|
84
|
-
JSON.stringify(
|
|
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
|
|
92
|
-
await
|
|
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
|
|
98
|
-
let
|
|
99
|
-
if (!
|
|
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 =
|
|
104
|
+
let e = i;
|
|
103
105
|
if (!e) {
|
|
104
|
-
const
|
|
106
|
+
const h = `${S}/devices/apps/${o}`, y = await O(h);
|
|
105
107
|
e = JSON.parse(y);
|
|
106
108
|
}
|
|
107
|
-
const
|
|
108
|
-
|
|
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
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
let
|
|
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 =
|
|
120
|
+
let e = i;
|
|
119
121
|
if (!e) {
|
|
120
|
-
const r =
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
e = JSON.parse(
|
|
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 && (
|
|
128
|
+
e && (w = e?.app?.store?.name || w);
|
|
127
129
|
} catch {
|
|
128
130
|
}
|
|
129
|
-
|
|
130
|
-
let { directoryPath:
|
|
131
|
-
if (
|
|
132
|
-
let e =
|
|
133
|
-
for (;
|
|
134
|
-
e = `${
|
|
135
|
-
if (e !==
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
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
|
-
|
|
142
|
+
d.add(u);
|
|
141
143
|
}
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
|
|
144
|
+
const F = D;
|
|
145
|
+
if (m)
|
|
146
|
+
l = c(t, F);
|
|
145
147
|
else {
|
|
146
|
-
const e =
|
|
147
|
-
|
|
148
|
+
const e = H(l);
|
|
149
|
+
l = c(e, F);
|
|
148
150
|
}
|
|
149
|
-
const
|
|
151
|
+
const M = a === "production" || a === "optimistic", b = ae(
|
|
150
152
|
o,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
O,
|
|
153
|
+
n,
|
|
154
|
+
u,
|
|
154
155
|
j,
|
|
155
|
-
|
|
156
|
+
x,
|
|
157
|
+
v,
|
|
156
158
|
$,
|
|
157
|
-
F,
|
|
158
159
|
J,
|
|
159
|
-
|
|
160
|
+
U,
|
|
161
|
+
a,
|
|
160
162
|
{
|
|
161
|
-
width:
|
|
162
|
-
height:
|
|
163
|
-
aspectRatio:
|
|
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
|
-
),
|
|
167
|
+
), B = se(
|
|
166
168
|
o,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
O,
|
|
169
|
+
n,
|
|
170
|
+
w,
|
|
171
|
+
E,
|
|
172
|
+
u,
|
|
172
173
|
j,
|
|
173
|
-
|
|
174
|
+
x,
|
|
175
|
+
v,
|
|
174
176
|
$,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
J,
|
|
178
|
+
U
|
|
177
179
|
);
|
|
178
|
-
if (
|
|
179
|
-
const e =
|
|
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
|
|
184
|
+
r = await N(e, "utf-8");
|
|
183
185
|
} catch {
|
|
184
186
|
}
|
|
185
|
-
let
|
|
186
|
-
if (!
|
|
187
|
+
let p = i;
|
|
188
|
+
if (!p)
|
|
187
189
|
try {
|
|
188
|
-
const y =
|
|
189
|
-
|
|
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
|
|
193
|
-
app:
|
|
194
|
-
page:
|
|
194
|
+
const h = {
|
|
195
|
+
app: p,
|
|
196
|
+
page: s,
|
|
195
197
|
componentCode: r
|
|
196
198
|
};
|
|
197
|
-
await
|
|
198
|
-
|
|
199
|
-
JSON.stringify(
|
|
199
|
+
await C(
|
|
200
|
+
c(l, "data.json"),
|
|
201
|
+
JSON.stringify(h, null, 2),
|
|
200
202
|
"utf-8"
|
|
201
203
|
);
|
|
202
204
|
}
|
|
203
|
-
const
|
|
204
|
-
await
|
|
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
|
|
207
|
-
console.
|
|
208
|
-
Usage: generate
|
|
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:
|
|
234
|
-
if (
|
|
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
|
|
239
|
-
for (const
|
|
240
|
-
if (
|
|
218
|
+
const l = /* @__PURE__ */ new Set();
|
|
219
|
+
for (const m of a)
|
|
220
|
+
if (m.id)
|
|
241
221
|
try {
|
|
242
|
-
await
|
|
243
|
-
appId:
|
|
244
|
-
pageId:
|
|
245
|
-
outputPath:
|
|
222
|
+
await G({
|
|
223
|
+
appId: o,
|
|
224
|
+
pageId: m.id,
|
|
225
|
+
outputPath: t,
|
|
246
226
|
cachedAppData: d,
|
|
247
|
-
|
|
248
|
-
usedNames:
|
|
227
|
+
mode: i,
|
|
228
|
+
usedNames: l
|
|
249
229
|
});
|
|
250
|
-
} catch (
|
|
230
|
+
} catch (f) {
|
|
251
231
|
console.warn(
|
|
252
|
-
`Error with page ${
|
|
253
|
-
|
|
232
|
+
`Error with page ${m.id}:`,
|
|
233
|
+
f instanceof Error ? f.message : f
|
|
254
234
|
);
|
|
255
235
|
}
|
|
256
|
-
} catch (
|
|
236
|
+
} catch (a) {
|
|
257
237
|
console.error(`
|
|
258
|
-
Error:`,
|
|
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
|
|
265
|
-
} catch (
|
|
243
|
+
await G({ appId: o, pageId: n, outputPath: t, mode: i });
|
|
244
|
+
} catch (a) {
|
|
266
245
|
console.error(`
|
|
267
|
-
Error:`,
|
|
246
|
+
Error:`, a instanceof Error ? a.message : a), process.exit(1);
|
|
268
247
|
}
|
|
269
248
|
}
|
|
270
249
|
export {
|
|
271
|
-
|
|
250
|
+
ue as runGenerate
|
|
272
251
|
};
|
|
273
252
|
//# sourceMappingURL=generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sources":["../../../src/cli/commands/generate.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\nimport { join, dirname } from \"path\";\nimport { existsSync } from \"fs\";\nimport * as dotenv from \"dotenv\";\nimport {\n CONST_APPS_SERVICE_URL,\n CONST_COMPONENTS_CDN_URL,\n} from \"../../../constants\";\nimport {\n findSlidersAndDataBindings,\n findStandaloneComponents,\n findInputGroups,\n findForms,\n findStandaloneSelectInputs,\n findActionButtons,\n qualifyFormInputs,\n generateComponentCode,\n generateReadme,\n sanitizePropName,\n} from \"../../codegen\";\n\nconst { writeFile, mkdir, readFile } = fs;\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.APPS_SERVICE_URL ||\n process.env.VITE_APPS_SERVICE_URL ||\n CONST_APPS_SERVICE_URL;\nconsole.log(`Using APPS_SERVICE_URL: ${APPS_SERVICE_URL}`);\nconst COMPONENTS_CDN_URL = CONST_COMPONENTS_CDN_URL;\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\nfunction generateNames(\n appName: string,\n pageName: string\n): { directoryPath: string; componentName: string } {\n const appCamel = sanitizePropName(appName);\n const pageCamel = sanitizePropName(pageName);\n // Capitalize first letter for PascalCase\n const appPascal = appCamel.charAt(0).toUpperCase() + appCamel.slice(1);\n const pagePascal = pageCamel.charAt(0).toUpperCase() + pageCamel.slice(1);\n return {\n directoryPath: join(appPascal, pagePascal),\n componentName: pagePascal,\n };\n}\n\nasync function getAppPages(\n appId: string\n): Promise<{ pages: any[]; appData: any }> {\n const url = `${APPS_SERVICE_URL}/devices/apps/${appId}`;\n console.log(`Fetching app data from ${url}...`);\n try {\n const content = await downloadFile(url);\n const appData = JSON.parse(content);\n const pages = appData?.app?.data?.pages || [];\n return { pages, appData };\n } catch (error) {\n console.error(\"Failed to fetch app data:\", error);\n throw error;\n }\n}\n\nasync function generateWrapper({\n appId,\n pageId,\n outputPath,\n cachedAppData,\n isProduction,\n usedNames,\n}: {\n appId: string;\n pageId: string;\n outputPath: string;\n cachedAppData?: any;\n isProduction?: boolean;\n usedNames?: Set<string>;\n}) {\n console.log(`Generating wrapper for app: ${appId}, page: ${pageId}`);\n\n // Determine final output path - we'll update it after we get app/page names\n let finalOutputPath = outputPath;\n let needsFilenameGeneration = false;\n const pathExt = outputPath.split(\".\").pop()?.toLowerCase();\n if (\n pathExt !== \"tsx\" &&\n pathExt !== \"ts\" &&\n pathExt !== \"jsx\" &&\n pathExt !== \"js\"\n ) {\n // Path doesn't have a file extension, treat as directory\n const { stat } = await import(\"fs/promises\");\n try {\n const pathStats = await stat(outputPath);\n if (pathStats.isDirectory()) {\n needsFilenameGeneration = true;\n }\n } catch {\n // Path doesn't exist, check if it looks like a directory (no extension)\n if (!pathExt || outputPath.endsWith(\"/\")) {\n needsFilenameGeneration = true;\n }\n }\n }\n\n if (needsFilenameGeneration) {\n console.log(\n `Output path is a directory, will generate filename from app/page names`\n );\n }\n\n console.log(`Output path: ${outputPath}`);\n\n // Create temp directory for downloaded files\n const tempDir = join(process.cwd(), \".temp-bravo\", appId, pageId);\n if (!existsSync(tempDir)) {\n await mkdir(tempDir, { recursive: true });\n }\n\n // Download files (skip app.json if we have cached data)\n const files: Array<{\n url: string;\n filename: string;\n headers?: Record<string, string>;\n skipIfCached?: boolean;\n }> = [\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}`,\n filename: \"app.json\",\n skipIfCached: true,\n },\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}/node/${pageId}`,\n filename: \"page.json\",\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 // Skip app.json if we have cached data\n if (file.skipIfCached && cachedAppData) {\n console.log(`Using cached ${file.filename} (skipping download)`);\n const filePath = join(tempDir, file.filename);\n await writeFile(\n filePath,\n JSON.stringify(cachedAppData, null, 2),\n \"utf-8\"\n );\n console.log(`✓ Saved ${file.filename} from cache`);\n continue;\n }\n\n try {\n console.log(`Downloading ${file.filename} from ${file.url}...`);\n const content = await downloadFile(file.url, file.headers);\n const filePath = join(tempDir, file.filename);\n await writeFile(filePath, content, \"utf-8\");\n console.log(`✓ Saved ${file.filename}`);\n } catch (error) {\n console.error(`✗ Failed to download ${file.filename}:`, error);\n throw error;\n }\n }\n\n // Read and parse page.json\n const pageJsonPath = join(tempDir, \"page.json\");\n const pageJsonContent = await readFile(pageJsonPath, \"utf-8\");\n const pageResponse = JSON.parse(pageJsonContent);\n\n // Extract page data - API response has it under 'data' field\n let pageData = pageResponse.data || pageResponse;\n\n // If pageData doesn't have body, try using cached app.json or downloading as fallback\n if (!pageData.body && !(pageData as any).data?.body) {\n console.log(\"Page data doesn't have body, trying app.json...\");\n try {\n let appData = cachedAppData;\n\n // If we don't have cached data, download it\n if (!appData) {\n const appUrl = `${APPS_SERVICE_URL}/devices/apps/${appId}`;\n const appContent = await downloadFile(appUrl);\n appData = JSON.parse(appContent);\n }\n\n // Find the page in app.data.pages\n const pages = appData?.app?.data?.pages || [];\n const page = pages.find((p: any) => p.id === pageId);\n if (page) {\n pageData = page;\n console.log(\"✓ Found page data in app.json\");\n }\n } catch (error) {\n console.warn(\"Could not load app.json:\", error);\n }\n }\n\n // Find components using extracted logic\n const sliders = findSlidersAndDataBindings(pageData);\n const standaloneComponents = findStandaloneComponents(pageData);\n const inputGroups = findInputGroups(pageData);\n const forms = findForms(pageData);\n\n // Qualify form input prop names\n qualifyFormInputs(forms);\n\n const selectInputs = findStandaloneSelectInputs(pageData, forms);\n const actionButtons = findActionButtons(pageData);\n\n // Extract app name and page name\n let appName = \"Encore App\";\n let pageName = \"Page\";\n\n try {\n let appDataForName = cachedAppData;\n if (!appDataForName) {\n const appJsonPath = join(tempDir, \"app.json\");\n if (existsSync(appJsonPath)) {\n const appJsonContent = await readFile(appJsonPath, \"utf-8\");\n appDataForName = JSON.parse(appJsonContent);\n }\n }\n if (appDataForName) {\n appName = appDataForName?.app?.store?.name || appName;\n }\n } catch (error) {\n // Ignore errors, use defaults\n }\n\n pageName = pageData.name || pageData.id || pageName;\n\n // Generate component name and directory name\n let { directoryPath, componentName } = generateNames(appName, pageName);\n\n // Ensure unique component name\n if (usedNames) {\n let uniqueName = componentName;\n let counter = 2;\n while (usedNames.has(uniqueName)) {\n uniqueName = `${componentName}${counter}`;\n counter++;\n }\n if (uniqueName !== componentName) {\n componentName = uniqueName;\n // Reconstitute directory path with new component name\n // generateNames uses: join(appPascal, pagePascal) where pagePascal is componentName\n const appCamel = sanitizePropName(appName);\n const appPascal = appCamel.charAt(0).toUpperCase() + appCamel.slice(1);\n directoryPath = join(appPascal, componentName);\n }\n usedNames.add(componentName);\n }\n\n const directoryName = directoryPath;\n\n // Update output path\n if (needsFilenameGeneration) {\n finalOutputPath = join(outputPath, directoryName);\n } else {\n const providedDir = dirname(finalOutputPath);\n finalOutputPath = join(providedDir, directoryName);\n }\n\n // Generate component code and README\n const componentCode = generateComponentCode(\n appId,\n pageId,\n componentName,\n sliders,\n standaloneComponents,\n inputGroups,\n forms,\n selectInputs,\n actionButtons,\n !!isProduction,\n {\n width: pageData.style?.width,\n height: pageData.style?.height,\n aspectRatio:\n pageData.style?.width && pageData.style?.height\n ? pageData.style.width / pageData.style.height\n : undefined,\n }\n );\n\n const readmeContent = generateReadme(\n appId,\n pageId,\n appName,\n pageName,\n componentName,\n sliders,\n standaloneComponents,\n inputGroups,\n forms,\n selectInputs,\n actionButtons\n );\n\n // Ensure output directory exists\n if (!existsSync(finalOutputPath)) {\n await mkdir(finalOutputPath, { recursive: true });\n }\n\n // Write files\n if (isProduction) {\n const componentJsPath = join(tempDir, \"component.js\");\n let componentCodeContent = \"\";\n try {\n componentCodeContent = await readFile(componentJsPath, \"utf-8\");\n } catch (e) {}\n\n let appDataForProd = cachedAppData;\n if (!appDataForProd) {\n try {\n const appJsonPath = join(tempDir, \"app.json\");\n const appJsonContent = await readFile(appJsonPath, \"utf-8\");\n appDataForProd = JSON.parse(appJsonContent);\n } catch (e) {}\n }\n\n const productionData = {\n app: appDataForProd,\n page: pageData,\n componentCode: componentCodeContent,\n };\n await writeFile(\n join(finalOutputPath, \"data.json\"),\n JSON.stringify(productionData, null, 2),\n \"utf-8\"\n );\n }\n\n const indexPath = join(finalOutputPath, \"index.tsx\");\n const readmePath = join(finalOutputPath, \"README.md\");\n\n await writeFile(indexPath, componentCode, \"utf-8\");\n await writeFile(readmePath, readmeContent, \"utf-8\");\n\n console.log(`✓ Generated wrapper component at: ${indexPath}`);\n}\n\nfunction printUsage() {\n console.log(`\nUsage: generate-wrapper.ts <appId> [pageId] <outputPath>\n\nArguments:\n appId The Encore app ID\n pageId The Encore page ID (optional - if omitted, generates wrappers for ALL pages)\n outputPath Path where the generated TSX file(s) should be saved\n --production Generate for production (bundles data)\n --preseed Alias for --production (bundles data)\n\nEnvironment variables:\n APPS_SERVICE_URL Base URL for the apps service\n\nExample:\n generate-wrapper.ts 01KA964B1T6KCKSKCNMYSTKRKZ 01KA964B2F42MN4WGCYDTG1Y70 ./src/components/MyEncoreApp.tsx\n`);\n}\n\nexport async function runGenerate(args: string[]) {\n const isProduction =\n args.includes(\"--production\") || args.includes(\"--preseed\");\n const cleanArgs = args.filter(\n (arg) => arg !== \"--production\" && arg !== \"--preseed\"\n );\n\n if (\n cleanArgs.length < 2 ||\n cleanArgs.includes(\"--help\") ||\n cleanArgs.includes(\"-h\")\n ) {\n printUsage();\n process.exit(\n cleanArgs.includes(\"--help\") || cleanArgs.includes(\"-h\") ? 0 : 1\n );\n }\n\n if (cleanArgs.length === 2) {\n const [appId, outputPath] = cleanArgs;\n\n try {\n const { pages, appData } = await getAppPages(appId);\n if (pages.length === 0) {\n console.warn(\"No pages found for this app.\");\n return;\n }\n\n const usedNames = new Set<string>();\n for (const page of pages) {\n if (!page.id) continue;\n try {\n await generateWrapper({\n appId,\n pageId: page.id,\n outputPath,\n cachedAppData: appData,\n isProduction,\n usedNames,\n });\n } catch (error) {\n console.warn(\n `Error with page ${page.id}:`,\n error instanceof Error ? error.message : error\n );\n }\n }\n } catch (error) {\n console.error(\"\\nError:\", error instanceof Error ? error.message : error);\n process.exit(1);\n }\n return;\n }\n\n const [appId, pageId, outputPath] = cleanArgs;\n\n try {\n await generateWrapper({ appId, pageId, outputPath, isProduction }); // Single page generation, no collision context needed unless we wanted global uniqueness but usually used for one-off\n } catch (error) {\n console.error(\"\\nError:\", error instanceof Error ? error.message : error);\n process.exit(1);\n }\n}\n"],"names":["writeFile","mkdir","readFile","fs","dotenv.config","APPS_SERVICE_URL","CONST_APPS_SERVICE_URL","COMPONENTS_CDN_URL","CONST_COMPONENTS_CDN_URL","downloadFile","url","headers","response","generateNames","appName","pageName","appCamel","sanitizePropName","pageCamel","appPascal","pagePascal","join","getAppPages","appId","content","appData","error","generateWrapper","pageId","outputPath","cachedAppData","isProduction","usedNames","finalOutputPath","needsFilenameGeneration","pathExt","stat","tempDir","existsSync","files","file","filePath","pageJsonPath","pageJsonContent","pageResponse","pageData","appUrl","appContent","page","p","sliders","findSlidersAndDataBindings","standaloneComponents","findStandaloneComponents","inputGroups","findInputGroups","forms","findForms","qualifyFormInputs","selectInputs","findStandaloneSelectInputs","actionButtons","findActionButtons","appDataForName","appJsonPath","appJsonContent","directoryPath","componentName","uniqueName","counter","directoryName","providedDir","dirname","componentCode","generateComponentCode","readmeContent","generateReadme","componentJsPath","componentCodeContent","appDataForProd","productionData","indexPath","readmePath","printUsage","runGenerate","args","cleanArgs","arg","pages"],"mappings":";;;;;;AAqBA,MAAM,EAAE,WAAAA,GAAW,OAAAC,GAAO,UAAAC,EAAA,IAAaC;AAEvCC,EAAAA,OAAO;AAGP,MAAMC,IACJ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,yBACZC;AACF,QAAQ,IAAI,2BAA2BD,CAAgB,EAAE;AACzD,MAAME,KAAqBC;AAE3B,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,SAASC,GACPC,GACAC,GACkD;AAClD,QAAMC,IAAWC,EAAiBH,CAAO,GACnCI,IAAYD,EAAiBF,CAAQ,GAErCI,IAAYH,EAAS,OAAO,CAAC,EAAE,gBAAgBA,EAAS,MAAM,CAAC,GAC/DI,IAAaF,EAAU,OAAO,CAAC,EAAE,gBAAgBA,EAAU,MAAM,CAAC;AACxE,SAAO;AAAA,IACL,eAAeG,EAAKF,GAAWC,CAAU;AAAA,IACzC,eAAeA;AAAA,EAAA;AAEnB;AAEA,eAAeE,G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,GAAOM,CAAU,IAAIyD;AAE5B,QAAI;AACF,YAAM,EAAE,OAAAE,GAAO,SAAA/D,EAAA,IAAY,MAAMH,GAAYC,CAAK;AAClD,UAAIiE,EAAM,WAAW,GAAG;AACtB,gBAAQ,KAAK,8BAA8B;AAC3C;AAAA,MACF;AAEA,YAAMxD,wBAAgB,IAAA;AACtB,iBAAWgB,KAAQwC;AACjB,YAAKxC,EAAK;AACV,cAAI;AACF,kBAAMrB,EAAgB;AAAA,cACpB,OAAAJ;AAAAA,cACA,QAAQyB,EAAK;AAAA,cACb,YAAAnB;AAAAA,cACA,eAAeJ;AAAA,cACf,cAAAM;AAAA,cACA,WAAAC;AAAA,YAAA,CACD;AAAA,UACH,SAASN,GAAO;AACd,oBAAQ;AAAA,cACN,mBAAmBsB,EAAK,EAAE;AAAA,cAC1BtB,aAAiB,QAAQA,EAAM,UAAUA;AAAA,YAAA;AAAA,UAE7C;AAAA,IAEJ,SAASA,GAAO;AACd,cAAQ,MAAM;AAAA,SAAYA,aAAiB,QAAQA,EAAM,UAAUA,CAAK,GACxE,QAAQ,KAAK,CAAC;AAAA,IAChB;AACA;AAAA,EACF;AAEA,QAAM,CAACH,GAAOK,GAAQC,CAAU,IAAIyD;AAEpC,MAAI;AACF,UAAM3D,EAAgB,EAAE,OAAAJ,GAAO,QAAAK,GAAQ,YAAAC,GAAY,cAAAE,GAAc;AAAA,EACnE,SAASL,GAAO;AACd,YAAQ,MAAM;AAAA,SAAYA,aAAiB,QAAQA,EAAM,UAAUA,CAAK,GACxE,QAAQ,KAAK,CAAC;AAAA,EAChB;AACF;"}
|
|
1
|
+
{"version":3,"file":"generate.js","sources":["../../../src/cli/commands/generate.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\nimport { join, dirname } from \"path\";\nimport { existsSync } from \"fs\";\nimport * as dotenv from \"dotenv\";\nimport {\n CONST_APPS_SERVICE_URL,\n CONST_COMPONENTS_CDN_URL,\n} from \"../../../constants\";\nimport {\n findSlidersAndDataBindings,\n findStandaloneComponents,\n findInputGroups,\n findForms,\n findStandaloneSelectInputs,\n findActionButtons,\n qualifyFormInputs,\n generateComponentCode,\n generateReadme,\n sanitizePropName,\n} from \"../../codegen\";\n\nconst { writeFile, mkdir, readFile } = fs;\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.APPS_SERVICE_URL ||\n process.env.VITE_APPS_SERVICE_URL ||\n CONST_APPS_SERVICE_URL;\nconsole.log(`Using APPS_SERVICE_URL: ${APPS_SERVICE_URL}`);\nconst COMPONENTS_CDN_URL = CONST_COMPONENTS_CDN_URL;\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\nfunction generateNames(\n appName: string,\n pageName: string\n): { directoryPath: string; componentName: string } {\n const appCamel = sanitizePropName(appName);\n const pageCamel = sanitizePropName(pageName);\n // Capitalize first letter for PascalCase\n const appPascal = appCamel.charAt(0).toUpperCase() + appCamel.slice(1);\n const pagePascal = pageCamel.charAt(0).toUpperCase() + pageCamel.slice(1);\n return {\n directoryPath: join(appPascal, pagePascal),\n componentName: pagePascal,\n };\n}\n\nasync function getAppPages(\n appId: string\n): Promise<{ pages: any[]; appData: any }> {\n const url = `${APPS_SERVICE_URL}/devices/apps/${appId}`;\n console.log(`Fetching app data from ${url}...`);\n try {\n const content = await downloadFile(url);\n const appData = JSON.parse(content);\n const pages = appData?.app?.data?.pages || [];\n return { pages, appData };\n } catch (error) {\n console.error(\"Failed to fetch app data:\", error);\n throw error;\n }\n}\n\nasync function generateWrapper({\n appId,\n pageId,\n outputPath,\n cachedAppData,\n mode = \"dynamic\",\n usedNames,\n}: {\n appId: string;\n pageId: string;\n outputPath: string;\n cachedAppData?: any;\n mode?: string;\n usedNames?: Set<string>;\n}) {\n console.log(\n `Generating wrapper for app: ${appId}, page: ${pageId}, mode: ${mode}`\n );\n\n // Determine final output path - we'll update it after we get app/page names\n let finalOutputPath = outputPath;\n let needsFilenameGeneration = false;\n const pathExt = outputPath.split(\".\").pop()?.toLowerCase();\n if (\n pathExt !== \"tsx\" &&\n pathExt !== \"ts\" &&\n pathExt !== \"jsx\" &&\n pathExt !== \"js\"\n ) {\n // Path doesn't have a file extension, treat as directory\n const { stat } = await import(\"fs/promises\");\n try {\n const pathStats = await stat(outputPath);\n if (pathStats.isDirectory()) {\n needsFilenameGeneration = true;\n }\n } catch {\n // Path doesn't exist, check if it looks like a directory (no extension)\n if (!pathExt || outputPath.endsWith(\"/\")) {\n needsFilenameGeneration = true;\n }\n }\n }\n\n if (needsFilenameGeneration) {\n console.log(\n `Output path is a directory, will generate filename from app/page names`\n );\n }\n\n console.log(`Output path: ${outputPath}`);\n\n // Create temp directory for downloaded files\n const tempDir = join(process.cwd(), \".temp-bravo\", appId, pageId);\n if (!existsSync(tempDir)) {\n await mkdir(tempDir, { recursive: true });\n }\n\n // Download files (skip app.json if we have cached data)\n const files: Array<{\n url: string;\n filename: string;\n headers?: Record<string, string>;\n skipIfCached?: boolean;\n }> = [\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}`,\n filename: \"app.json\",\n skipIfCached: true,\n },\n {\n url: `${APPS_SERVICE_URL}/devices/apps/${appId}/node/${pageId}`,\n filename: \"page.json\",\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 // Skip app.json if we have cached data\n if (file.skipIfCached && cachedAppData) {\n console.log(`Using cached ${file.filename} (skipping download)`);\n const filePath = join(tempDir, file.filename);\n await writeFile(\n filePath,\n JSON.stringify(cachedAppData, null, 2),\n \"utf-8\"\n );\n console.log(`✓ Saved ${file.filename} from cache`);\n continue;\n }\n\n try {\n console.log(`Downloading ${file.filename} from ${file.url}...`);\n const content = await downloadFile(file.url, file.headers);\n const filePath = join(tempDir, file.filename);\n await writeFile(filePath, content, \"utf-8\");\n console.log(`✓ Saved ${file.filename}`);\n } catch (error) {\n console.error(`✗ Failed to download ${file.filename}:`, error);\n throw error;\n }\n }\n\n // Read and parse page.json\n const pageJsonPath = join(tempDir, \"page.json\");\n const pageJsonContent = await readFile(pageJsonPath, \"utf-8\");\n const pageResponse = JSON.parse(pageJsonContent);\n\n // Extract page data - API response has it under 'data' field\n let pageData = pageResponse.data || pageResponse;\n\n // If pageData doesn't have body, try using cached app.json or downloading as fallback\n if (!pageData.body && !(pageData as any).data?.body) {\n console.log(\"Page data doesn't have body, trying app.json...\");\n try {\n let appData = cachedAppData;\n\n // If we don't have cached data, download it\n if (!appData) {\n const appUrl = `${APPS_SERVICE_URL}/devices/apps/${appId}`;\n const appContent = await downloadFile(appUrl);\n appData = JSON.parse(appContent);\n }\n\n // Find the page in app.data.pages\n const pages = appData?.app?.data?.pages || [];\n const page = pages.find((p: any) => p.id === pageId);\n if (page) {\n pageData = page;\n console.log(\"✓ Found page data in app.json\");\n }\n } catch (error) {\n console.warn(\"Could not load app.json:\", error);\n }\n }\n\n // Find components using extracted logic\n const sliders = findSlidersAndDataBindings(pageData);\n const standaloneComponents = findStandaloneComponents(pageData);\n const inputGroups = findInputGroups(pageData);\n const forms = findForms(pageData);\n\n // Qualify form input prop names\n qualifyFormInputs(forms);\n\n const selectInputs = findStandaloneSelectInputs(pageData, forms);\n const actionButtons = findActionButtons(pageData);\n\n // Extract app name and page name\n let appName = \"Encore App\";\n let pageName = \"Page\";\n\n try {\n let appDataForName = cachedAppData;\n if (!appDataForName) {\n const appJsonPath = join(tempDir, \"app.json\");\n if (existsSync(appJsonPath)) {\n const appJsonContent = await readFile(appJsonPath, \"utf-8\");\n appDataForName = JSON.parse(appJsonContent);\n }\n }\n if (appDataForName) {\n appName = appDataForName?.app?.store?.name || appName;\n }\n } catch (error) {\n // Ignore errors, use defaults\n }\n\n pageName = pageData.name || pageData.id || pageName;\n\n // Generate component name and directory name\n let { directoryPath, componentName } = generateNames(appName, pageName);\n\n // Ensure unique component name\n if (usedNames) {\n let uniqueName = componentName;\n let counter = 2;\n while (usedNames.has(uniqueName)) {\n uniqueName = `${componentName}${counter}`;\n counter++;\n }\n if (uniqueName !== componentName) {\n componentName = uniqueName;\n // Reconstitute directory path with new component name\n // generateNames uses: join(appPascal, pagePascal) where pagePascal is componentName\n const appCamel = sanitizePropName(appName);\n const appPascal = appCamel.charAt(0).toUpperCase() + appCamel.slice(1);\n directoryPath = join(appPascal, componentName);\n }\n usedNames.add(componentName);\n }\n\n const directoryName = directoryPath;\n\n // Update output path\n if (needsFilenameGeneration) {\n finalOutputPath = join(outputPath, directoryName);\n } else {\n const providedDir = dirname(finalOutputPath);\n finalOutputPath = join(providedDir, directoryName);\n }\n\n // Generate component code and README\n const shouldBundleData = mode === \"production\" || mode === \"optimistic\";\n const componentCode = generateComponentCode(\n appId,\n pageId,\n componentName,\n sliders,\n standaloneComponents,\n inputGroups,\n forms,\n selectInputs,\n actionButtons,\n mode,\n {\n width: pageData.style?.width,\n height: pageData.style?.height,\n aspectRatio:\n pageData.style?.width && pageData.style?.height\n ? pageData.style.width / pageData.style.height\n : undefined,\n }\n );\n\n const readmeContent = generateReadme(\n appId,\n pageId,\n appName,\n pageName,\n componentName,\n sliders,\n standaloneComponents,\n inputGroups,\n forms,\n selectInputs,\n actionButtons\n );\n\n // Ensure output directory exists\n if (!existsSync(finalOutputPath)) {\n await mkdir(finalOutputPath, { recursive: true });\n }\n\n // Write files\n if (shouldBundleData) {\n const componentJsPath = join(tempDir, \"component.js\");\n let componentCodeContent = \"\";\n try {\n componentCodeContent = await readFile(componentJsPath, \"utf-8\");\n } catch (e) {}\n\n let appDataForProd = cachedAppData;\n if (!appDataForProd) {\n try {\n const appJsonPath = join(tempDir, \"app.json\");\n const appJsonContent = await readFile(appJsonPath, \"utf-8\");\n appDataForProd = JSON.parse(appJsonContent);\n } catch (e) {}\n }\n\n const productionData = {\n app: appDataForProd,\n page: pageData,\n componentCode: componentCodeContent,\n };\n await writeFile(\n join(finalOutputPath, \"data.json\"),\n JSON.stringify(productionData, null, 2),\n \"utf-8\"\n );\n }\n\n const indexPath = join(finalOutputPath, \"index.tsx\");\n const readmePath = join(finalOutputPath, \"README.md\");\n\n await writeFile(indexPath, componentCode, \"utf-8\");\n await writeFile(readmePath, readmeContent, \"utf-8\");\n\n console.log(`✓ Generated wrapper component at: ${indexPath}`);\n}\n\nexport async function runGenerate(\n appId: string,\n pageId: string | undefined,\n outputPath: string | undefined,\n mode: string\n) {\n if (!appId || (!pageId && !outputPath)) {\n console.error(\n \"Error: Missing required arguments. Usage: generate <appId> [pageId] <outputPath>\"\n );\n process.exit(1);\n }\n\n // If outputPath is missing but we have 2 args logic from caller, handle it.\n // actually caller logic:\n // if 2 args (appId, pageId/output), caller puts output in output and pageId=undefined.\n // so if we are here, we have appId and outputPath. pageId might be undefined.\n\n // Wait, if I changed the caller to pass (appId, undefined, outputPath), I need to be sure.\n // arguments: appId, pageId, outputPath.\n // If user ran: generate app out\n // caller: appId=app, pageId=out, output=undefined.\n // caller logic: if (pageId && !output) -> output=pageId, pageId=undefined.\n // caller calls: runGenerate(app, undefined, out, prod).\n\n // If user ran: generate app page out\n // caller: appId=app, pageId=page, output=out.\n // caller calls: runGenerate(app, page, out, prod).\n\n // So outputPath MUST be defined here effectively if the CLI usage was correct.\n if (!outputPath) {\n console.error(\"Error: Missing output path.\");\n process.exit(1);\n }\n\n // Default mode: Generate all pages\n if (!pageId) {\n try {\n const { pages, appData } = await getAppPages(appId);\n if (pages.length === 0) {\n console.warn(\"No pages found for this app.\");\n return;\n }\n\n const usedNames = new Set<string>();\n for (const page of pages) {\n if (!page.id) continue;\n try {\n await generateWrapper({\n appId,\n pageId: page.id,\n outputPath,\n cachedAppData: appData,\n mode,\n usedNames,\n });\n } catch (error) {\n console.warn(\n `Error with page ${page.id}:`,\n error instanceof Error ? error.message : error\n );\n }\n }\n } catch (error) {\n console.error(\"\\nError:\", error instanceof Error ? error.message : error);\n process.exit(1);\n }\n return;\n }\n\n // Single page generation\n try {\n await generateWrapper({ appId, pageId, outputPath, mode });\n } catch (error) {\n console.error(\"\\nError:\", error instanceof Error ? error.message : error);\n process.exit(1);\n }\n}\n"],"names":["writeFile","mkdir","readFile","fs","dotenv.config","APPS_SERVICE_URL","CONST_APPS_SERVICE_URL","COMPONENTS_CDN_URL","CONST_COMPONENTS_CDN_URL","downloadFile","url","headers","response","generateNames","appName","pageName","appCamel","sanitizePropName","pageCamel","appPascal","pagePascal","join","getAppPages","appId","content","appData","error","generateWrapper","pageId","outputPath","cachedAppData","mode","usedNames","finalOutputPath","needsFilenameGeneration","pathExt","stat","tempDir","existsSync","files","file","filePath","pageJsonPath","pageJsonContent","pageResponse","pageData","appUrl","appContent","page","p","sliders","findSlidersAndDataBindings","standaloneComponents","findStandaloneComponents","inputGroups","findInputGroups","forms","findForms","qualifyFormInputs","selectInputs","findStandaloneSelectInputs","actionButtons","findActionButtons","appDataForName","appJsonPath","appJsonContent","directoryPath","componentName","uniqueName","counter","directoryName","providedDir","dirname","shouldBundleData","componentCode","generateComponentCode","readmeContent","generateReadme","componentJsPath","componentCodeContent","appDataForProd","productionData","indexPath","readmePath","runGenerate","pages"],"mappings":";;;;;;AAqBA,MAAM,EAAE,WAAAA,GAAW,OAAAC,GAAO,UAAAC,EAAA,IAAaC;AAEvCC,EAAAA,OAAO;AAGP,MAAMC,IACJ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,yBACZC;AACF,QAAQ,IAAI,2BAA2BD,CAAgB,EAAE;AACzD,MAAME,KAAqBC;AAE3B,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,IAA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-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
r();
|
|
1
|
+
import { Command as i } from "commander";
|
|
2
|
+
import { runDownload as p } from "./cli/commands/download.js";
|
|
3
|
+
import { runGenerate as c } from "./cli/commands/generate.js";
|
|
4
|
+
const o = new i();
|
|
5
|
+
o.name("encore-lib").description("Encore CLI tools").version("0.1.32");
|
|
6
|
+
o.command("download").description("Download Encore page data").argument("<appId>", "The Encore app ID").argument("<pageId>", "The Encore page ID").argument("<targetPath>", "Path where files should be saved").action(async (n, e, a) => {
|
|
7
|
+
await p(n, e, a);
|
|
8
|
+
});
|
|
9
|
+
o.command("generate").description("Generate React wrapper components").argument("<appId>", "The Encore app ID").argument("[pageId]", "The Encore page ID (optional)").argument(
|
|
10
|
+
"[outputPath]",
|
|
11
|
+
"Path where the generated TSX file(s) should be saved"
|
|
12
|
+
).option(
|
|
13
|
+
"--mode <mode>",
|
|
14
|
+
"Deployment mode: dynamic (default), optimistic, or production"
|
|
15
|
+
).action(async (n, e, a, m) => {
|
|
16
|
+
let t = e, r = a;
|
|
17
|
+
e && !a && (r = e, t = void 0);
|
|
18
|
+
const d = m.mode || "dynamic";
|
|
19
|
+
await c(n, t, r, d);
|
|
20
|
+
});
|
|
21
|
+
o.parse();
|
|
25
22
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sources":["../src/cli/index.ts"],"sourcesContent":["\nimport { runDownload } from \"./commands/download\";\nimport { runGenerate } from \"./commands/generate\";\n\
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli/index.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { runDownload } from \"./commands/download\";\nimport { runGenerate } from \"./commands/generate\";\n\nconst program = new Command();\n\nprogram\n .name(\"encore-lib\")\n .description(\"Encore CLI tools\")\n // We'll read version from package.json in build or hardcode for now to avoid async import issues in simple CLI\n .version(\"0.1.32\");\n\nprogram\n .command(\"download\")\n .description(\"Download Encore page data\")\n .argument(\"<appId>\", \"The Encore app ID\")\n .argument(\"<pageId>\", \"The Encore page ID\")\n .argument(\"<targetPath>\", \"Path where files should be saved\")\n .action(async (appId, pageId, targetPath) => {\n await runDownload(appId, pageId, targetPath);\n });\n\nprogram\n .command(\"generate\")\n .description(\"Generate React wrapper components\")\n .argument(\"<appId>\", \"The Encore app ID\")\n .argument(\"[pageId]\", \"The Encore page ID (optional)\")\n .argument(\n \"[outputPath]\",\n \"Path where the generated TSX file(s) should be saved\"\n )\n .option(\n \"--mode <mode>\",\n \"Deployment mode: dynamic (default), optimistic, or production\"\n )\n .action(async (appId, pageId, outputPath, options) => {\n // Handle overload: generate <appId> <outputPath> vs generate <appId> <pageId> <outputPath>\n let finalPageId = pageId;\n let finalOutputPath = outputPath;\n\n // If only 2 arguments provided (appId and pageId/outputPath), the second one is outputPath\n if (pageId && !outputPath) {\n finalOutputPath = pageId;\n finalPageId = undefined;\n }\n\n const mode = options.mode || \"dynamic\";\n\n await runGenerate(appId, finalPageId, finalOutputPath, mode);\n });\n\nprogram.parse();\n"],"names":["program","Command","appId","pageId","targetPath","runDownload","outputPath","options","finalPageId","finalOutputPath","mode","runGenerate"],"mappings":";;;AAIA,MAAMA,IAAU,IAAIC,EAAA;AAEpBD,EACG,KAAK,YAAY,EACjB,YAAY,kBAAkB,EAE9B,QAAQ,QAAQ;AAEnBA,EACG,QAAQ,UAAU,EAClB,YAAY,2BAA2B,EACvC,SAAS,WAAW,mBAAmB,EACvC,SAAS,YAAY,oBAAoB,EACzC,SAAS,gBAAgB,kCAAkC,EAC3D,OAAO,OAAOE,GAAOC,GAAQC,MAAe;AAC3C,QAAMC,EAAYH,GAAOC,GAAQC,CAAU;AAC7C,CAAC;AAEHJ,EACG,QAAQ,UAAU,EAClB,YAAY,mCAAmC,EAC/C,SAAS,WAAW,mBAAmB,EACvC,SAAS,YAAY,+BAA+B,EACpD;AAAA,EACC;AAAA,EACA;AACF,EACC;AAAA,EACC;AAAA,EACA;AACF,EACC,OAAO,OAAOE,GAAOC,GAAQG,GAAYC,MAAY;AAEpD,MAAIC,IAAcL,GACdM,IAAkBH;AAGtB,EAAIH,KAAU,CAACG,MACbG,IAAkBN,GAClBK,IAAc;AAGhB,QAAME,IAAOH,EAAQ,QAAQ;AAE7B,QAAMI,EAAYT,GAAOM,GAAaC,GAAiBC,CAAI;AAC7D,CAAC;AAEHV,EAAQ,MAAA;"}
|