create-brainerce-store 1.24.0 → 1.26.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/dist/index.js +72 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var require_package = __commonJS({
|
|
|
31
31
|
"package.json"(exports2, module2) {
|
|
32
32
|
module2.exports = {
|
|
33
33
|
name: "create-brainerce-store",
|
|
34
|
-
version: "1.
|
|
34
|
+
version: "1.26.0",
|
|
35
35
|
description: "Scaffold a production-ready e-commerce storefront connected to Brainerce",
|
|
36
36
|
bin: {
|
|
37
37
|
"create-brainerce-store": "dist/index.js"
|
|
@@ -174,6 +174,17 @@ async function runInteractive(defaults) {
|
|
|
174
174
|
return error || true;
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
|
+
} else {
|
|
178
|
+
questions.push({
|
|
179
|
+
type: "text",
|
|
180
|
+
name: "projectName",
|
|
181
|
+
message: "Project name:",
|
|
182
|
+
initial: defaults.projectName,
|
|
183
|
+
validate: (value) => {
|
|
184
|
+
const error = validateProjectName(value);
|
|
185
|
+
return error || true;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
177
188
|
}
|
|
178
189
|
if (!defaults.connectionId) {
|
|
179
190
|
questions.push({
|
|
@@ -448,8 +459,11 @@ async function fetchStoreInfo(connectionId, baseUrl = KNOWN_API_URLS.production)
|
|
|
448
459
|
} catch {
|
|
449
460
|
throw new Error(`Invalid response from ${baseUrl}`);
|
|
450
461
|
}
|
|
462
|
+
const storeName = json.storeName || json.name || "My Store";
|
|
463
|
+
const displayName = json.channelName || storeName;
|
|
451
464
|
return {
|
|
452
|
-
name:
|
|
465
|
+
name: displayName,
|
|
466
|
+
storeName,
|
|
453
467
|
currency: json.currency || "USD",
|
|
454
468
|
language: json.language || "en",
|
|
455
469
|
...json.i18n ? { i18n: json.i18n } : {}
|
|
@@ -583,11 +597,41 @@ program.name("create-brainerce-store").description("Scaffold a production-ready
|
|
|
583
597
|
let pkgManager = options.pkgManager;
|
|
584
598
|
const skipGit = options.git === false;
|
|
585
599
|
const skipInstall = options.install === false;
|
|
600
|
+
let storeInfo = null;
|
|
601
|
+
let resolvedApiUrl = candidateApiUrls[0];
|
|
602
|
+
if (connectionId) {
|
|
603
|
+
const connError2 = validateConnectionId(connectionId);
|
|
604
|
+
if (connError2) {
|
|
605
|
+
logger.error(connError2);
|
|
606
|
+
process.exit(1);
|
|
607
|
+
}
|
|
608
|
+
const prefetchSpinner = createSpinner("Fetching store info...");
|
|
609
|
+
prefetchSpinner.start();
|
|
610
|
+
try {
|
|
611
|
+
const resolved = await resolveStoreInfo(connectionId, candidateApiUrls);
|
|
612
|
+
storeInfo = resolved.info;
|
|
613
|
+
resolvedApiUrl = resolved.apiBaseUrl;
|
|
614
|
+
const envLabel = resolved.apiBaseUrl === KNOWN_API_URLS.staging ? " [staging]" : resolved.apiBaseUrl === KNOWN_API_URLS.production ? "" : ` [${resolved.apiBaseUrl}]`;
|
|
615
|
+
const i18nStatus = storeInfo.i18n?.enabled && storeInfo.i18n.supportedLocales.length > 1 ? ` | i18n: ${storeInfo.i18n.supportedLocales.join(", ")}` : "";
|
|
616
|
+
const channelLabel = storeInfo.name !== storeInfo.storeName ? `"${storeInfo.name}" (channel in "${storeInfo.storeName}")` : `"${storeInfo.name}"`;
|
|
617
|
+
prefetchSpinner.succeed(
|
|
618
|
+
`Channel: ${channelLabel} | ${storeInfo.currency} | ${storeInfo.language}${i18nStatus}${envLabel}`
|
|
619
|
+
);
|
|
620
|
+
} catch (err) {
|
|
621
|
+
prefetchSpinner.fail("Could not fetch store info");
|
|
622
|
+
logger.warn(
|
|
623
|
+
err instanceof Error ? err.message : "Using defaults. Make sure the connection ID is correct and the Brainerce API is reachable."
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const slugify = (s) => s.toLowerCase().trim().replace(/[^a-z0-9\u0590-\u05FF]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 50);
|
|
628
|
+
const projectNameDefault = projectName || (storeInfo ? slugify(storeInfo.name) : void 0);
|
|
629
|
+
const languageDefault = language || storeInfo?.language;
|
|
586
630
|
if (!projectName || !connectionId || !language) {
|
|
587
631
|
const answers = await runInteractive({
|
|
588
|
-
projectName,
|
|
632
|
+
projectName: projectNameDefault,
|
|
589
633
|
connectionId,
|
|
590
|
-
language,
|
|
634
|
+
language: languageDefault,
|
|
591
635
|
framework,
|
|
592
636
|
theme,
|
|
593
637
|
pkgManager
|
|
@@ -609,28 +653,31 @@ program.name("create-brainerce-store").description("Scaffold a production-ready
|
|
|
609
653
|
logger.error(connError);
|
|
610
654
|
process.exit(1);
|
|
611
655
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
656
|
+
if (!storeInfo) {
|
|
657
|
+
const spinner = createSpinner("Fetching store info...");
|
|
658
|
+
spinner.start();
|
|
659
|
+
try {
|
|
660
|
+
const resolved = await resolveStoreInfo(connectionId, candidateApiUrls);
|
|
661
|
+
storeInfo = resolved.info;
|
|
662
|
+
resolvedApiUrl = resolved.apiBaseUrl;
|
|
663
|
+
const envLabel = resolved.apiBaseUrl === KNOWN_API_URLS.staging ? " [staging]" : resolved.apiBaseUrl === KNOWN_API_URLS.production ? "" : ` [${resolved.apiBaseUrl}]`;
|
|
664
|
+
const i18nStatus = storeInfo.i18n?.enabled && storeInfo.i18n.supportedLocales.length > 1 ? ` | i18n: ${storeInfo.i18n.supportedLocales.join(", ")}` : "";
|
|
665
|
+
const channelLabel = storeInfo.name !== storeInfo.storeName ? `"${storeInfo.name}" (channel in "${storeInfo.storeName}")` : `"${storeInfo.name}"`;
|
|
666
|
+
spinner.succeed(
|
|
667
|
+
`Channel: ${channelLabel} | ${storeInfo.currency} | ${storeInfo.language}${i18nStatus}${envLabel}`
|
|
668
|
+
);
|
|
669
|
+
} catch (err) {
|
|
670
|
+
spinner.fail("Could not fetch store info");
|
|
671
|
+
logger.warn(
|
|
672
|
+
err instanceof Error ? err.message : "Using defaults. Make sure the connection ID is correct and the Brainerce API is reachable."
|
|
673
|
+
);
|
|
674
|
+
storeInfo = {
|
|
675
|
+
name: projectName,
|
|
676
|
+
storeName: projectName,
|
|
677
|
+
currency: "USD",
|
|
678
|
+
language: "en"
|
|
679
|
+
};
|
|
627
680
|
}
|
|
628
|
-
} catch (err) {
|
|
629
|
-
spinner.fail("Could not fetch store info");
|
|
630
|
-
logger.warn(
|
|
631
|
-
err instanceof Error ? err.message : "Using defaults. Make sure the connection ID is correct and the Brainerce API is reachable."
|
|
632
|
-
);
|
|
633
|
-
storeInfo = { name: projectName, currency: "USD", language: "en" };
|
|
634
681
|
}
|
|
635
682
|
if (!pkgManager) {
|
|
636
683
|
pkgManager = detectPackageManager();
|