@speedkit/cli 4.38.1 → 4.40.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/CHANGELOG.md +21 -0
- package/README.md +10 -1
- package/dist/commands/airports_iata.json +9202 -1
- package/dist/commands/generate-customer-config.d.ts +2 -0
- package/dist/commands/generate-customer-config.js +7 -1
- package/dist/services/customer-config/customer-config-service-build-context.d.ts +8 -0
- package/dist/services/customer-config/customer-config-service-build-context.js +8 -0
- package/dist/services/customer-config/customer-config-service-factory.js +3 -1
- package/dist/services/customer-config/customer-config-service.d.ts +10 -7
- package/dist/services/customer-config/customer-config-service.js +138 -308
- package/dist/services/customer-config/index.d.ts +2 -0
- package/dist/services/customer-config/index.js +2 -0
- package/dist/services/customer-config/spec/wizard-answers.spec.d.ts +1 -0
- package/dist/services/customer-config/spec/wizard-answers.spec.js +207 -0
- package/dist/services/customer-config/wizard-answers.d.ts +48 -0
- package/dist/services/customer-config/wizard-answers.js +67 -0
- package/dist/services/customer-config/wizard-questions.d.ts +86 -0
- package/dist/services/customer-config/wizard-questions.js +400 -0
- package/dist/services/document-handler-runtime/document-handler-abort.d.ts +44 -0
- package/dist/services/document-handler-runtime/document-handler-abort.js +48 -0
- package/dist/services/document-handler-runtime/document-handler-console.d.ts +45 -0
- package/dist/services/document-handler-runtime/document-handler-console.js +81 -0
- package/dist/services/document-handler-runtime/document-handler-server.js +3 -23
- package/dist/services/document-handler-runtime/spec/document-handler-abort.spec.js +57 -1
- package/dist/services/document-handler-runtime/spec/document-handler-console.spec.d.ts +1 -0
- package/dist/services/document-handler-runtime/spec/document-handler-console.spec.js +97 -0
- package/dist/services/onboarding/error/document-handler-transform-error.d.ts +2 -0
- package/dist/services/onboarding/error/document-handler-transform-error.js +3 -0
- package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -0
- package/dist/services/onboarding/virtual-orestes-app/index.js +27 -2
- package/dist/templates/speedKit.Revalidated.js +5 -1
- package/oclif.manifest.json +98 -83
- package/package.json +1 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import { DirectoryOverwriteOption,
|
|
3
|
+
import { DirectoryOverwriteOption, TEMPLATE_VARIABLES, } from "./customer-config-service-model.js";
|
|
4
4
|
import { findUnknownVariables, resolveTemplateSource, } from "./template-source.js";
|
|
5
|
+
import { WizardAnswerSource } from "./wizard-answers.js";
|
|
6
|
+
import { applicableChoices, conditionHolds, resolveDefault, settingsFromAnswers, validateAnswer, WIZARD_QUESTIONS, } from "./wizard-questions.js";
|
|
5
7
|
export class CustomerConfigService {
|
|
6
8
|
context;
|
|
7
9
|
siteAnalyzer;
|
|
10
|
+
answers;
|
|
8
11
|
cli;
|
|
9
12
|
_appName;
|
|
10
13
|
_outputDirPath;
|
|
@@ -23,9 +26,10 @@ export class CustomerConfigService {
|
|
|
23
26
|
}
|
|
24
27
|
/** Set from the "Downtime Detection" feature answer in the wizard. */
|
|
25
28
|
includeDowntimeDetection = false;
|
|
26
|
-
constructor(context, cli, siteAnalyzer) {
|
|
29
|
+
constructor(context, cli, siteAnalyzer, answers = new WizardAnswerSource()) {
|
|
27
30
|
this.context = context;
|
|
28
31
|
this.siteAnalyzer = siteAnalyzer;
|
|
32
|
+
this.answers = answers;
|
|
29
33
|
const { appName } = this.context;
|
|
30
34
|
this.appName = appName;
|
|
31
35
|
this.cli = cli;
|
|
@@ -54,18 +58,11 @@ export class CustomerConfigService {
|
|
|
54
58
|
else {
|
|
55
59
|
proposedNewDirectoryName = `${directoryName}-2`;
|
|
56
60
|
}
|
|
57
|
-
const newDirectoryName = await this.cli.prompt(`Please enter new output directory name:`, {
|
|
61
|
+
const newDirectoryName = await this.answers.get("newDirectoryName", () => this.cli.prompt(`Please enter new output directory name:`, {
|
|
58
62
|
defaultAnswer: proposedNewDirectoryName,
|
|
59
|
-
});
|
|
63
|
+
}), proposedNewDirectoryName);
|
|
60
64
|
return this.selectOutputDirectory(this.getPathWithChangedDir(directoryPath, newDirectoryName));
|
|
61
65
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Japanese customers sign off every rollout themselves, so the approval flag
|
|
64
|
-
* is preselected for them. A `.jp` host is the signal we have at this point.
|
|
65
|
-
*/
|
|
66
|
-
isJapaneseHost(host) {
|
|
67
|
-
return /\.jp$/i.test(host.trim().replace(/\/.*$/, ""));
|
|
68
|
-
}
|
|
69
66
|
/** A pre-PoC config marks itself via splitTestId "pre_poc" in config_SpeedKit.js. */
|
|
70
67
|
isPrePocConfig(directoryPath) {
|
|
71
68
|
const speedKitConfigPath = path.join(directoryPath, "config_SpeedKit.js");
|
|
@@ -94,7 +91,7 @@ export class CustomerConfigService {
|
|
|
94
91
|
"On continue, its config_* files are renamed to *_pre-poc and the full " +
|
|
95
92
|
"config is scaffolded next to them. Merge the verified trackers into the " +
|
|
96
93
|
"new config_loadHandler.js afterwards, then delete the *_pre-poc files.\n");
|
|
97
|
-
const graduate = await this.cli.confirm("Rename the pre-PoC files and continue?");
|
|
94
|
+
const graduate = await this.answers.get("graduatePrePoc", () => this.cli.confirm("Rename the pre-PoC files and continue?"));
|
|
98
95
|
if (graduate) {
|
|
99
96
|
this.renamePrePocFiles(directoryPath);
|
|
100
97
|
return directoryPath;
|
|
@@ -104,10 +101,22 @@ export class CustomerConfigService {
|
|
|
104
101
|
// protect output directory if already existing and not empty:
|
|
105
102
|
if (this.isDirNotEmpty(directoryPath)) {
|
|
106
103
|
this.cli.spacer();
|
|
107
|
-
const
|
|
108
|
-
name:
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
const answerOptions = {
|
|
105
|
+
"new-name": DirectoryOverwriteOption.NEW_NAME,
|
|
106
|
+
"overwrite-file-wise": DirectoryOverwriteOption.OVERWRITE_FILE_WISE,
|
|
107
|
+
empty: DirectoryOverwriteOption.OVERWRITE_COMPLETELY,
|
|
108
|
+
};
|
|
109
|
+
const answer = await this.answers.get("existingDirectory", async () => {
|
|
110
|
+
const option = await this.cli.select(`Output directory ${directoryPath} is not empty. How to proceed?`, Object.values(DirectoryOverwriteOption).map((value) => ({
|
|
111
|
+
name: value,
|
|
112
|
+
value,
|
|
113
|
+
})));
|
|
114
|
+
return Object.entries(answerOptions).find(([, value]) => value === option)[0];
|
|
115
|
+
});
|
|
116
|
+
const selectedDirectoryOverwriteOption = answerOptions[answer];
|
|
117
|
+
if (!selectedDirectoryOverwriteOption) {
|
|
118
|
+
throw new Error(`Unknown existingDirectory "${answer}". Use one of: ${Object.keys(answerOptions).join(", ")}.`);
|
|
119
|
+
}
|
|
111
120
|
switch (selectedDirectoryOverwriteOption) {
|
|
112
121
|
case DirectoryOverwriteOption.OVERWRITE_COMPLETELY: {
|
|
113
122
|
fs.rmSync(directoryPath, { recursive: true, force: true });
|
|
@@ -158,318 +167,132 @@ export class CustomerConfigService {
|
|
|
158
167
|
}
|
|
159
168
|
this.cli.spacer();
|
|
160
169
|
}
|
|
161
|
-
async getEnvironmentConfig(environmentType, defaultHost) {
|
|
162
|
-
const label = environmentType.charAt(0).toUpperCase() + environmentType.slice(1);
|
|
163
|
-
const host = await this.cli.prompt(`[${label}] Enter ${label.toLowerCase()} host (without https://):`, {
|
|
164
|
-
defaultAnswer: defaultHost,
|
|
165
|
-
});
|
|
166
|
-
const forceInstall = !(await this.cli.confirm(`[${label}] Is the install.js already present?`, false));
|
|
167
|
-
return {
|
|
168
|
-
host,
|
|
169
|
-
forceInstall,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
170
|
async shouldFileBeOverwritten(outputFilePath) {
|
|
173
171
|
if (fs.existsSync(outputFilePath)) {
|
|
174
|
-
const overwrite = await this.cli.confirm(`File ${path.basename(outputFilePath)} already exists. Overwrite?`);
|
|
172
|
+
const overwrite = await this.answers.get("overwriteExistingFiles", () => this.cli.confirm(`File ${path.basename(outputFilePath)} already exists. Overwrite?`));
|
|
175
173
|
if (!overwrite)
|
|
176
174
|
return false;
|
|
177
175
|
}
|
|
178
176
|
return true;
|
|
179
177
|
}
|
|
180
178
|
async getConfigSettings() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
defaultAnswer: this.appName,
|
|
187
|
-
});
|
|
188
|
-
this.cli.spacer();
|
|
189
|
-
// 1. Production host (needed for site analysis)
|
|
190
|
-
const productionHost = await this.cli.prompt(`[Production] Enter production host (without https://):`, { defaultAnswer: `www.${this.appName}.de` });
|
|
191
|
-
this.cli.spacer();
|
|
192
|
-
// 2. Site analysis (informs shop system, install.js, and feature defaults)
|
|
193
|
-
let siteAnalysis = null;
|
|
194
|
-
const shouldAnalyze = await this.cli.confirm("[Analysis] Analyze production site to auto-detect settings?", true);
|
|
195
|
-
if (shouldAnalyze) {
|
|
196
|
-
this.cli.startAction("ANALYSE:CUSTOMER:CONFIG", `Analyzing https://${productionHost}`);
|
|
197
|
-
siteAnalysis = await this.siteAnalyzer.analyze(productionHost);
|
|
198
|
-
if (siteAnalysis) {
|
|
199
|
-
this.cli.successAction("ANALYSE:CUSTOMER:CONFIG");
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
this.cli.endAction("ANALYSE:CUSTOMER:CONFIG", "Could not analyze site — using defaults.");
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
this.cli.spacer();
|
|
206
|
-
// 3. Shop system
|
|
207
|
-
const detectedShopMap = {
|
|
208
|
-
shopify: ShopSystem.SHOPIFY,
|
|
209
|
-
shopware: ShopSystem.SHOPWARE,
|
|
210
|
-
salesforce: ShopSystem.SALESFORCE,
|
|
211
|
-
oxid: ShopSystem.OXID,
|
|
212
|
-
plentymarkets: ShopSystem.PLENTYMARKETS,
|
|
213
|
-
magento: ShopSystem.MAGENTO,
|
|
214
|
-
woocommerce: ShopSystem.WOOCOMMERCE,
|
|
215
|
-
bigcommerce: ShopSystem.BIGCOMMERCE,
|
|
216
|
-
prestashop: ShopSystem.PRESTASHOP,
|
|
217
|
-
jtl: ShopSystem.JTL,
|
|
218
|
-
commercetools: ShopSystem.COMMERCETOOLS,
|
|
219
|
-
spryker: ShopSystem.SPRYKER,
|
|
220
|
-
shoptet: ShopSystem.SHOPTET,
|
|
221
|
-
ecforce: ShopSystem.ECFORCE,
|
|
222
|
-
futureshop: ShopSystem.FUTURESHOP,
|
|
179
|
+
const context = {
|
|
180
|
+
answers: {},
|
|
181
|
+
analysis: null,
|
|
182
|
+
appName: this.appName,
|
|
183
|
+
mode: this.context.mode,
|
|
223
184
|
};
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
else {
|
|
233
|
-
if (siteAnalysis) {
|
|
234
|
-
this.cli.comment("[Shop System] Could not detect shop system from site.");
|
|
235
|
-
}
|
|
236
|
-
selectedShopSystem = await this.cli.select("[Shop System] Which shop system is in use?", [
|
|
237
|
-
ShopSystem.SHOPIFY,
|
|
238
|
-
ShopSystem.SHOPWARE,
|
|
239
|
-
ShopSystem.SALESFORCE,
|
|
240
|
-
ShopSystem.OXID,
|
|
241
|
-
ShopSystem.PLENTYMARKETS,
|
|
242
|
-
ShopSystem.OTHER,
|
|
243
|
-
].map((option) => ({ name: option, value: option })));
|
|
244
|
-
}
|
|
245
|
-
this.cli.spacer();
|
|
246
|
-
switch (selectedShopSystem) {
|
|
247
|
-
case ShopSystem.SHOPIFY: {
|
|
248
|
-
isShopify = true;
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
case ShopSystem.SHOPWARE: {
|
|
252
|
-
isShopware = true;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
case ShopSystem.SALESFORCE: {
|
|
256
|
-
isSalesforce = true;
|
|
257
|
-
break;
|
|
185
|
+
for (const question of WIZARD_QUESTIONS) {
|
|
186
|
+
if (question.phase !== "settings")
|
|
187
|
+
continue;
|
|
188
|
+
if (!conditionHolds(question.when, context.answers, context.mode)) {
|
|
189
|
+
if (this.answers.has(question.key)) {
|
|
190
|
+
this.cli.writeWarning(`The answers file sets "${question.key}", but the question does not apply here — ignored.`);
|
|
191
|
+
}
|
|
192
|
+
continue;
|
|
258
193
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
194
|
+
const value = await this.answerQuestion(question, context);
|
|
195
|
+
context.answers[question.key] = value;
|
|
196
|
+
if (question.key === "appName") {
|
|
197
|
+
this.appName = value;
|
|
262
198
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
break;
|
|
199
|
+
if (question.key === "analyzeSite" && value) {
|
|
200
|
+
context.analysis = await this.analyzeSite(context.answers.productionHost);
|
|
266
201
|
}
|
|
267
202
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
203
|
+
return settingsFromAnswers(context.answers, context.mode);
|
|
204
|
+
}
|
|
205
|
+
/** Takes the answer from the answers file, or asks it; then checks and records it. */
|
|
206
|
+
async answerQuestion(question, context) {
|
|
207
|
+
const defaultValue = resolveDefault(question, question.default, context);
|
|
208
|
+
let value;
|
|
209
|
+
if (this.answers.active) {
|
|
210
|
+
value = this.answers.has(question.key)
|
|
211
|
+
? this.answers.provided(question.key)
|
|
212
|
+
: defaultValue;
|
|
213
|
+
if (value === undefined) {
|
|
214
|
+
throw new Error(`The answers file has no "${question.key}", and this question has no default.`);
|
|
278
215
|
}
|
|
279
|
-
this.cli.spacer();
|
|
280
|
-
}
|
|
281
|
-
// 6. Customer approval. Its own question rather than a feature toggle: it
|
|
282
|
-
// decides whether sk deploy may ever activate a rollout unattended, which
|
|
283
|
-
// is too easy to miss in a multi-select. The question is the same for every
|
|
284
|
-
// customer — only the default answer follows the domain.
|
|
285
|
-
const needsCustomerApproval = await this.cli.confirm("[Approval] Must the customer approve a change before it may be activated?", this.isJapaneseHost(productionHost));
|
|
286
|
-
this.cli.spacer();
|
|
287
|
-
// Pre-PoC: the tracking-only set uses no acceleration answers — stop asking here.
|
|
288
|
-
if (this.context.mode === "pre-poc") {
|
|
289
|
-
return {
|
|
290
|
-
appName: this.appName,
|
|
291
|
-
production,
|
|
292
|
-
staging,
|
|
293
|
-
needsCustomerApproval,
|
|
294
|
-
shopSystemName: selectedShopSystem === ShopSystem.OTHER
|
|
295
|
-
? undefined
|
|
296
|
-
: selectedShopSystem,
|
|
297
|
-
isShopify,
|
|
298
|
-
isShopware,
|
|
299
|
-
isSalesforce,
|
|
300
|
-
isOxid,
|
|
301
|
-
isPlentymarkets,
|
|
302
|
-
};
|
|
303
216
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (siteAnalysis[feature])
|
|
308
|
-
return { label: " (detected)", checked: true };
|
|
309
|
-
return { label: " (not detected)", checked: fallback };
|
|
310
|
-
};
|
|
311
|
-
const lazyLoading = resolve("removeLazyLoading", true);
|
|
312
|
-
const softNav = resolve("hasSoftNavigations", false);
|
|
313
|
-
const serviceWorker = resolve("includeServiceWorker", false);
|
|
314
|
-
const gaTracking = resolve("useGATracking", true);
|
|
315
|
-
const googleOptimize = resolve("withGoogleOptimize", false);
|
|
316
|
-
const cfRocketLoader = resolve("activateCfRocketLoaderPlugin", false);
|
|
317
|
-
const usercentrics = resolve("handleUsercentrics", false);
|
|
318
|
-
// Detectable features — sorted detected-first when analysis is available
|
|
319
|
-
const detectableChoices = [
|
|
320
|
-
{
|
|
321
|
-
name: `Lazy-Loading Removal / Preloading${lazyLoading.label}`,
|
|
322
|
-
value: "removeLazyLoading",
|
|
323
|
-
checked: lazyLoading.checked,
|
|
324
|
-
description: "Remove lazy-loading attributes and preload critical resources",
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
name: `Soft Navigation Tracking${softNav.label}`,
|
|
328
|
-
value: "hasSoftNavigations",
|
|
329
|
-
checked: softNav.checked,
|
|
330
|
-
description: "Track SPA route changes (Next.js, Nuxt, Vue/React Router)",
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
name: `Include existing Service Worker${serviceWorker.label}`,
|
|
334
|
-
value: "includeServiceWorker",
|
|
335
|
-
checked: serviceWorker.checked,
|
|
336
|
-
description: "Merge customer's existing Service Worker with Speed Kit's",
|
|
337
|
-
},
|
|
338
|
-
...(isShopify
|
|
339
|
-
? []
|
|
340
|
-
: [
|
|
341
|
-
{
|
|
342
|
-
name: `GA DataLayer Tracking${gaTracking.label}`,
|
|
343
|
-
value: "useGATracking",
|
|
344
|
-
checked: gaTracking.checked,
|
|
345
|
-
description: "Forward dataLayer events through Speed Kit",
|
|
346
|
-
},
|
|
347
|
-
]),
|
|
348
|
-
{
|
|
349
|
-
name: `Google Optimize Support${googleOptimize.label}`,
|
|
350
|
-
value: "withGoogleOptimize",
|
|
351
|
-
checked: googleOptimize.checked,
|
|
352
|
-
description: "Ensure compatibility with Google Optimize experiments",
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
name: `Cloudflare Rocket Loader Plugin${cfRocketLoader.label}`,
|
|
356
|
-
value: "activateCfRocketLoaderPlugin",
|
|
357
|
-
checked: cfRocketLoader.checked,
|
|
358
|
-
description: "Handle Cloudflare Rocket Loader script deferral",
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
name: `Usercentrics Handling${usercentrics.label}`,
|
|
362
|
-
value: "handleUsercentrics",
|
|
363
|
-
checked: usercentrics.checked,
|
|
364
|
-
description: "Set handleUsercentrics: true in DH Config — declares uc-block.bundle.js (Usercentrics CMP) as safe script",
|
|
365
|
-
},
|
|
366
|
-
];
|
|
367
|
-
if (siteAnalysis) {
|
|
368
|
-
const detectionRank = (name) => {
|
|
369
|
-
if (name.includes("(detected)"))
|
|
370
|
-
return 0;
|
|
371
|
-
if (name.includes("(not detected)"))
|
|
372
|
-
return 1;
|
|
373
|
-
return 2;
|
|
374
|
-
};
|
|
375
|
-
detectableChoices.sort((a, b) => detectionRank(a.name) - detectionRank(b.name));
|
|
217
|
+
else if (question.skipPromptWhenDefaulted && defaultValue !== undefined) {
|
|
218
|
+
this.cli.comment(`${question.prompt} Detected: ${String(defaultValue)}`);
|
|
219
|
+
value = defaultValue;
|
|
376
220
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
{
|
|
380
|
-
name: "Disabled Sites approach",
|
|
381
|
-
value: "useDisabledSitesApproach",
|
|
382
|
-
description: "Use when URL structure makes page type identification hard",
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
name: "Image Optimisation",
|
|
386
|
-
value: "activateImageOptimisation",
|
|
387
|
-
description: "Optimize images via Speed Kit (skip if site already uses an image CDN with WebP)",
|
|
388
|
-
},
|
|
389
|
-
{ name: "Server-Side Rendering (SSR)", value: "addSSR" },
|
|
390
|
-
{
|
|
391
|
-
name: "Device Detection",
|
|
392
|
-
value: "addDeviceDetection",
|
|
393
|
-
description: "Auto-enabled with SSR",
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
name: "Enhanced PoV Tracking",
|
|
397
|
-
value: "isPOV",
|
|
398
|
-
description: "Extended analytics for Proof of Value engagements",
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
name: "ScrapingBee",
|
|
402
|
-
value: "useScrapingBee",
|
|
403
|
-
description: "Use for geo-location-based responses",
|
|
404
|
-
},
|
|
405
|
-
{ name: "Downtime Detection", value: "addDowntimeDetection" },
|
|
406
|
-
];
|
|
407
|
-
const featureChoices = [
|
|
408
|
-
...detectableChoices,
|
|
409
|
-
...staticChoices,
|
|
410
|
-
];
|
|
411
|
-
const selectedFeatures = await this.cli.multiSelect("[Features] Select features to enable:", featureChoices);
|
|
412
|
-
this.cli.spacer();
|
|
413
|
-
const has = (feature) => selectedFeatures.includes(feature);
|
|
414
|
-
const useDisabledSitesApproach = has("useDisabledSitesApproach");
|
|
415
|
-
const activateImageOptimisation = has("activateImageOptimisation");
|
|
416
|
-
const removeLazyLoading = has("removeLazyLoading");
|
|
417
|
-
const addSSR = has("addSSR");
|
|
418
|
-
// SSR always implies device detection
|
|
419
|
-
const addDeviceDetection = addSSR || has("addDeviceDetection");
|
|
420
|
-
const hasSoftNavigations = has("hasSoftNavigations");
|
|
421
|
-
const useGATracking = has("useGATracking");
|
|
422
|
-
const isPOV = has("isPOV");
|
|
423
|
-
const withGoogleOptimize = has("withGoogleOptimize");
|
|
424
|
-
const activateCfRocketLoaderPlugin = has("activateCfRocketLoaderPlugin");
|
|
425
|
-
const handleUsercentrics = has("handleUsercentrics");
|
|
426
|
-
const useScrapingBee = has("useScrapingBee");
|
|
427
|
-
const addDowntimeDetection = has("addDowntimeDetection");
|
|
428
|
-
// Follow-up questions for features that need additional input
|
|
429
|
-
if (has("includeServiceWorker")) {
|
|
430
|
-
includeServiceWorker = await this.cli.prompt("[Service Worker] Enter path of Service Worker to be included:", { defaultAnswer: "/sw.js" });
|
|
221
|
+
else {
|
|
222
|
+
value = await this.ask(question, defaultValue, context);
|
|
431
223
|
this.cli.spacer();
|
|
432
224
|
}
|
|
433
|
-
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
this.cli.spacer();
|
|
225
|
+
const problem = validateAnswer(question, value, context);
|
|
226
|
+
if (problem) {
|
|
227
|
+
throw new Error(problem);
|
|
437
228
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
229
|
+
this.answers.record(question.key, value);
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
/** The interactive prompt of one question. */
|
|
233
|
+
async ask(question, defaultValue, context) {
|
|
234
|
+
const detected = (choiceDefault) => context.analysis &&
|
|
235
|
+
typeof choiceDefault === "object" &&
|
|
236
|
+
choiceDefault !== null &&
|
|
237
|
+
"fromAnalysis" in choiceDefault
|
|
238
|
+
? context.analysis[choiceDefault.fromAnalysis]
|
|
239
|
+
? " (detected)"
|
|
240
|
+
: " (not detected)"
|
|
241
|
+
: "";
|
|
242
|
+
switch (question.type) {
|
|
243
|
+
case "string":
|
|
244
|
+
return this.cli.prompt(question.prompt, {
|
|
245
|
+
defaultAnswer: defaultValue ?? question.suggestion?.replace("<app>", this.appName),
|
|
246
|
+
validator: (input) => validateAnswer(question, input, context) ? "invalid input" : "",
|
|
247
|
+
});
|
|
248
|
+
case "boolean":
|
|
249
|
+
return this.cli.confirm(`${question.prompt}${detected(question.default).replace(" (not detected)", "")}`, Boolean(defaultValue));
|
|
250
|
+
case "select":
|
|
251
|
+
if (question.skipPromptWhenDefaulted && context.analysis) {
|
|
252
|
+
this.cli.comment(`${question.prompt} Could not detect it from the site.`);
|
|
253
|
+
}
|
|
254
|
+
return this.cli.select(question.prompt, applicableChoices(question, context).map((choice) => ({
|
|
255
|
+
name: choice.label ?? choice.value,
|
|
256
|
+
value: choice.value,
|
|
257
|
+
})), defaultValue);
|
|
258
|
+
case "multiSelect": {
|
|
259
|
+
const rank = (label) => label === " (detected)" ? 0 : label === " (not detected)" ? 1 : 2;
|
|
260
|
+
const choices = applicableChoices(question, context).map((choice) => ({
|
|
261
|
+
name: `${choice.label ?? choice.value}${detected(choice.default)}`,
|
|
262
|
+
value: choice.value,
|
|
263
|
+
checked: resolveDefault(question, choice.default, context) === true,
|
|
264
|
+
description: choice.description,
|
|
265
|
+
rank: rank(detected(choice.default)),
|
|
266
|
+
}));
|
|
267
|
+
if (context.analysis) {
|
|
268
|
+
choices.sort((a, b) => a.rank - b.rank);
|
|
269
|
+
}
|
|
270
|
+
return this.cli.multiSelect(question.prompt, choices.map(({ rank: _rank, ...choice }) => choice));
|
|
271
|
+
}
|
|
272
|
+
case "object": {
|
|
273
|
+
// Only staging is an object question: a host plus its install.js state.
|
|
274
|
+
if (!(await this.cli.confirm(question.prompt, false))) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
const host = await this.cli.prompt("[Staging] Enter staging host (without https://):", {
|
|
278
|
+
defaultAnswer: (context.answers.productionHost ?? "").replace("www", "staging"),
|
|
279
|
+
});
|
|
280
|
+
const installJsPresent = await this.cli.confirm("[Staging] Is the install.js already present?", false);
|
|
281
|
+
return { host, installJsPresent };
|
|
282
|
+
}
|
|
442
283
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
useGATracking,
|
|
456
|
-
useScrapingBee,
|
|
457
|
-
withGoogleOptimize,
|
|
458
|
-
activateCfRocketLoaderPlugin,
|
|
459
|
-
handleUsercentrics,
|
|
460
|
-
hasSoftNavigations,
|
|
461
|
-
convertSoftToHardNavigations,
|
|
462
|
-
useDisabledSitesApproach,
|
|
463
|
-
shopSystemName,
|
|
464
|
-
isShopify,
|
|
465
|
-
isShopware,
|
|
466
|
-
isSalesforce,
|
|
467
|
-
isOxid,
|
|
468
|
-
isPlentymarkets,
|
|
469
|
-
isPOV,
|
|
470
|
-
addDowntimeDetection,
|
|
471
|
-
needsCustomerApproval,
|
|
472
|
-
};
|
|
284
|
+
}
|
|
285
|
+
async analyzeSite(host) {
|
|
286
|
+
this.cli.startAction("ANALYSE:CUSTOMER:CONFIG", `Analyzing https://${host}`);
|
|
287
|
+
const analysis = await this.siteAnalyzer.analyze(host);
|
|
288
|
+
if (analysis) {
|
|
289
|
+
this.cli.successAction("ANALYSE:CUSTOMER:CONFIG");
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
this.cli.endAction("ANALYSE:CUSTOMER:CONFIG", "Could not analyze site — using defaults.");
|
|
293
|
+
}
|
|
294
|
+
this.cli.spacer();
|
|
295
|
+
return analysis;
|
|
473
296
|
}
|
|
474
297
|
async logWarnings(configSettings) {
|
|
475
298
|
if (configSettings.useScrapingBee) {
|
|
@@ -481,12 +304,19 @@ export class CustomerConfigService {
|
|
|
481
304
|
`);
|
|
482
305
|
}
|
|
483
306
|
}
|
|
307
|
+
/** The answers that decide the scaffold; the output-directory answers stay out. */
|
|
308
|
+
settingsAnswers() {
|
|
309
|
+
return Object.fromEntries(Object.entries(this.answers.used).filter(([key]) => WIZARD_QUESTIONS.find((question) => question.key === key)?.phase ===
|
|
310
|
+
"settings"));
|
|
311
|
+
}
|
|
484
312
|
async generateConfig() {
|
|
485
313
|
this.cli.write("\nLet's generate a config...\n");
|
|
486
314
|
const configSettings = await this.getConfigSettings();
|
|
487
315
|
this.includeDowntimeDetection = Boolean(configSettings.addDowntimeDetection);
|
|
488
316
|
await this.compileTemplateFiles(configSettings);
|
|
489
317
|
await this.logWarnings(configSettings);
|
|
318
|
+
this.cli.write(`\nAnswers used — pass them to --answers to repeat this run:\n` +
|
|
319
|
+
`${JSON.stringify(this.settingsAnswers(), null, 2)}\n`);
|
|
490
320
|
this.cli.writeSuccess("\nConfig generation completed 👏\n");
|
|
491
321
|
}
|
|
492
322
|
}
|
|
@@ -2,3 +2,5 @@ export * from "./customer-config-service.js";
|
|
|
2
2
|
export * from "./customer-config-service-build-context.js";
|
|
3
3
|
export * from "./customer-config-service-model.js";
|
|
4
4
|
export * from "./customer-config-service-factory.js";
|
|
5
|
+
export * from "./wizard-answers.js";
|
|
6
|
+
export * from "./wizard-questions.js";
|
|
@@ -2,3 +2,5 @@ export * from "./customer-config-service.js";
|
|
|
2
2
|
export * from "./customer-config-service-build-context.js";
|
|
3
3
|
export * from "./customer-config-service-model.js";
|
|
4
4
|
export * from "./customer-config-service-factory.js";
|
|
5
|
+
export * from "./wizard-answers.js";
|
|
6
|
+
export * from "./wizard-questions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|