create-ilorb 0.0.0-stage → 0.2.0
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/LICENSE-API.md +108 -0
- package/README.md +285 -2
- package/assets/dev-local.mjs +205 -0
- package/dist/args.js +39 -0
- package/dist/cli.js +7 -0
- package/dist/cloudflare/provider.js +48 -0
- package/dist/cloudflare/real.js +211 -0
- package/dist/cloudflare/simulated.js +213 -0
- package/dist/core-admin.js +85 -0
- package/dist/engine.js +52 -0
- package/dist/errors.js +23 -0
- package/dist/exec.js +49 -0
- package/dist/fsutil.js +130 -0
- package/dist/generate.js +260 -0
- package/dist/i18n/en.js +380 -0
- package/dist/i18n/es.js +372 -0
- package/dist/i18n/index.js +23 -0
- package/dist/i18n/pt.js +372 -0
- package/dist/license/activate.js +71 -0
- package/dist/license/keys.js +14 -0
- package/dist/license/verify.js +56 -0
- package/dist/local/ports.js +33 -0
- package/dist/main.js +594 -0
- package/dist/products.js +1528 -0
- package/dist/readme.js +228 -0
- package/dist/state.js +58 -0
- package/dist/steps.js +869 -0
- package/dist/templates.js +31 -0
- package/dist/theme/preview.js +39 -0
- package/dist/theme/vendor/color.js +133 -0
- package/dist/theme/vendor/tokens.js +314 -0
- package/dist/ui/prompt.js +108 -0
- package/dist/ui/term.js +92 -0
- package/package.json +50 -4
package/dist/main.js
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
// create-ilorb (ex create-overture): template folder (+ ilorb.env) → questions → project → Cloudflare (or local) → panel → URLs.
|
|
2
|
+
// Ilorb Code templates are FREE (owner, 12/11/2026): no license. The old license path stays dormant: it only runs when
|
|
3
|
+
// --license / --purchase-code (or their env vars) are given.
|
|
4
|
+
// main() receives everything from outside (exec, fetch, provider, questions, output) so tests can run the whole flow.
|
|
5
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { parseArgs, str } from "./args.js";
|
|
9
|
+
import { RealCloudflare } from "./cloudflare/real.js";
|
|
10
|
+
import { SimulatedCloudflare } from "./cloudflare/simulated.js";
|
|
11
|
+
import { printPlan, runSteps } from "./engine.js";
|
|
12
|
+
import { HumanError, isHuman } from "./errors.js";
|
|
13
|
+
import { realExec } from "./exec.js";
|
|
14
|
+
import { detectLang, hasMsg, setLang, t } from "./i18n/index.js";
|
|
15
|
+
import { DEFAULT_LICENSE_SERVER } from "./license/keys.js";
|
|
16
|
+
import { looksLikeLicenseKey, looksLikePurchaseCode, maskCredential } from "./license/verify.js";
|
|
17
|
+
import { BUNDLE_RE, DEFAULT_LOCALES, DOMAIN_RE, EMAIL_RE, HEX_RE, LOCALES, PRODUCTS, slugify, suggestBundleId } from "./products.js";
|
|
18
|
+
import { licensePath, loadSecrets, loadState, newState, saveSecrets, saveState, STATE_DIR, } from "./state.js";
|
|
19
|
+
import { buildSteps } from "./steps.js";
|
|
20
|
+
import { normalizeHex, PRESET_IDS, primaryReport, resolveTheme, themeLine } from "./theme/preview.js";
|
|
21
|
+
import { PRESETS } from "./theme/vendor/tokens.js";
|
|
22
|
+
import { ttyPrompter } from "./ui/prompt.js";
|
|
23
|
+
import { Out } from "./ui/term.js";
|
|
24
|
+
export const CLI_VERSION = (() => {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8')).version;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return '0.0.0';
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
export async function main(argv, deps = {}) {
|
|
33
|
+
let env = deps.env ?? process.env;
|
|
34
|
+
const { positionals, flags } = parseArgs(argv);
|
|
35
|
+
const lang = detectLang(str(flags.lang), env);
|
|
36
|
+
setLang(lang.lang);
|
|
37
|
+
const out = deps.out ?? new Out();
|
|
38
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
39
|
+
if (flags.help) {
|
|
40
|
+
out.line(t('help'));
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
if (flags.version) {
|
|
44
|
+
out.line(CLI_VERSION);
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
let dir = '';
|
|
48
|
+
let ctx = null;
|
|
49
|
+
try {
|
|
50
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
51
|
+
if (major < 20)
|
|
52
|
+
throw new HumanError('node_too_old', { version: process.versions.node });
|
|
53
|
+
// ── who and where ─────────────────────────────────────────────────────────────────────────
|
|
54
|
+
const resume = flags.resume === true;
|
|
55
|
+
let productId = positionals[0];
|
|
56
|
+
let dirArg = positionals[1];
|
|
57
|
+
if (resume && productId && !PRODUCTS[productId]) {
|
|
58
|
+
dirArg = productId;
|
|
59
|
+
productId = undefined;
|
|
60
|
+
}
|
|
61
|
+
if (dirArg)
|
|
62
|
+
dir = isAbsolute(dirArg) ? dirArg : resolve(cwd, dirArg);
|
|
63
|
+
else if (resume)
|
|
64
|
+
dir = cwd;
|
|
65
|
+
let state = dir ? loadState(dir) : null;
|
|
66
|
+
if (resume && !state)
|
|
67
|
+
throw new HumanError('no_state', { dir: dir || cwd });
|
|
68
|
+
productId ??= state?.product;
|
|
69
|
+
if (!productId) {
|
|
70
|
+
out.line(t('help'));
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
const product = PRODUCTS[productId];
|
|
74
|
+
if (!product)
|
|
75
|
+
throw new HumanError('unknown_product', { product: productId, list: Object.keys(PRODUCTS).join(', ') });
|
|
76
|
+
const target = str(flags.target) ?? state?.target ?? 'cloud';
|
|
77
|
+
if (target !== 'cloud' && target !== 'local')
|
|
78
|
+
throw new HumanError('invalid_answer', { field: '--target', value: String(flags.target), hint: 'cloud | local' });
|
|
79
|
+
if (state && (state.product !== product.id || state.target !== target))
|
|
80
|
+
throw new HumanError('state_mismatch', { product: state.product, target: state.target });
|
|
81
|
+
const interactive = !flags.yes && deps.prompter !== null && (deps.prompter !== undefined || !!process.stdin.isTTY);
|
|
82
|
+
const prompter = interactive ? deps.prompter ?? ttyPrompter(out, { yes: t('yes'), no: t('no'), choose: t('choose'), invalid: t('invalid') }) : null;
|
|
83
|
+
out.line();
|
|
84
|
+
out.line(`${out.bold(out.magenta('◆'))} ${out.bold(t('app.title'))} ${out.dim(`v${CLI_VERSION}`)}`);
|
|
85
|
+
out.line(` ${out.dim(t('app.subtitle', { product: `${product.name.replace(/^Overture /, 'Ilorb ')} Template` }))}`);
|
|
86
|
+
if (lang.fallbackFrom)
|
|
87
|
+
out.line(` ${out.dim('(ar → en)')}`);
|
|
88
|
+
out.line();
|
|
89
|
+
// ── template source, Ilorb key, answers ─────────────────────────────────────────────────
|
|
90
|
+
const secrets = dir ? loadSecrets(dir) : {};
|
|
91
|
+
// legacy (dormant): a license only when one is given; Ilorb Code templates need none
|
|
92
|
+
const legacyLicense = !!(str(flags.license) ?? str(flags['purchase-code']) ?? env.OVERTURE_LICENSE ?? env.ENVATO_PURCHASE_CODE);
|
|
93
|
+
const credential = state ? loadCredential(dir) ?? (legacyLicense ? await askCredential(flags, env, prompter) : null) : legacyLicense ? await askCredential(flags, env, prompter) : null;
|
|
94
|
+
// where the template is: --templates, OVERTURE_TEMPLATES, or the folder we run in (an unzipped Ilorb Code download)
|
|
95
|
+
const templatesDir = str(flags.templates)
|
|
96
|
+
? resolve(cwd, str(flags.templates))
|
|
97
|
+
: env.OVERTURE_TEMPLATES
|
|
98
|
+
? resolve(cwd, env.OVERTURE_TEMPLATES)
|
|
99
|
+
: existsSync(join(cwd, 'overture-core')) && existsSync(join(cwd, `overture-${product.id}`))
|
|
100
|
+
? cwd
|
|
101
|
+
: null;
|
|
102
|
+
if (!templatesDir && !credential)
|
|
103
|
+
throw new HumanError('templates_needed', { product: product.id });
|
|
104
|
+
// ilorb.env (written by the Ilorb Code download) feeds the Ilorb Signal key and endpoints; flags/env still win
|
|
105
|
+
const ilorb = templatesDir ? readIlorbEnv(templatesDir) : {};
|
|
106
|
+
if (ilorb.ILORB_APP_ID && flags['opera-app-id'] === undefined && (product.opera || product.ilorbOptional))
|
|
107
|
+
flags['opera-app-id'] = ilorb.ILORB_APP_ID;
|
|
108
|
+
env = {
|
|
109
|
+
...env,
|
|
110
|
+
...(ilorb.ILORB_APP_SECRET && !env.OPERA_APP_SECRET ? { OPERA_APP_SECRET: ilorb.ILORB_APP_SECRET } : {}),
|
|
111
|
+
...(ilorb.ILORB_CHAT_URL && !env.ILORB_CHAT_URL ? { ILORB_CHAT_URL: ilorb.ILORB_CHAT_URL } : {}),
|
|
112
|
+
...(ilorb.ILORB_API_URL && !env.ILORB_API_URL ? { ILORB_API_URL: ilorb.ILORB_API_URL } : {}),
|
|
113
|
+
};
|
|
114
|
+
if (ilorb.ILORB_APP_ID)
|
|
115
|
+
out.line(` ${out.dim(t('ilorb.key', { appId: ilorb.ILORB_APP_ID }))}`);
|
|
116
|
+
const answers = await collectAnswers({ flags, env, prompter, out, product, target, state, secrets, credential });
|
|
117
|
+
if (!dir)
|
|
118
|
+
dir = resolve(cwd, answers.slug);
|
|
119
|
+
if (!state) {
|
|
120
|
+
state = loadState(dir);
|
|
121
|
+
if (state && (state.product !== product.id || state.target !== target))
|
|
122
|
+
throw new HumanError('state_mismatch', { product: state.product, target: state.target });
|
|
123
|
+
if (!state && existsSync(dir) && readdirSync(dir).filter((f) => f !== '.DS_Store').length)
|
|
124
|
+
throw new HumanError('dir_not_empty', { dir });
|
|
125
|
+
}
|
|
126
|
+
Object.assign(secrets, { ...loadSecrets(dir), ...pick(secrets) });
|
|
127
|
+
if (prompter && !state) {
|
|
128
|
+
printSummary(out, answers, dir);
|
|
129
|
+
if (!(await prompter.confirm(t('q.confirm'), true))) {
|
|
130
|
+
out.line(t('q.cancelled'));
|
|
131
|
+
prompter.close();
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const isNew = !state;
|
|
136
|
+
state ??= newState(product.id, target, CLI_VERSION);
|
|
137
|
+
state.answers = answers;
|
|
138
|
+
const provider = target === 'cloud'
|
|
139
|
+
? deps.provider ??
|
|
140
|
+
(str(flags.provider) === 'simulated' || env.OVERTURE_PROVIDER === 'simulated' || state.simulated
|
|
141
|
+
? new SimulatedCloudflare({ delayMs: Number(env.OVERTURE_SIM_DELAY ?? 250) })
|
|
142
|
+
: new RealCloudflare({
|
|
143
|
+
exec: deps.exec ?? realExec,
|
|
144
|
+
fetch: deps.fetch,
|
|
145
|
+
apiToken: env.CLOUDFLARE_API_TOKEN,
|
|
146
|
+
stateDir: join(dir, STATE_DIR),
|
|
147
|
+
wrangler: () => join(dir, 'overture-core/api/workers/node_modules/.bin', process.platform === 'win32' ? 'wrangler.cmd' : 'wrangler'),
|
|
148
|
+
}))
|
|
149
|
+
: null;
|
|
150
|
+
if (provider?.kind === 'simulated') {
|
|
151
|
+
if (!deps.provider)
|
|
152
|
+
state.simulated = true;
|
|
153
|
+
out.line(` ${out.yellow('!')} ${out.bold(t('cf.simulated'))}`);
|
|
154
|
+
out.line();
|
|
155
|
+
}
|
|
156
|
+
ctx = {
|
|
157
|
+
dir, product, answers, secrets, state, out, provider, prompter, credential,
|
|
158
|
+
exec: deps.exec ?? realExec,
|
|
159
|
+
fetch: deps.fetch ?? fetch,
|
|
160
|
+
licenseServer: str(flags['license-server']) ?? env.OVERTURE_LICENSE_SERVER ?? state.licenseServer ?? DEFAULT_LICENSE_SERVER,
|
|
161
|
+
templatesDir,
|
|
162
|
+
cliVersion: CLI_VERSION,
|
|
163
|
+
serve: !(flags['no-serve'] === true || flags.serve === false),
|
|
164
|
+
env,
|
|
165
|
+
};
|
|
166
|
+
state.licenseServer = ctx.licenseServer;
|
|
167
|
+
const steps = buildSteps(product, target, answers, !!credential);
|
|
168
|
+
if (flags['dry-run']) {
|
|
169
|
+
printPlan(ctx, steps);
|
|
170
|
+
prompter?.close();
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
// ── from here on it writes ───────────────────────────────────────────────────────────────
|
|
174
|
+
mkdirSync(join(dir, STATE_DIR), { recursive: true });
|
|
175
|
+
out.logTo(join(dir, STATE_DIR, 'install.log'));
|
|
176
|
+
const logFlag = str(flags.log);
|
|
177
|
+
if (logFlag)
|
|
178
|
+
out.logTo(resolve(cwd, logFlag));
|
|
179
|
+
out.log(`\n===== ${new Date().toISOString()} create-overture ${CLI_VERSION} ${argv.map((a) => (/^osc1\.|^[0-9a-f]{8}-/i.test(a) ? maskCredential(a) : a)).join(' ')}`);
|
|
180
|
+
if (isNew)
|
|
181
|
+
out.info(`${t('sum.folder')}: ${dir}`);
|
|
182
|
+
saveSecrets(dir, secrets);
|
|
183
|
+
saveState(dir, state);
|
|
184
|
+
prompter?.close();
|
|
185
|
+
await runSteps(ctx, steps);
|
|
186
|
+
printFinal(ctx);
|
|
187
|
+
if (target === 'local' && ctx.child) {
|
|
188
|
+
if (!ctx.serve || deps.noWait) {
|
|
189
|
+
await stopChild(ctx);
|
|
190
|
+
out.line(out.dim(t('local.stopped')));
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
out.line(out.dim(t('local.stop')));
|
|
194
|
+
await new Promise((resolveWait) => {
|
|
195
|
+
let stopping = false;
|
|
196
|
+
const stop = async () => {
|
|
197
|
+
stopping = true;
|
|
198
|
+
await stopChild(ctx);
|
|
199
|
+
out.line(out.dim(t('local.stopped')));
|
|
200
|
+
resolveWait();
|
|
201
|
+
};
|
|
202
|
+
process.once('SIGINT', stop);
|
|
203
|
+
process.once('SIGTERM', stop);
|
|
204
|
+
// dev-local went down on its own (not us): finish as well
|
|
205
|
+
ctx.child.once('exit', () => !stopping && resolveWait());
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
if (ctx?.child)
|
|
212
|
+
await stopChild(ctx);
|
|
213
|
+
if (e.aborted) {
|
|
214
|
+
out.line();
|
|
215
|
+
out.line(t('aborted'));
|
|
216
|
+
return 130;
|
|
217
|
+
}
|
|
218
|
+
printError(out, e, dir);
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const pick = (s) => Object.fromEntries(Object.entries(s).filter(([, v]) => v));
|
|
223
|
+
async function stopChild(ctx) {
|
|
224
|
+
const c = ctx.child;
|
|
225
|
+
if (!c || c.exitCode !== null)
|
|
226
|
+
return;
|
|
227
|
+
await new Promise((r) => {
|
|
228
|
+
const timer = setTimeout(() => {
|
|
229
|
+
try {
|
|
230
|
+
c.kill('SIGKILL');
|
|
231
|
+
}
|
|
232
|
+
catch { }
|
|
233
|
+
r();
|
|
234
|
+
}, 8000);
|
|
235
|
+
c.once('exit', () => {
|
|
236
|
+
clearTimeout(timer);
|
|
237
|
+
r();
|
|
238
|
+
});
|
|
239
|
+
c.kill('SIGTERM');
|
|
240
|
+
});
|
|
241
|
+
ctx.child = null;
|
|
242
|
+
}
|
|
243
|
+
/** ilorb.env (KEY=VALUE lines) of an Ilorb Code template folder; {} when there is none */
|
|
244
|
+
export function readIlorbEnv(dir) {
|
|
245
|
+
const file = join(dir, 'ilorb.env');
|
|
246
|
+
if (!existsSync(file))
|
|
247
|
+
return {};
|
|
248
|
+
const out = {};
|
|
249
|
+
for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
|
|
250
|
+
const m = line.match(/^\s*(ILORB_[A-Z0-9_]+)\s*=\s*(.*?)\s*$/);
|
|
251
|
+
if (m && m[2])
|
|
252
|
+
out[m[1]] = m[2].replace(/^"(.*)"$/, '$1');
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
function loadCredential(dir) {
|
|
257
|
+
if (!existsSync(licensePath(dir)))
|
|
258
|
+
return null;
|
|
259
|
+
try {
|
|
260
|
+
return JSON.parse(readFileSync(licensePath(dir), 'utf8')).credential ?? null;
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function askCredential(flags, env, prompter) {
|
|
267
|
+
let raw = str(flags.license) ?? str(flags['purchase-code']) ?? env.OVERTURE_LICENSE ?? env.ENVATO_PURCHASE_CODE;
|
|
268
|
+
if (!raw) {
|
|
269
|
+
if (!prompter)
|
|
270
|
+
throw new HumanError('license_missing');
|
|
271
|
+
raw = await prompter.text(t('license.ask'), { validate: (v) => (looksLikeLicenseKey(v) || looksLikePurchaseCode(v) ? null : t('err.license_malformed.do')) });
|
|
272
|
+
}
|
|
273
|
+
raw = raw.trim();
|
|
274
|
+
if (looksLikeLicenseKey(raw))
|
|
275
|
+
return { type: 'license', key: raw };
|
|
276
|
+
if (looksLikePurchaseCode(raw))
|
|
277
|
+
return { type: 'envato', purchaseCode: raw.toLowerCase() };
|
|
278
|
+
if (str(flags['purchase-code']) || env.ENVATO_PURCHASE_CODE)
|
|
279
|
+
throw new HumanError('purchase_code_malformed');
|
|
280
|
+
throw new HumanError('license_malformed');
|
|
281
|
+
}
|
|
282
|
+
async function collectAnswers(i) {
|
|
283
|
+
const { flags, env, prompter, out, target, secrets } = i;
|
|
284
|
+
const prev = i.state?.answers ?? null;
|
|
285
|
+
const need = async (field, flag, ask) => {
|
|
286
|
+
if (!prompter)
|
|
287
|
+
throw new HumanError('missing_answer', { field, flag });
|
|
288
|
+
return ask();
|
|
289
|
+
};
|
|
290
|
+
const invalid = (field, value, hint) => new HumanError('invalid_answer', { field, value, hint });
|
|
291
|
+
// name
|
|
292
|
+
let appName = str(flags.name) ?? prev?.appName;
|
|
293
|
+
if (appName && (appName.length < 2 || appName.length > 40))
|
|
294
|
+
throw invalid('--name', appName, t('q.name.invalid'));
|
|
295
|
+
appName ??= await need(t('q.name'), '--name "<nome>"', () => prompter.text(t('q.name'), { validate: (v) => (v.trim().length >= 2 && v.trim().length <= 40 ? null : t('q.name.invalid')) }));
|
|
296
|
+
appName = appName.trim();
|
|
297
|
+
const slug = prev?.slug && prev.appName === appName ? prev.slug : slugify(appName);
|
|
298
|
+
// owner
|
|
299
|
+
let ownerEmail = str(flags['owner-email']) ?? prev?.ownerEmail;
|
|
300
|
+
if (ownerEmail && !EMAIL_RE.test(ownerEmail))
|
|
301
|
+
throw invalid('--owner-email', ownerEmail, t('q.owner.invalid'));
|
|
302
|
+
ownerEmail ??= await need(t('q.owner'), '--owner-email <e-mail>', () => prompter.text(t('q.owner'), { validate: (v) => (EMAIL_RE.test(v.trim()) ? null : t('q.owner.invalid')) }));
|
|
303
|
+
ownerEmail = ownerEmail.trim().toLowerCase();
|
|
304
|
+
// languages
|
|
305
|
+
const parseLangs = (v) => [...new Set(v.split(/[\s,]+/).map((x) => x.trim().toLowerCase()).filter(Boolean))];
|
|
306
|
+
let languages = str(flags.languages) ? parseLangs(str(flags.languages)) : prev?.languages ?? null;
|
|
307
|
+
if (!languages && prompter)
|
|
308
|
+
languages = parseLangs(await prompter.text(t('q.languages'), { default: DEFAULT_LOCALES.join(','), validate: (v) => (parseLangs(v).every((l) => LOCALES.includes(l)) && parseLangs(v).length ? null : t('q.languages.invalid')) }));
|
|
309
|
+
languages ??= [...DEFAULT_LOCALES];
|
|
310
|
+
if (!languages.length || !languages.every((l) => LOCALES.includes(l)))
|
|
311
|
+
throw invalid('--languages', languages.join(','), t('q.languages.invalid'));
|
|
312
|
+
// style + color (samples with the app's engine)
|
|
313
|
+
let preset = str(flags.style) ?? prev?.theme.preset;
|
|
314
|
+
if (preset && !PRESET_IDS.includes(preset))
|
|
315
|
+
throw invalid('--style', preset, PRESET_IDS.join(' | '));
|
|
316
|
+
let primary = str(flags.primary) ?? (prev && prev.theme.preset === preset ? prev.theme.primary : undefined);
|
|
317
|
+
if (primary && !HEX_RE.test(primary))
|
|
318
|
+
throw invalid('--primary', primary, t('q.primary.invalid'));
|
|
319
|
+
if (!preset && prompter) {
|
|
320
|
+
out.line(` ${out.dim(`${' '.repeat(8)}${t('theme.light').padEnd(31)}${t('theme.dark')}`)}`);
|
|
321
|
+
preset = await prompter.select(t('q.style'), PRESET_IDS.map((id) => ({ value: id, label: themeLine(out, { preset: id }, PRESETS[id].label, t('theme.button')) })));
|
|
322
|
+
}
|
|
323
|
+
preset ??= 'clean';
|
|
324
|
+
if (!primary && prompter && !str(flags.style)) {
|
|
325
|
+
const def = PRESETS[preset].primary;
|
|
326
|
+
primary = normalizeHex(await prompter.text(t('q.primary'), { default: def, validate: (v) => (HEX_RE.test(v.trim()) ? null : t('q.primary.invalid')) }));
|
|
327
|
+
}
|
|
328
|
+
const theme = resolveTheme(preset, primary ? normalizeHex(primary) : null);
|
|
329
|
+
if (!prev || prev.theme.primary !== theme.primary || prev.theme.preset !== theme.preset) {
|
|
330
|
+
const rep = primaryReport(theme);
|
|
331
|
+
out.line(` ${themeLine(out, theme, PRESETS[preset].label, t('theme.button'))}`);
|
|
332
|
+
out.line(` ${out.dim(rep.adjusted ? t('q.primary.adjusted', { from: theme.primary, to: rep.light, ratio: rep.ratioLight, dark: rep.dark }) : t('q.primary.kept', { ratio: rep.ratioLight }))}`);
|
|
333
|
+
}
|
|
334
|
+
// bundle id (derived; only changes with --bundle-id). Product without an app (Widgets): does not exist
|
|
335
|
+
let bundleId = null;
|
|
336
|
+
if (i.product.app) {
|
|
337
|
+
bundleId = str(flags['bundle-id']) ?? (prev && prev.slug === slug && prev.bundleId ? prev.bundleId : suggestBundleId(ownerEmail, slug));
|
|
338
|
+
if (!BUNDLE_RE.test(bundleId))
|
|
339
|
+
throw invalid('--bundle-id', bundleId, 'com.empresa.app');
|
|
340
|
+
}
|
|
341
|
+
// Cloudflare (the account is chosen in the account step, after login)
|
|
342
|
+
const accountId = str(flags['account-id']) ?? i.env.CLOUDFLARE_ACCOUNT_ID ?? prev?.cloudflare.accountId ?? null;
|
|
343
|
+
// Opera. Cloud: the production app (or "I'll set it up later" in the panel). Local: the buyer's TEST app is REQUIRED
|
|
344
|
+
// in the cloud Opera — the Opera chat server is not in the package. Without the keys, the "local.opera" step stops and explains.
|
|
345
|
+
// Product without Opera (Status): neither asks nor stores an Opera key.
|
|
346
|
+
// Optional Ilorb chat (Classificados): the key is TAKEN when given (ilorb.env / flag + env), never asked nor required.
|
|
347
|
+
const usesOpera = i.product.opera;
|
|
348
|
+
const takesKey = usesOpera || !!i.product.ilorbOptional;
|
|
349
|
+
let operaAppId = takesKey ? str(flags['opera-app-id']) ?? prev?.opera.appId ?? null : null;
|
|
350
|
+
if (takesKey && env.OPERA_APP_SECRET)
|
|
351
|
+
secrets.OPERA_APP_SECRET = env.OPERA_APP_SECRET;
|
|
352
|
+
if (usesOpera && env.OPERA_CALLBACK_SECRET)
|
|
353
|
+
secrets.OPERA_CALLBACK_SECRET = env.OPERA_CALLBACK_SECRET;
|
|
354
|
+
const askOpera = !usesOpera ? false : target === 'cloud' ? !operaAppId && !flags['skip-opera'] && !prev : !operaAppId || !secrets.OPERA_APP_SECRET;
|
|
355
|
+
if (askOpera) {
|
|
356
|
+
if (prompter) {
|
|
357
|
+
out.line();
|
|
358
|
+
if (target === 'local')
|
|
359
|
+
out.line(` ${out.dim(t(i.product.app ? 'q.opera.localHint' : 'q.opera.localHint.site', { product: i.product.name.replace(/^Overture /, '') }))}`);
|
|
360
|
+
const now = await prompter.select(target === 'local' ? t('q.opera.local') : t('q.opera'), [{ value: true, label: t('q.opera.now') }, { value: false, label: target === 'local' ? t('q.opera.localLater') : t('q.opera.later') }], 0);
|
|
361
|
+
if (now) {
|
|
362
|
+
operaAppId = (await prompter.text(t('q.opera.appId'), { default: operaAppId ?? undefined, validate: (v) => (/^app_[A-Za-z0-9_-]{4,}$/.test(v.trim()) ? null : 'app_…') })).trim();
|
|
363
|
+
secrets.OPERA_APP_SECRET = await prompter.secret(t('q.opera.secret'));
|
|
364
|
+
const cb = await prompter.secret(t('q.opera.callback'), { allowEmpty: true });
|
|
365
|
+
if (cb)
|
|
366
|
+
secrets.OPERA_CALLBACK_SECRET = cb;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (operaAppId && !/^app_[A-Za-z0-9_-]{4,}$/.test(operaAppId))
|
|
371
|
+
throw invalid('--opera-app-id', operaAppId, 'app_…');
|
|
372
|
+
// optional product secrets (Sites: TURNSTILE_SECRET) — only through the environment, never through a flag
|
|
373
|
+
for (const k of i.product.envSecrets ?? [])
|
|
374
|
+
if (env[k])
|
|
375
|
+
secrets[k] = env[k];
|
|
376
|
+
// code email (cloud only; local shows the code on screen)
|
|
377
|
+
let emailFrom = str(flags['email-from']) ?? prev?.email.from ?? null;
|
|
378
|
+
if (env.RESEND_API_KEY)
|
|
379
|
+
secrets.RESEND_API_KEY = env.RESEND_API_KEY;
|
|
380
|
+
if (target === 'cloud' && !emailFrom && !flags['skip-email'] && !prev && prompter) {
|
|
381
|
+
const now = await prompter.select(t('q.email'), [{ value: true, label: t('q.email.now') }, { value: false, label: t('q.email.later') }], 0);
|
|
382
|
+
if (now) {
|
|
383
|
+
secrets.RESEND_API_KEY = await prompter.secret(t('q.email.key'));
|
|
384
|
+
emailFrom = (await prompter.text(t('q.email.from'), { default: `${appName} <login@${ownerEmail.split('@')[1]}>` })).trim();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
// Resend key without a sender (--yes): uses the owner's domain — the buyer changes it in the panel
|
|
388
|
+
if (target === 'cloud' && secrets.RESEND_API_KEY && !emailFrom)
|
|
389
|
+
emailFrom = `${appName} <login@${ownerEmail.split('@')[1]}>`;
|
|
390
|
+
if (target === 'local')
|
|
391
|
+
emailFrom = null;
|
|
392
|
+
// own domain (only products with customDomain: the Status page). Optional: without it, stays on workers.dev
|
|
393
|
+
let domain = null;
|
|
394
|
+
if (i.product.customDomain) {
|
|
395
|
+
const flag = i.product.domainFlag ?? 'status-domain';
|
|
396
|
+
const raw = str(flags[flag]) ?? prev?.domain ?? null;
|
|
397
|
+
domain = raw ? raw.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/\/+$/, '') : null;
|
|
398
|
+
if (domain && !DOMAIN_RE.test(domain))
|
|
399
|
+
throw invalid(`--${flag}`, raw, t('q.domain.invalid'));
|
|
400
|
+
if (target === 'local')
|
|
401
|
+
domain = null;
|
|
402
|
+
}
|
|
403
|
+
// paid Workers plan (Link: turns on the click queue). --workers-paid / --no-workers-paid; default: no. Cloud only.
|
|
404
|
+
let workersPaid;
|
|
405
|
+
if (i.product.paidQueue) {
|
|
406
|
+
const f = flags['workers-paid'];
|
|
407
|
+
workersPaid = typeof f === 'boolean' ? f : prev?.workersPaid ?? undefined;
|
|
408
|
+
if (workersPaid === undefined && target === 'cloud' && prompter) {
|
|
409
|
+
workersPaid = await prompter.select(t('q.workersPaid'), [{ value: false, label: t('q.workersPaid.no') }, { value: true, label: t('q.workersPaid.yes') }], 0);
|
|
410
|
+
}
|
|
411
|
+
workersPaid = target === 'cloud' ? !!workersPaid : false;
|
|
412
|
+
}
|
|
413
|
+
// sample data (Quiz: questions). --sample-data / --no-sample-data; default: yes locally, no in the cloud
|
|
414
|
+
let sampleData;
|
|
415
|
+
if (i.product.sampleImport) {
|
|
416
|
+
const f = flags['sample-data'];
|
|
417
|
+
sampleData = typeof f === 'boolean' ? f : prev?.sampleData ?? undefined;
|
|
418
|
+
if (sampleData === undefined && prompter)
|
|
419
|
+
sampleData = await prompter.confirm(t('q.sampleData'), target === 'local');
|
|
420
|
+
sampleData ??= target === 'local';
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
product: i.product.id,
|
|
424
|
+
target,
|
|
425
|
+
appName,
|
|
426
|
+
slug,
|
|
427
|
+
ownerEmail,
|
|
428
|
+
languages: languages,
|
|
429
|
+
theme,
|
|
430
|
+
bundleId,
|
|
431
|
+
cloudflare: { accountId, accountName: prev?.cloudflare.accountName ?? null },
|
|
432
|
+
opera: { appId: operaAppId },
|
|
433
|
+
email: { from: emailFrom },
|
|
434
|
+
...(i.product.customDomain ? { domain } : {}),
|
|
435
|
+
...(i.product.paidQueue ? { workersPaid } : {}),
|
|
436
|
+
...(i.product.sampleImport ? { sampleData } : {}),
|
|
437
|
+
license: i.credential ? { type: i.credential.type, masked: maskCredential(i.credential.type === 'license' ? i.credential.key : i.credential.purchaseCode) } : null,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function printSummary(out, a, dir) {
|
|
441
|
+
out.line();
|
|
442
|
+
out.line(` ${out.bold(t('q.summary'))}`);
|
|
443
|
+
const row = (k, v) => out.line(` ${out.dim(k.padEnd(16))} ${v}`);
|
|
444
|
+
row(t('sum.product'), PRODUCTS[a.product]?.name ?? a.product);
|
|
445
|
+
row(t('sum.app'), `${a.appName} ${out.dim(`(${a.slug})`)}`);
|
|
446
|
+
row(t('sum.owner'), a.ownerEmail);
|
|
447
|
+
row(t('sum.languages'), a.languages.join(', '));
|
|
448
|
+
row(t('sum.style'), `${PRESETS[a.theme.preset].label} · ${a.theme.primary}`);
|
|
449
|
+
if (a.bundleId)
|
|
450
|
+
row(t('sum.bundle'), a.bundleId);
|
|
451
|
+
row(t('sum.folder'), dir);
|
|
452
|
+
row(t('sum.target'), a.target === 'cloud' ? t('sum.target.cloud') : t('sum.target.local'));
|
|
453
|
+
if (PRODUCTS[a.product]?.opera !== false)
|
|
454
|
+
row(t('sum.opera'), a.opera.appId ? `${a.opera.appId}${a.target === 'local' ? ` ${out.dim(t('sum.opera.test'))}` : ''}` : t('sum.opera.skip'));
|
|
455
|
+
if (a.target === 'cloud')
|
|
456
|
+
row(t('sum.email'), a.email.from ?? t('sum.email.skip'));
|
|
457
|
+
if (a.target === 'cloud' && PRODUCTS[a.product]?.customDomain)
|
|
458
|
+
row(t('sum.domain'), a.domain ?? t('sum.domain.skip'));
|
|
459
|
+
if (a.target === 'cloud' && PRODUCTS[a.product]?.paidQueue)
|
|
460
|
+
row(t('sum.workersPaid'), a.workersPaid ? t('sum.workersPaid.yes') : t('sum.workersPaid.no'));
|
|
461
|
+
out.line();
|
|
462
|
+
}
|
|
463
|
+
function printFinal(c) {
|
|
464
|
+
const { out, answers: a, state } = c;
|
|
465
|
+
const u = state.resources.urls;
|
|
466
|
+
out.line();
|
|
467
|
+
out.line(`${out.green('✔')} ${out.bold(a.target === 'local' ? t('final.local.title', { app: a.appName }) : t('final.title', { app: a.appName }))}`);
|
|
468
|
+
out.line();
|
|
469
|
+
out.line(` ${out.bold(t('final.urls'))}`);
|
|
470
|
+
const row = (k, v) => v && out.line(` ${k.padEnd(28)} ${out.cyan(v)}`);
|
|
471
|
+
row(t('final.admin'), u.admin);
|
|
472
|
+
row(t('final.app'), u.app);
|
|
473
|
+
row(t('final.auth'), u.auth);
|
|
474
|
+
row(t('final.api', { product: c.product.name }), u.api);
|
|
475
|
+
row(t(c.product.id === 'agenda' ? 'final.bookingPage' : 'final.site'), u.site);
|
|
476
|
+
// Status: the public page is the Worker itself (or the own domain)
|
|
477
|
+
if (c.product.id === 'status')
|
|
478
|
+
row(t('final.statusPage'), a.target === 'cloud' && a.domain ? `https://${a.domain}` : u.api);
|
|
479
|
+
if (c.product.id === 'sites')
|
|
480
|
+
row(t('final.siteUrl'), u.api);
|
|
481
|
+
if (a.target === 'local' && c.product.opera)
|
|
482
|
+
row(t('final.opera'), u.opera);
|
|
483
|
+
if (a.target === 'local' && c.product.opera)
|
|
484
|
+
row(t('final.callback'), `${u.api}/v1/opera/callback`);
|
|
485
|
+
out.line();
|
|
486
|
+
// owner's first-access link: signs in to the panel without a code and without an email provider (single use, 15 min)
|
|
487
|
+
if (c.bootstrap?.url) {
|
|
488
|
+
out.line(` ${out.bold(t('final.bootstrap'))}`);
|
|
489
|
+
const mask = c.bootstrap.url.replace(/bootstrap=[^&]+/, 'bootstrap=bst_…');
|
|
490
|
+
out.secretLine(` ${out.cyan(c.bootstrap.url)}`, ` ${mask} (oculto no log)`);
|
|
491
|
+
out.line(` ${out.dim(t('final.bootstrapNote', { email: a.ownerEmail }))}`);
|
|
492
|
+
out.line();
|
|
493
|
+
}
|
|
494
|
+
else if (c.bootstrapError) {
|
|
495
|
+
out.line(` ${out.yellow('!')} ${t('final.bootstrapFailed')}`);
|
|
496
|
+
out.line();
|
|
497
|
+
}
|
|
498
|
+
out.line(` ${out.bold(t('final.next'))}`);
|
|
499
|
+
const n = (s) => out.line(` → ${s}`);
|
|
500
|
+
// local: the code appears on screen (no email) — mentioning Resend here only confuses
|
|
501
|
+
n(t(c.bootstrap?.url ? (a.target === 'local' ? 'final.next.panelLinkLocal' : 'final.next.panelLink') : 'final.next.panel', { email: a.ownerEmail }));
|
|
502
|
+
// Widgets: create the widget in the panel, set the domain and copy the snippet (local: the test page already loads it)
|
|
503
|
+
if (c.product.id === 'widgets')
|
|
504
|
+
n(t(a.target === 'local' ? 'final.next.widgetLocal' : 'final.next.widget', { site: u.site ?? '', host: u.site?.replace(/^https?:\/\//, '') ?? '' }));
|
|
505
|
+
// Consultas: professionals/services in the panel; payments (simulated locally) and the reminders cron
|
|
506
|
+
if (c.product.id === 'consultas')
|
|
507
|
+
n(t(a.target === 'local' ? 'final.next.consultasLocal' : 'final.next.consultas'));
|
|
508
|
+
// Agenda: panel (hours, professionals, services), the booking page + embed.js; payments (simulated locally) and the cron
|
|
509
|
+
// Sites: pick a demo or create the pages and publish (changes instantly, no deploy); own domain is manual
|
|
510
|
+
if (c.product.id === 'sites')
|
|
511
|
+
n(t(a.target === 'local' ? 'final.next.sitesLocal' : 'final.next.sites', { site: u.api ?? '', worker: state.resources.workers.api?.name ?? `${a.slug}-sites` }));
|
|
512
|
+
if (c.product.id === 'starter')
|
|
513
|
+
n(t(a.target === 'local' ? 'final.next.starterLocal' : 'final.next.starter', { app: u.app ?? '' }));
|
|
514
|
+
// Help Center: Email Routing is manual (Cloudflare does not let the installer do it) — it also goes in the generated README
|
|
515
|
+
// Classificados: the 4 steps after installing (INSTALADOR.md) + the site domain (SEO lives off it)
|
|
516
|
+
if (c.product.id === 'classificados') {
|
|
517
|
+
for (const k of ['final.next.cls1', 'final.next.cls2', 'final.next.cls3'])
|
|
518
|
+
n(t(k));
|
|
519
|
+
n(t('final.next.cls4', { site: a.target === 'cloud' && a.domain ? `https://${a.domain}` : u.api ?? '' }));
|
|
520
|
+
if (a.target === 'cloud' && !a.domain)
|
|
521
|
+
n(t('final.next.clsDomain', { worker: state.resources.workers.api?.name ?? `${a.slug}-classificados` }));
|
|
522
|
+
}
|
|
523
|
+
if (c.product.id === 'helpcenter') {
|
|
524
|
+
n(t(a.target === 'local' ? 'final.next.helpcenterLocal' : 'final.next.helpcenter', { api: u.api ?? '' }));
|
|
525
|
+
if (a.target === 'cloud')
|
|
526
|
+
n(t('final.next.helpcenterEmail', { worker: state.resources.workers.api?.name ?? `${a.slug}-helpcenter` }));
|
|
527
|
+
}
|
|
528
|
+
if (c.product.id === 'imoveis')
|
|
529
|
+
n(t(a.target === 'local' ? 'final.next.imoveisLocal' : 'final.next.imoveis', { site: u.api ?? '', app: u.app ?? '' }));
|
|
530
|
+
if (c.product.id === 'quiz')
|
|
531
|
+
n(t(a.target === 'local' ? 'final.next.quizLocal' : 'final.next.quiz', { app: u.app ?? '' }));
|
|
532
|
+
if (c.product.id === 'link') {
|
|
533
|
+
n(t(a.target === 'local' ? 'final.next.linkLocal' : 'final.next.link', { app: u.app ?? '' }));
|
|
534
|
+
if (a.target === 'cloud')
|
|
535
|
+
n(t(a.workersPaid ? 'final.next.linkQueue' : 'final.next.linkNoQueue', { queue: `${a.slug}-link-clicks` }));
|
|
536
|
+
if (a.target === 'cloud' && !a.domain)
|
|
537
|
+
n(t('final.next.linkDomain', { worker: state.resources.workers.api?.name ?? `${a.slug}-link` }));
|
|
538
|
+
}
|
|
539
|
+
if (c.product.id === 'agenda')
|
|
540
|
+
n(t(a.target === 'local' ? 'final.next.agendaLocal' : 'final.next.agenda', { site: u.site ?? '' }));
|
|
541
|
+
// Status: monitors, components and alerts in the panel; the checks cron; the page's own domain
|
|
542
|
+
if (c.product.id === 'status') {
|
|
543
|
+
n(t(a.target === 'local' ? 'final.next.statusLocal' : 'final.next.status', { page: a.target === 'cloud' && a.domain ? `https://${a.domain}` : u.api ?? '' }));
|
|
544
|
+
if (a.target === 'cloud')
|
|
545
|
+
n(a.domain ? t('final.next.statusDomainSet', { domain: a.domain, worker: state.resources.workers.api?.name ?? `${a.slug}-status` }) : t('final.next.statusDomain', { worker: state.resources.workers.api?.name ?? `${a.slug}-status` }));
|
|
546
|
+
}
|
|
547
|
+
// new products: the steps come from the spec (i18n keys; `<key>Local` in local mode when it exists)
|
|
548
|
+
for (const k of c.product.finalNext ?? []) {
|
|
549
|
+
const key = a.target === 'local' && hasMsg(`${k}Local`) ? `${k}Local` : k;
|
|
550
|
+
if (hasMsg(key))
|
|
551
|
+
n(t(key, { site: u.site ?? u.api ?? '', app: u.app ?? '', api: u.api ?? '', admin: u.admin ?? '', worker: state.resources.workers.api?.name ?? `${a.slug}-${c.product.api.suffix}` }));
|
|
552
|
+
}
|
|
553
|
+
if (a.target === 'local') {
|
|
554
|
+
n(t('final.next.localCode'));
|
|
555
|
+
// the cloud Opera cannot reach localhost: push and callback reports need a tunnel or the cloud deploy
|
|
556
|
+
if (c.product.opera)
|
|
557
|
+
n(t('final.next.localCallback', { port: String(state.local?.ports.api ?? '<api>'), path: '/v1/opera/callback' }));
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
if (!c.product.opera) { /* no Opera: nothing to configure */ }
|
|
561
|
+
else if (a.opera.appId)
|
|
562
|
+
n(t('final.next.opera', { url: `${u.api}/v1/opera/callback` }));
|
|
563
|
+
else
|
|
564
|
+
n(t(c.product.id === 'consultas' ? 'final.next.operaSkip.consultas' : c.product.app ? 'final.next.operaSkip' : 'final.next.operaSkip.widgets'));
|
|
565
|
+
if (!a.email.from || !c.secrets.RESEND_API_KEY)
|
|
566
|
+
n(t(c.product.id === 'status' ? 'final.next.emailSkip.status' : 'final.next.emailSkip'));
|
|
567
|
+
if (c.product.app)
|
|
568
|
+
n(t('final.next.eas', { dir: c.product.app.dir }));
|
|
569
|
+
}
|
|
570
|
+
n(t('final.next.secrets'));
|
|
571
|
+
out.line(` ${out.dim(t('final.again'))}`);
|
|
572
|
+
out.line();
|
|
573
|
+
}
|
|
574
|
+
function printError(out, e, dir) {
|
|
575
|
+
const human = isHuman(e) ? e : null;
|
|
576
|
+
out.line();
|
|
577
|
+
out.line(`${out.red('✖')} ${out.bold(human ? human.what() : t('err.unexpected.what', { message: e?.message ?? String(e) }))}`);
|
|
578
|
+
out.line(` ${out.bold(t('err.whatToDo'))}: ${human ? human.todo() : t('err.unexpected.do')}`);
|
|
579
|
+
const detail = human?.detail ?? (human ? undefined : e?.stack);
|
|
580
|
+
if (detail) {
|
|
581
|
+
out.line(` ${out.dim(t('err.details'))}:`);
|
|
582
|
+
for (const l of String(detail).trim().split('\n').slice(-8))
|
|
583
|
+
out.line(` ${out.dim(l)}`);
|
|
584
|
+
out.log(String(detail));
|
|
585
|
+
}
|
|
586
|
+
if (dir && existsSync(join(dir, STATE_DIR, 'install.json'))) {
|
|
587
|
+
out.line(` ${t('err.resume', { cmd: out.cyan(`npx create-ilorb --resume ${shortDir(dir)}`) })}`);
|
|
588
|
+
}
|
|
589
|
+
out.line();
|
|
590
|
+
}
|
|
591
|
+
const shortDir = (dir) => {
|
|
592
|
+
const rel = dir.startsWith(process.cwd() + '/') ? dir.slice(process.cwd().length + 1) : dir;
|
|
593
|
+
return rel.includes(' ') ? `"${rel}"` : rel || basename(dir);
|
|
594
|
+
};
|