@faststore/cli 4.4.0-dev.4 → 4.4.0-dev.6
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 +548 -309
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -315,18 +315,239 @@ async function checkDeps(basePath) {
|
|
|
315
315
|
|
|
316
316
|
// src/commands/cms-sync.ts
|
|
317
317
|
import { Args as Args2, Command as Command2, Flags as Flags2 } from "@oclif/core";
|
|
318
|
+
import chalk9 from "chalk";
|
|
318
319
|
import { spawn } from "child_process";
|
|
320
|
+
import { existsSync as existsSync9 } from "fs";
|
|
321
|
+
import path9 from "path";
|
|
322
|
+
import { pathToFileURL as pathToFileURL7 } from "url";
|
|
319
323
|
|
|
320
|
-
// src/utils/
|
|
324
|
+
// src/utils/config.ts
|
|
325
|
+
import chalk3 from "chalk";
|
|
326
|
+
import { existsSync as existsSync4 } from "fs";
|
|
327
|
+
import path3 from "path";
|
|
328
|
+
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
329
|
+
var configFileName = "discovery.config.js";
|
|
330
|
+
function isMyAccountEnabled(config) {
|
|
331
|
+
return config?.experimental?.enableFaststoreMyAccount === true;
|
|
332
|
+
}
|
|
333
|
+
function resolveContentSource(rawType) {
|
|
334
|
+
const normalized = rawType?.toUpperCase();
|
|
335
|
+
switch (normalized) {
|
|
336
|
+
case void 0:
|
|
337
|
+
case "CMS":
|
|
338
|
+
return "CMS";
|
|
339
|
+
case "CP":
|
|
340
|
+
return "CP";
|
|
341
|
+
default: {
|
|
342
|
+
logger.error(
|
|
343
|
+
`${chalk3.red("[Error]")} - Unsupported contentSource.type "${rawType}". Expected "CMS" or "CP".`
|
|
344
|
+
);
|
|
345
|
+
process.exit(1);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function getDiscoveryConfig(basePath) {
|
|
350
|
+
const { tmpDir } = withBasePath(basePath);
|
|
351
|
+
const configPaths = [
|
|
352
|
+
path3.join(tmpDir, configFileName),
|
|
353
|
+
path3.join(basePath, configFileName)
|
|
354
|
+
];
|
|
355
|
+
for (const configPath of configPaths) {
|
|
356
|
+
if (existsSync4(configPath)) {
|
|
357
|
+
try {
|
|
358
|
+
const discoveryConfig = await import(pathToFileURL3(configPath).href);
|
|
359
|
+
return discoveryConfig?.default ?? discoveryConfig;
|
|
360
|
+
} catch (error) {
|
|
361
|
+
logger.warn(
|
|
362
|
+
`${chalk3.yellow("warning")} - Could not read config file: ${configPath}.`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
function isLocalizationEnabled(config) {
|
|
370
|
+
return config?.localization?.enabled === true;
|
|
371
|
+
}
|
|
372
|
+
function validateContentSourceForLocalization(config) {
|
|
373
|
+
if (!isLocalizationEnabled(config)) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const currentContentSourceType = config?.contentSource?.type?.toUpperCase();
|
|
377
|
+
if (currentContentSourceType !== "CP") {
|
|
378
|
+
logger.error(
|
|
379
|
+
`
|
|
380
|
+
${chalk3.red("[Error]")} - Localization is enabled but contentSource is set to "${currentContentSourceType}".
|
|
381
|
+
|
|
382
|
+
${chalk3.cyan("Required Action:")}
|
|
383
|
+
Update your ${chalk3.bold("discovery.config.js")} file:
|
|
384
|
+
|
|
385
|
+
contentSource: {
|
|
386
|
+
type: ${chalk3.green('"CP"')}
|
|
387
|
+
},
|
|
388
|
+
|
|
389
|
+
${chalk3.dim("When localization is enabled, Content Platform (CP) is required.")}
|
|
390
|
+
`
|
|
391
|
+
);
|
|
392
|
+
process.exit(1);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async function checkAndValidateLocalization(basePath) {
|
|
396
|
+
const config = await getDiscoveryConfig(basePath);
|
|
397
|
+
if (!config) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
validateContentSourceForLocalization(config);
|
|
401
|
+
return isLocalizationEnabled(config);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/utils/cp-schema.ts
|
|
405
|
+
import chalk5 from "chalk";
|
|
406
|
+
import { cpSync, existsSync as existsSync5, mkdirSync, mkdtempSync, rmSync } from "fs";
|
|
407
|
+
import path4 from "path";
|
|
408
|
+
|
|
409
|
+
// src/utils/runCommandSync.ts
|
|
321
410
|
import chalk4 from "chalk";
|
|
411
|
+
import { execSync } from "child_process";
|
|
412
|
+
var showError = ({
|
|
413
|
+
message,
|
|
414
|
+
cmd,
|
|
415
|
+
output
|
|
416
|
+
}) => {
|
|
417
|
+
logger.error(`${chalk4.red("error")} - ${message}`);
|
|
418
|
+
if (cmd && output) {
|
|
419
|
+
logger.error(`${chalk4.magenta("$")} ${cmd}`);
|
|
420
|
+
logger.error(output);
|
|
421
|
+
}
|
|
422
|
+
process.exit(1);
|
|
423
|
+
};
|
|
424
|
+
var showWarning = ({
|
|
425
|
+
message,
|
|
426
|
+
cmd,
|
|
427
|
+
output
|
|
428
|
+
}) => {
|
|
429
|
+
logger.warn(`${chalk4.yellow("warn")} - ${message}`);
|
|
430
|
+
if (cmd && output) {
|
|
431
|
+
logger.warn(`${chalk4.magenta("$")} ${cmd}`);
|
|
432
|
+
logger.warn(output);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var runCommandSync = ({
|
|
436
|
+
cmd,
|
|
437
|
+
errorMessage,
|
|
438
|
+
throws,
|
|
439
|
+
cwd,
|
|
440
|
+
interactive = false
|
|
441
|
+
}) => {
|
|
442
|
+
try {
|
|
443
|
+
logger.log(`[STARTED] ${cmd}`);
|
|
444
|
+
const res = execSync(interactive ? cmd : `${cmd} 2>&1`, {
|
|
445
|
+
stdio: interactive ? "inherit" : "pipe",
|
|
446
|
+
cwd
|
|
447
|
+
});
|
|
448
|
+
logger.log(`[STATUS] ${res?.toString() ?? "Unknown"}`);
|
|
449
|
+
logger.log(`[FINISHED] ${cmd}`);
|
|
450
|
+
} catch (error) {
|
|
451
|
+
const execError = error;
|
|
452
|
+
const output = execError?.stdout?.toString() || execError?.stderr?.toString() || void 0;
|
|
453
|
+
if (throws === "warning") {
|
|
454
|
+
showWarning({ message: errorMessage, cmd, output });
|
|
455
|
+
} else {
|
|
456
|
+
showError({ message: errorMessage, cmd, output });
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// src/utils/cp-schema.ts
|
|
462
|
+
var MY_ACCOUNT_SUBDIRS = ["components", "pages"];
|
|
463
|
+
function getExistingCpDirs(basePath) {
|
|
464
|
+
const { userCMSDir } = withBasePath(basePath);
|
|
465
|
+
const componentsDir = path4.join(userCMSDir, "components");
|
|
466
|
+
const pagesDir = path4.join(userCMSDir, "pages");
|
|
467
|
+
return [componentsDir, pagesDir].filter((dir) => existsSync5(dir)).map((dir) => path4.relative(basePath, dir));
|
|
468
|
+
}
|
|
469
|
+
function errorNoCustomization() {
|
|
470
|
+
logger.error(
|
|
471
|
+
`${chalk5.red("[Error]")} - No CMS customization found. Expected cms/faststore/components and/or cms/faststore/pages.`
|
|
472
|
+
);
|
|
473
|
+
process.exit(1);
|
|
474
|
+
}
|
|
475
|
+
function getCpSchemaOutputPath(basePath) {
|
|
476
|
+
return path4.relative(
|
|
477
|
+
basePath,
|
|
478
|
+
path4.join(withBasePath(basePath).userCMSDir, "schema.json")
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
function prepareMyAccountMergeDir(basePath) {
|
|
482
|
+
const { coreCMSDir, userCMSDir, tmpDir } = withBasePath(basePath);
|
|
483
|
+
const coreMyAccountDir = path4.join(coreCMSDir, "my-account");
|
|
484
|
+
if (!existsSync5(coreMyAccountDir)) {
|
|
485
|
+
logger.error(
|
|
486
|
+
`${chalk5.red("[Error]")} - My Account is enabled but the core My Account schemas were not found at ${coreMyAccountDir}. Update @faststore/core or disable experimental.enableFaststoreMyAccount.`
|
|
487
|
+
);
|
|
488
|
+
process.exit(1);
|
|
489
|
+
}
|
|
490
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
491
|
+
const mergeDir = mkdtempSync(path4.join(tmpDir, "cms-myaccount-"));
|
|
492
|
+
try {
|
|
493
|
+
const dirs = [];
|
|
494
|
+
for (const subdir of MY_ACCOUNT_SUBDIRS) {
|
|
495
|
+
const dest = path4.join(mergeDir, subdir);
|
|
496
|
+
mkdirSync(dest, { recursive: true });
|
|
497
|
+
const coreSource = path4.join(coreMyAccountDir, subdir);
|
|
498
|
+
if (existsSync5(coreSource)) {
|
|
499
|
+
cpSync(coreSource, dest, { recursive: true });
|
|
500
|
+
}
|
|
501
|
+
const storeSource = path4.join(userCMSDir, subdir);
|
|
502
|
+
if (existsSync5(storeSource)) {
|
|
503
|
+
cpSync(storeSource, dest, { recursive: true });
|
|
504
|
+
}
|
|
505
|
+
dirs.push(path4.relative(basePath, dest));
|
|
506
|
+
}
|
|
507
|
+
return { mergeDir, dirs };
|
|
508
|
+
} catch (error) {
|
|
509
|
+
cleanupMyAccountMergeDir(mergeDir);
|
|
510
|
+
throw error;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function cleanupMyAccountMergeDir(mergeDir) {
|
|
514
|
+
rmSync(mergeDir, { recursive: true, force: true });
|
|
515
|
+
}
|
|
516
|
+
function generateAndUploadSchema({
|
|
517
|
+
basePath,
|
|
518
|
+
dirs,
|
|
519
|
+
schemaOut,
|
|
520
|
+
dryRun
|
|
521
|
+
}) {
|
|
522
|
+
runCommandSync({
|
|
523
|
+
cmd: `vtex content generate-schema ${dirs.join(" ")} -o ${schemaOut}`,
|
|
524
|
+
cwd: basePath,
|
|
525
|
+
throws: "error",
|
|
526
|
+
errorMessage: "Failed to generate CMS schema",
|
|
527
|
+
interactive: true
|
|
528
|
+
});
|
|
529
|
+
if (dryRun) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
runCommandSync({
|
|
533
|
+
cmd: `vtex content upload-schema ${schemaOut}`,
|
|
534
|
+
cwd: basePath,
|
|
535
|
+
throws: "error",
|
|
536
|
+
errorMessage: "Failed to upload CMS schema",
|
|
537
|
+
interactive: true
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/utils/generate.ts
|
|
542
|
+
import chalk6 from "chalk";
|
|
322
543
|
import fsExtra4 from "fs-extra";
|
|
323
|
-
import
|
|
544
|
+
import path7 from "path";
|
|
324
545
|
import ora from "ora";
|
|
325
|
-
import { pathToFileURL as
|
|
546
|
+
import { pathToFileURL as pathToFileURL5 } from "url";
|
|
326
547
|
|
|
327
548
|
// src/utils/createNextjsPages.ts
|
|
328
549
|
import fs from "fs";
|
|
329
|
-
import
|
|
550
|
+
import path5 from "path";
|
|
330
551
|
|
|
331
552
|
// src/utils/templates/myAccountPage.ts
|
|
332
553
|
var myAccountPageTemplate = (pagePath) => `
|
|
@@ -377,8 +598,8 @@ var createExternalPages = ({
|
|
|
377
598
|
baseCustomizationPagesDir
|
|
378
599
|
}) => {
|
|
379
600
|
fs.readdirSync(customizationPagesDir).forEach((file) => {
|
|
380
|
-
const filePath =
|
|
381
|
-
const destinationPath =
|
|
601
|
+
const filePath = path5.join(customizationPagesDir, file);
|
|
602
|
+
const destinationPath = path5.join(corePagesDir, file);
|
|
382
603
|
if (fs.statSync(filePath).isDirectory()) {
|
|
383
604
|
if (!fs.existsSync(destinationPath)) {
|
|
384
605
|
fs.mkdirSync(destinationPath, { recursive: true });
|
|
@@ -391,7 +612,7 @@ var createExternalPages = ({
|
|
|
391
612
|
}
|
|
392
613
|
const isReactFile = filePath.endsWith(".tsx");
|
|
393
614
|
const isDestinationAvailable = !fs.existsSync(destinationPath) && !fs.existsSync(
|
|
394
|
-
|
|
615
|
+
path5.join(destinationPath.replace(".tsx", ""), "index.tsx")
|
|
395
616
|
);
|
|
396
617
|
if (isReactFile && isDestinationAvailable) {
|
|
397
618
|
const externalPagePath = `src/customizations/src/pages${filePath.replace(baseCustomizationPagesDir, "").replace(".tsx", "")}`;
|
|
@@ -405,8 +626,8 @@ function isAllowedPrefixPage(file) {
|
|
|
405
626
|
}
|
|
406
627
|
function createNextJsPages(basePath) {
|
|
407
628
|
const { tmpDir } = withBasePath(basePath);
|
|
408
|
-
const corePagesDir =
|
|
409
|
-
const customizationPagesDir =
|
|
629
|
+
const corePagesDir = path5.join(tmpDir, "src/pages");
|
|
630
|
+
const customizationPagesDir = path5.join(
|
|
410
631
|
tmpDir,
|
|
411
632
|
"src/customizations/src/pages"
|
|
412
633
|
);
|
|
@@ -419,7 +640,7 @@ function createNextJsPages(basePath) {
|
|
|
419
640
|
}) => {
|
|
420
641
|
const items = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
421
642
|
return items.every((item) => {
|
|
422
|
-
const itemPath =
|
|
643
|
+
const itemPath = path5.join(dirPath, item.name);
|
|
423
644
|
if (item.isDirectory()) {
|
|
424
645
|
return allPagesAreAllowed({ basePath: basePath2, dirPath: itemPath });
|
|
425
646
|
}
|
|
@@ -430,7 +651,7 @@ function createNextJsPages(basePath) {
|
|
|
430
651
|
if (!isNextPage) {
|
|
431
652
|
return false;
|
|
432
653
|
}
|
|
433
|
-
const relativePath =
|
|
654
|
+
const relativePath = path5.relative(basePath2, itemPath);
|
|
434
655
|
const normalizedPath = "/" + relativePath.replace(/\\/g, "/").replace(/\.(js|jsx|ts|tsx)$/, "");
|
|
435
656
|
return isAllowedPrefixPage(normalizedPath);
|
|
436
657
|
});
|
|
@@ -451,61 +672,6 @@ function createNextJsPages(basePath) {
|
|
|
451
672
|
});
|
|
452
673
|
}
|
|
453
674
|
|
|
454
|
-
// src/utils/runCommandSync.ts
|
|
455
|
-
import chalk3 from "chalk";
|
|
456
|
-
import { execSync } from "child_process";
|
|
457
|
-
var showError = ({
|
|
458
|
-
message,
|
|
459
|
-
cmd,
|
|
460
|
-
output
|
|
461
|
-
}) => {
|
|
462
|
-
logger.error(`${chalk3.red("error")} - ${message}`);
|
|
463
|
-
if (cmd && output) {
|
|
464
|
-
logger.log(`${chalk3.magenta("DEBUG")} - $ ${JSON.stringify(cmd)} error \u2193`);
|
|
465
|
-
logger.log(output);
|
|
466
|
-
}
|
|
467
|
-
process.exit(1);
|
|
468
|
-
};
|
|
469
|
-
var showWarning = ({
|
|
470
|
-
message,
|
|
471
|
-
cmd,
|
|
472
|
-
output
|
|
473
|
-
}) => {
|
|
474
|
-
logger.warn(`${chalk3.yellow("warn")} - ${message}`);
|
|
475
|
-
if (cmd && output) {
|
|
476
|
-
logger.log(`${chalk3.magenta("DEBUG")} - $ ${JSON.stringify(cmd)} warn \u2193`);
|
|
477
|
-
logger.log(output);
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
var runCommandSync = ({
|
|
481
|
-
cmd,
|
|
482
|
-
errorMessage,
|
|
483
|
-
throws,
|
|
484
|
-
cwd
|
|
485
|
-
}) => {
|
|
486
|
-
const debug = process.env.DISCOVERY_DEBUG === "true" ? true : false;
|
|
487
|
-
try {
|
|
488
|
-
logger.log(`[STARTED] ${cmd}`);
|
|
489
|
-
const res = execSync(
|
|
490
|
-
debug ? `${cmd} --debug --verbose 2>&1` : `${cmd} 2>&1`,
|
|
491
|
-
{
|
|
492
|
-
stdio: "pipe",
|
|
493
|
-
cwd
|
|
494
|
-
}
|
|
495
|
-
);
|
|
496
|
-
logger.log(`[STATUS] ${res?.toString() ?? "Unknown"}`);
|
|
497
|
-
logger.log(`[FINISHED] ${cmd}`);
|
|
498
|
-
} catch (error) {
|
|
499
|
-
const execError = error;
|
|
500
|
-
const output = execError?.stdout?.toString() || execError?.stderr?.toString() || void 0;
|
|
501
|
-
if (throws === "warning") {
|
|
502
|
-
showWarning({ message: errorMessage, cmd, output });
|
|
503
|
-
} else {
|
|
504
|
-
showError({ message: errorMessage, cmd, output });
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
|
|
509
675
|
// src/utils/dependencies.ts
|
|
510
676
|
async function installDependencies({
|
|
511
677
|
dependencies,
|
|
@@ -524,9 +690,9 @@ async function installDependencies({
|
|
|
524
690
|
|
|
525
691
|
// src/utils/plugins.ts
|
|
526
692
|
import fsExtra3 from "fs-extra";
|
|
527
|
-
import
|
|
528
|
-
import { pathToFileURL as
|
|
529
|
-
var { copySync: copySync2, existsSync:
|
|
693
|
+
import path6 from "path";
|
|
694
|
+
import { pathToFileURL as pathToFileURL4 } from "url";
|
|
695
|
+
var { copySync: copySync2, existsSync: existsSync6, mkdirSync: mkdirSync2, readdirSync: readdirSync2, writeFileSync } = fsExtra3;
|
|
530
696
|
var PLUGIN_CONFIG_FILE = "plugin.config.js";
|
|
531
697
|
var sanitizePluginName = (pluginName, pascalCase = false) => {
|
|
532
698
|
const sanitized = pluginName.split("/")[1];
|
|
@@ -556,7 +722,7 @@ var getPluginsList = async (basePath) => {
|
|
|
556
722
|
try {
|
|
557
723
|
const {
|
|
558
724
|
default: { plugins = [] }
|
|
559
|
-
} = await import(
|
|
725
|
+
} = await import(pathToFileURL4(tmpStoreConfigFile).href);
|
|
560
726
|
return plugins;
|
|
561
727
|
} catch (error) {
|
|
562
728
|
logger.error(`Could not load plugins from store config`);
|
|
@@ -572,7 +738,7 @@ var copyPluginsSrc = async (basePath, plugins) => {
|
|
|
572
738
|
basePath,
|
|
573
739
|
getPluginName(pluginName)
|
|
574
740
|
);
|
|
575
|
-
const pluginDestPath =
|
|
741
|
+
const pluginDestPath = path6.join(
|
|
576
742
|
tmpPluginsDir,
|
|
577
743
|
sanitizePluginName(pluginName)
|
|
578
744
|
);
|
|
@@ -587,7 +753,7 @@ var copyPluginPublicFiles = async (basePath, plugins) => {
|
|
|
587
753
|
const pluginName = getPluginName(plugin);
|
|
588
754
|
const pluginPath = getPackagePath(getPluginName(pluginName));
|
|
589
755
|
try {
|
|
590
|
-
if (
|
|
756
|
+
if (existsSync6(`${pluginPath}/public`)) {
|
|
591
757
|
copySync2(`${pluginPath}/public`, `${tmpDir}/public`, {
|
|
592
758
|
dereference: true,
|
|
593
759
|
overwrite: true
|
|
@@ -633,7 +799,7 @@ var generatePluginPages = async (basePath, plugins) => {
|
|
|
633
799
|
plugins.forEach(async (plugin) => {
|
|
634
800
|
const pluginName = getPluginName(plugin);
|
|
635
801
|
const pluginConfigPath = getPackagePath(pluginName, PLUGIN_CONFIG_FILE);
|
|
636
|
-
const { default: pluginConfig } = await import(
|
|
802
|
+
const { default: pluginConfig } = await import(pathToFileURL4(pluginConfigPath).href);
|
|
637
803
|
const { pages: pagesCustom } = getPluginCustomConfig(plugin);
|
|
638
804
|
const pagesConfig = {
|
|
639
805
|
...pluginConfig.pages ?? {},
|
|
@@ -644,13 +810,13 @@ var generatePluginPages = async (basePath, plugins) => {
|
|
|
644
810
|
const paths = pagesConfig[pageName].path.split("/");
|
|
645
811
|
const pageFile = paths.pop();
|
|
646
812
|
const pagePaths = paths;
|
|
647
|
-
const pagePath =
|
|
813
|
+
const pagePath = path6.join(tmpPagesDir, ...pagePaths, pageFile + ".tsx");
|
|
648
814
|
const fileContent = getPluginPageFileContent(
|
|
649
815
|
sanitizePluginName(pluginName),
|
|
650
816
|
pageName,
|
|
651
817
|
pagesConfig[pageName].appLayout
|
|
652
818
|
);
|
|
653
|
-
|
|
819
|
+
mkdirSync2(path6.dirname(pagePath), { recursive: true });
|
|
654
820
|
writeFileSync(pagePath, fileContent);
|
|
655
821
|
});
|
|
656
822
|
});
|
|
@@ -659,7 +825,7 @@ async function addPluginsSections(basePath, plugins) {
|
|
|
659
825
|
const { tmpPluginsDir, getPackagePath } = withBasePath(basePath);
|
|
660
826
|
logger.log("Adding plugin sections");
|
|
661
827
|
const indexPluginsOverrides = plugins.filter(
|
|
662
|
-
(plugin) =>
|
|
828
|
+
(plugin) => existsSync6(
|
|
663
829
|
getPackagePath(getPluginName(plugin), "src", "components", "index.ts")
|
|
664
830
|
)
|
|
665
831
|
).map((plugin) => {
|
|
@@ -676,7 +842,7 @@ async function addPluginsSections(basePath, plugins) {
|
|
|
676
842
|
${indexPluginsOverrides.map((plugin) => `...${plugin.pluginReference}`).join(",\n")}
|
|
677
843
|
}
|
|
678
844
|
`;
|
|
679
|
-
const sectionPath =
|
|
845
|
+
const sectionPath = path6.join(tmpPluginsDir, "index.ts");
|
|
680
846
|
writeFileSync(sectionPath, pluginsImportFileContent);
|
|
681
847
|
logger.log("Writing plugins overrides");
|
|
682
848
|
logger.log(sectionPath);
|
|
@@ -693,14 +859,14 @@ async function addPluginsOverrides(basePath, plugins) {
|
|
|
693
859
|
"components",
|
|
694
860
|
"overrides"
|
|
695
861
|
)
|
|
696
|
-
})).filter(({ pluginOverridesPath }) =>
|
|
862
|
+
})).filter(({ pluginOverridesPath }) => existsSync6(pluginOverridesPath)).reverse().forEach(({ pluginName, pluginOverridesPath }) => {
|
|
697
863
|
const overrideFilesAlreadyCopied = [];
|
|
698
864
|
const sanitizedPluginName = sanitizePluginName(pluginName);
|
|
699
865
|
const overrideFiles = readdirSync2(pluginOverridesPath);
|
|
700
866
|
overrideFiles.filter((file) => !overrideFilesAlreadyCopied.includes(file)).forEach((overrideFileName) => {
|
|
701
867
|
const overrideFileContent = `export { override } from 'src/plugins/${sanitizedPluginName}/components/overrides/${overrideFileName.split(".")[0]}'`;
|
|
702
868
|
writeFileSync(
|
|
703
|
-
|
|
869
|
+
path6.join(tmpPluginsDir, "overrides", overrideFileName),
|
|
704
870
|
overrideFileContent
|
|
705
871
|
);
|
|
706
872
|
overrideFilesAlreadyCopied.push(overrideFileName);
|
|
@@ -710,7 +876,7 @@ async function addPluginsOverrides(basePath, plugins) {
|
|
|
710
876
|
var addPluginsTheme = async (basePath, plugins) => {
|
|
711
877
|
const { getPackagePath, tmpThemesPluginsFile } = withBasePath(basePath);
|
|
712
878
|
const pluginImportsContent = plugins.filter(
|
|
713
|
-
(plugin) =>
|
|
879
|
+
(plugin) => existsSync6(
|
|
714
880
|
getPackagePath(getPluginName(plugin), "src", "themes", "index.scss")
|
|
715
881
|
)
|
|
716
882
|
).map(
|
|
@@ -734,7 +900,7 @@ var generatePluginApis = async (basePath, plugins) => {
|
|
|
734
900
|
plugins.forEach(async (plugin) => {
|
|
735
901
|
const pluginName = getPluginName(plugin);
|
|
736
902
|
const pluginConfigPath = getPackagePath(pluginName, PLUGIN_CONFIG_FILE);
|
|
737
|
-
const { default: pluginConfig } = await import(
|
|
903
|
+
const { default: pluginConfig } = await import(pathToFileURL4(pluginConfigPath).href);
|
|
738
904
|
const { apis: apisCustom } = getPluginCustomConfig(plugin);
|
|
739
905
|
const apisConfig = {
|
|
740
906
|
...pluginConfig.apis ?? {},
|
|
@@ -745,7 +911,7 @@ var generatePluginApis = async (basePath, plugins) => {
|
|
|
745
911
|
const paths = apisConfig[apiName].path.split("/");
|
|
746
912
|
const apiFile = paths.pop();
|
|
747
913
|
const apiPaths = paths;
|
|
748
|
-
const apiPath =
|
|
914
|
+
const apiPath = path6.join(
|
|
749
915
|
tmpApiDir,
|
|
750
916
|
"plugins",
|
|
751
917
|
...apiPaths,
|
|
@@ -755,7 +921,7 @@ var generatePluginApis = async (basePath, plugins) => {
|
|
|
755
921
|
sanitizePluginName(pluginName),
|
|
756
922
|
apiName
|
|
757
923
|
);
|
|
758
|
-
|
|
924
|
+
mkdirSync2(path6.dirname(apiPath), { recursive: true });
|
|
759
925
|
writeFileSync(apiPath, fileContent);
|
|
760
926
|
});
|
|
761
927
|
});
|
|
@@ -775,7 +941,7 @@ var installPlugins = async (basePath) => {
|
|
|
775
941
|
var {
|
|
776
942
|
copyFileSync,
|
|
777
943
|
copySync: copySync3,
|
|
778
|
-
existsSync:
|
|
944
|
+
existsSync: existsSync7,
|
|
779
945
|
mkdirsSync,
|
|
780
946
|
readFileSync,
|
|
781
947
|
readdirSync: readdirSync3,
|
|
@@ -793,17 +959,17 @@ var ignorePaths = [
|
|
|
793
959
|
function createTmpFolder(basePath) {
|
|
794
960
|
const { tmpDir, tmpFolderName } = withBasePath(basePath);
|
|
795
961
|
try {
|
|
796
|
-
if (
|
|
962
|
+
if (existsSync7(tmpDir)) {
|
|
797
963
|
removeSync2(tmpDir);
|
|
798
964
|
}
|
|
799
965
|
mkdirsSync(tmpDir);
|
|
800
966
|
logger.log(
|
|
801
|
-
`${
|
|
967
|
+
`${chalk6.green("success")} - Temporary folder ${chalk6.dim(
|
|
802
968
|
tmpFolderName
|
|
803
969
|
)} created`
|
|
804
970
|
);
|
|
805
971
|
} catch (err) {
|
|
806
|
-
logger.error(`${
|
|
972
|
+
logger.error(`${chalk6.red("error")} - ${err}`);
|
|
807
973
|
}
|
|
808
974
|
}
|
|
809
975
|
function buildFaststorePackageJson(coreManifest, voltaConfig) {
|
|
@@ -831,8 +997,8 @@ function buildFaststorePackageJson(coreManifest, voltaConfig) {
|
|
|
831
997
|
}
|
|
832
998
|
function readRootVoltaConfig(rootDir) {
|
|
833
999
|
try {
|
|
834
|
-
const rootManifestPath =
|
|
835
|
-
if (!
|
|
1000
|
+
const rootManifestPath = path7.join(rootDir, "package.json");
|
|
1001
|
+
if (!existsSync7(rootManifestPath)) {
|
|
836
1002
|
return void 0;
|
|
837
1003
|
}
|
|
838
1004
|
const rootManifest = JSON.parse(readFileSync(rootManifestPath, "utf8"));
|
|
@@ -844,27 +1010,27 @@ function readRootVoltaConfig(rootDir) {
|
|
|
844
1010
|
function filterAndCopyPackageJson(basePath) {
|
|
845
1011
|
const { coreDir, tmpDir, getRoot } = withBasePath(basePath);
|
|
846
1012
|
const coreManifest = JSON.parse(
|
|
847
|
-
readFileSync(
|
|
1013
|
+
readFileSync(path7.join(coreDir, "package.json"), "utf8")
|
|
848
1014
|
);
|
|
849
1015
|
const voltaConfig = readRootVoltaConfig(getRoot());
|
|
850
1016
|
const filteredFileContent = buildFaststorePackageJson(
|
|
851
1017
|
coreManifest,
|
|
852
1018
|
voltaConfig
|
|
853
1019
|
);
|
|
854
|
-
writeJsonSync(
|
|
1020
|
+
writeJsonSync(path7.join(tmpDir, "package.json"), filteredFileContent, {
|
|
855
1021
|
spaces: 2
|
|
856
1022
|
});
|
|
857
1023
|
}
|
|
858
1024
|
var TS_CONFIG_STRICT_RULES_ENABLED = ["noImplicitAny"];
|
|
859
1025
|
function disableTsConfigStrictRules(basePath) {
|
|
860
1026
|
const { coreDir, tmpDir } = withBasePath(basePath);
|
|
861
|
-
const coreTsConfigPath =
|
|
1027
|
+
const coreTsConfigPath = path7.join(coreDir, "tsconfig.json");
|
|
862
1028
|
const coreTsConfigFile = readFileSync(coreTsConfigPath, "utf8");
|
|
863
1029
|
const tsConfig = JSON.parse(coreTsConfigFile);
|
|
864
1030
|
TS_CONFIG_STRICT_RULES_ENABLED.forEach((strictRule) => {
|
|
865
1031
|
tsConfig.compilerOptions[strictRule] = false;
|
|
866
1032
|
});
|
|
867
|
-
writeJsonSync(
|
|
1033
|
+
writeJsonSync(path7.join(tmpDir, "tsconfig.json"), tsConfig, {
|
|
868
1034
|
spaces: 2
|
|
869
1035
|
});
|
|
870
1036
|
}
|
|
@@ -874,14 +1040,14 @@ function copyCoreFiles(basePath) {
|
|
|
874
1040
|
copySync3(coreDir, tmpDir, {
|
|
875
1041
|
dereference: true,
|
|
876
1042
|
filter(src) {
|
|
877
|
-
const fileOrDirName =
|
|
1043
|
+
const fileOrDirName = path7.basename(src);
|
|
878
1044
|
const shouldCopy = fileOrDirName ? !ignorePaths.includes(fileOrDirName) : true;
|
|
879
1045
|
return shouldCopy;
|
|
880
1046
|
}
|
|
881
1047
|
});
|
|
882
1048
|
filterAndCopyPackageJson(basePath);
|
|
883
1049
|
disableTsConfigStrictRules(basePath);
|
|
884
|
-
logger.log(`${
|
|
1050
|
+
logger.log(`${chalk6.green("success")} - Core files copied`);
|
|
885
1051
|
} catch (e) {
|
|
886
1052
|
logger.error(e);
|
|
887
1053
|
}
|
|
@@ -890,7 +1056,7 @@ function copyPublicFiles(basePath) {
|
|
|
890
1056
|
const { userDir, tmpDir } = withBasePath(basePath);
|
|
891
1057
|
const allowList = ["json", "txt", "xml", "ico", "public", "svg"];
|
|
892
1058
|
try {
|
|
893
|
-
if (
|
|
1059
|
+
if (existsSync7(`${userDir}/public`)) {
|
|
894
1060
|
copySync3(`${userDir}/public`, `${tmpDir}/public`, {
|
|
895
1061
|
dereference: true,
|
|
896
1062
|
overwrite: true,
|
|
@@ -899,7 +1065,7 @@ function copyPublicFiles(basePath) {
|
|
|
899
1065
|
return allow;
|
|
900
1066
|
}
|
|
901
1067
|
});
|
|
902
|
-
logger.log(`${
|
|
1068
|
+
logger.log(`${chalk6.green("success")} - Public files copied`);
|
|
903
1069
|
}
|
|
904
1070
|
} catch (e) {
|
|
905
1071
|
logger.error(e);
|
|
@@ -908,34 +1074,34 @@ function copyPublicFiles(basePath) {
|
|
|
908
1074
|
async function copyCypressFiles(basePath) {
|
|
909
1075
|
const { userDir, userStoreConfigFile, userLegacyStoreConfigFile, tmpDir } = withBasePath(basePath);
|
|
910
1076
|
try {
|
|
911
|
-
if (
|
|
1077
|
+
if (existsSync7(`${userDir}/cypress.json`)) {
|
|
912
1078
|
copySync3(`${userDir}/cypress.json`, `${tmpDir}/cypress.json`, {
|
|
913
1079
|
dereference: true
|
|
914
1080
|
});
|
|
915
1081
|
}
|
|
916
|
-
if (
|
|
1082
|
+
if (existsSync7(`${userDir}/cypress.config.ts`)) {
|
|
917
1083
|
copySync3(`${userDir}/cypress.config.ts`, `${tmpDir}/cypress.config.ts`, {
|
|
918
1084
|
dereference: true
|
|
919
1085
|
});
|
|
920
1086
|
}
|
|
921
1087
|
let userStoreConfig;
|
|
922
|
-
if (
|
|
923
|
-
userStoreConfig = (await import(
|
|
924
|
-
} else if (
|
|
925
|
-
userStoreConfig = (await import(
|
|
1088
|
+
if (existsSync7(userStoreConfigFile)) {
|
|
1089
|
+
userStoreConfig = (await import(pathToFileURL5(path7.resolve(userStoreConfigFile)).href))?.default;
|
|
1090
|
+
} else if (existsSync7(userLegacyStoreConfigFile)) {
|
|
1091
|
+
userStoreConfig = (await import(pathToFileURL5(path7.resolve(userLegacyStoreConfigFile)).href))?.default;
|
|
926
1092
|
} else {
|
|
927
1093
|
logger.info(
|
|
928
|
-
`${
|
|
1094
|
+
`${chalk6.blue(
|
|
929
1095
|
"info"
|
|
930
1096
|
)} - No store config file was found in the root directory`
|
|
931
1097
|
);
|
|
932
1098
|
}
|
|
933
|
-
if (
|
|
1099
|
+
if (existsSync7(`${userDir}/cypress`) && userStoreConfig?.experimental?.enableCypressExtension) {
|
|
934
1100
|
copySync3(`${userDir}/cypress`, `${tmpDir}/cypress`, {
|
|
935
1101
|
overwrite: true,
|
|
936
1102
|
dereference: true
|
|
937
1103
|
});
|
|
938
|
-
logger.log(`${
|
|
1104
|
+
logger.log(`${chalk6.green("success")} - Cypress test files copied`);
|
|
939
1105
|
}
|
|
940
1106
|
if (userStoreConfig?.experimental?.cypressVersion > 9) {
|
|
941
1107
|
copySync3(
|
|
@@ -957,27 +1123,27 @@ function copyUserStarterToCustomizations(basePath) {
|
|
|
957
1123
|
tmpStoreConfigFile
|
|
958
1124
|
} = withBasePath(basePath);
|
|
959
1125
|
try {
|
|
960
|
-
if (
|
|
1126
|
+
if (existsSync7(userSrcDir) && readdirSync3(userSrcDir).length > 0) {
|
|
961
1127
|
copySync3(userSrcDir, tmpCustomizationsSrcDir, { dereference: true });
|
|
962
1128
|
createNextJsPages(basePath);
|
|
963
1129
|
}
|
|
964
1130
|
} catch (err) {
|
|
965
|
-
logger.error(`${
|
|
1131
|
+
logger.error(`${chalk6.red("error")} - ${err}`);
|
|
966
1132
|
}
|
|
967
|
-
if (
|
|
1133
|
+
if (existsSync7(userStoreConfigFile)) {
|
|
968
1134
|
copySync3(userStoreConfigFile, tmpStoreConfigFile, { dereference: true });
|
|
969
|
-
} else if (
|
|
1135
|
+
} else if (existsSync7(userLegacyStoreConfigFile)) {
|
|
970
1136
|
copySync3(userLegacyStoreConfigFile, tmpStoreConfigFile, {
|
|
971
1137
|
dereference: true
|
|
972
1138
|
});
|
|
973
1139
|
} else {
|
|
974
1140
|
logger.info(
|
|
975
|
-
`${
|
|
1141
|
+
`${chalk6.blue(
|
|
976
1142
|
"info"
|
|
977
1143
|
)} - No store config file was found in the root directory`
|
|
978
1144
|
);
|
|
979
1145
|
}
|
|
980
|
-
logger.log(`${
|
|
1146
|
+
logger.log(`${chalk6.green("success")} - Starter files copied`);
|
|
981
1147
|
}
|
|
982
1148
|
async function createCmsWebhookUrlsJsonFile(basePath) {
|
|
983
1149
|
const {
|
|
@@ -986,13 +1152,13 @@ async function createCmsWebhookUrlsJsonFile(basePath) {
|
|
|
986
1152
|
tmpCMSWebhookUrlsFile
|
|
987
1153
|
} = withBasePath(basePath);
|
|
988
1154
|
let userStoreConfig;
|
|
989
|
-
if (
|
|
990
|
-
userStoreConfig = (await import(
|
|
991
|
-
} else if (
|
|
992
|
-
userStoreConfig = (await import(
|
|
1155
|
+
if (existsSync7(userStoreConfigFile)) {
|
|
1156
|
+
userStoreConfig = (await import(pathToFileURL5(path7.resolve(userStoreConfigFile)).href))?.default;
|
|
1157
|
+
} else if (existsSync7(userLegacyStoreConfigFile)) {
|
|
1158
|
+
userStoreConfig = (await import(pathToFileURL5(path7.resolve(userLegacyStoreConfigFile)).href))?.default;
|
|
993
1159
|
} else {
|
|
994
1160
|
logger.info(
|
|
995
|
-
`${
|
|
1161
|
+
`${chalk6.blue(
|
|
996
1162
|
"info"
|
|
997
1163
|
)} - No store config file was found in the root directory`
|
|
998
1164
|
);
|
|
@@ -1001,12 +1167,12 @@ async function createCmsWebhookUrlsJsonFile(basePath) {
|
|
|
1001
1167
|
const { webhookUrls } = userStoreConfig?.vtexHeadlessCms;
|
|
1002
1168
|
try {
|
|
1003
1169
|
writeJsonSync(tmpCMSWebhookUrlsFile, { urls: webhookUrls }, { spaces: 2 });
|
|
1004
|
-
logger.log(`${
|
|
1170
|
+
logger.log(`${chalk6.green("success")} - CMS webhook URLs file created`);
|
|
1005
1171
|
} catch (err) {
|
|
1006
|
-
logger.error(`${
|
|
1172
|
+
logger.error(`${chalk6.red("error")} - ${err}`);
|
|
1007
1173
|
}
|
|
1008
1174
|
} else {
|
|
1009
|
-
logger.info(`${
|
|
1175
|
+
logger.info(`${chalk6.blue("info")} - No CMS webhook URLs were provided`);
|
|
1010
1176
|
}
|
|
1011
1177
|
}
|
|
1012
1178
|
async function copyTheme(basePath) {
|
|
@@ -1016,38 +1182,38 @@ async function copyTheme(basePath) {
|
|
|
1016
1182
|
tmpThemesCustomizationsFile,
|
|
1017
1183
|
userLegacyStoreConfigFile
|
|
1018
1184
|
} = withBasePath(basePath);
|
|
1019
|
-
const storeConfigFile =
|
|
1020
|
-
const userStoreConfigFilePath = storeConfigFile &&
|
|
1021
|
-
const importedStoreConfig = userStoreConfigFilePath && await import(
|
|
1185
|
+
const storeConfigFile = existsSync7(userStoreConfigFile) && userStoreConfigFile || existsSync7(userLegacyStoreConfigFile) && userLegacyStoreConfigFile;
|
|
1186
|
+
const userStoreConfigFilePath = storeConfigFile && path7.resolve(storeConfigFile);
|
|
1187
|
+
const importedStoreConfig = userStoreConfigFilePath && await import(pathToFileURL5(userStoreConfigFilePath).href);
|
|
1022
1188
|
const storeConfig = userStoreConfigFilePath && (importedStoreConfig?.default || importedStoreConfig);
|
|
1023
1189
|
if (!storeConfig)
|
|
1024
1190
|
logger.info(
|
|
1025
|
-
`${
|
|
1191
|
+
`${chalk6.blue(
|
|
1026
1192
|
"info"
|
|
1027
1193
|
)} - No store config file was found in the root directory`
|
|
1028
1194
|
);
|
|
1029
1195
|
if (storeConfig.theme) {
|
|
1030
|
-
const customTheme =
|
|
1196
|
+
const customTheme = path7.join(
|
|
1031
1197
|
userThemesFileDir,
|
|
1032
1198
|
`${storeConfig.theme}.scss`
|
|
1033
1199
|
);
|
|
1034
|
-
if (
|
|
1200
|
+
if (existsSync7(customTheme)) {
|
|
1035
1201
|
try {
|
|
1036
1202
|
copyFileSync(customTheme, tmpThemesCustomizationsFile);
|
|
1037
1203
|
logger.log(
|
|
1038
|
-
`${
|
|
1204
|
+
`${chalk6.green("success")} - ${storeConfig.theme} theme has been applied`
|
|
1039
1205
|
);
|
|
1040
1206
|
} catch (err) {
|
|
1041
|
-
logger.error(`${
|
|
1207
|
+
logger.error(`${chalk6.red("error")} - ${err}`);
|
|
1042
1208
|
}
|
|
1043
1209
|
} else {
|
|
1044
1210
|
logger.info(
|
|
1045
|
-
`${
|
|
1211
|
+
`${chalk6.blue("info")} - The ${storeConfig.theme} theme was added to the config file but the ${storeConfig.theme}.scss file does not exist in the themes folder. Read more: https://developers.vtex.com/docs/guides/faststore/themes-overview`
|
|
1046
1212
|
);
|
|
1047
1213
|
}
|
|
1048
|
-
} else if (
|
|
1214
|
+
} else if (existsSync7(userThemesFileDir) && readdirSync3(userThemesFileDir).length > 0) {
|
|
1049
1215
|
logger.info(
|
|
1050
|
-
`${
|
|
1216
|
+
`${chalk6.blue(
|
|
1051
1217
|
"info"
|
|
1052
1218
|
)} - The theme needs to be added to the config file to be applied. Read more: https://www.faststore.dev/docs/themes/overview`
|
|
1053
1219
|
);
|
|
@@ -1063,19 +1229,19 @@ function updateBuildTime(basePath) {
|
|
|
1063
1229
|
`const buildTime = '${newBuildTime}';`
|
|
1064
1230
|
);
|
|
1065
1231
|
writeFileSync2(tmpSeoConfig, config);
|
|
1066
|
-
logger.log(`${
|
|
1232
|
+
logger.log(`${chalk6.green("success")} - Build time updated`, newBuildTime);
|
|
1067
1233
|
} catch (error) {
|
|
1068
|
-
logger.error(`${
|
|
1234
|
+
logger.error(`${chalk6.red("error")} - Updating build time:`, error);
|
|
1069
1235
|
}
|
|
1070
1236
|
}
|
|
1071
1237
|
async function checkDependencies(basePath, packagesToCheck) {
|
|
1072
1238
|
const { coreDir, getRoot } = withBasePath(basePath);
|
|
1073
|
-
const corePackageJsonPath =
|
|
1074
|
-
const rootPackageJsonPath =
|
|
1075
|
-
const { default: corePackageJson } = await import(
|
|
1239
|
+
const corePackageJsonPath = path7.join(coreDir, "package.json");
|
|
1240
|
+
const rootPackageJsonPath = path7.join(getRoot(), "package.json");
|
|
1241
|
+
const { default: corePackageJson } = await import(pathToFileURL5(corePackageJsonPath).href, {
|
|
1076
1242
|
with: { type: "json" }
|
|
1077
1243
|
});
|
|
1078
|
-
const { default: rootPackageJson } = await import(
|
|
1244
|
+
const { default: rootPackageJson } = await import(pathToFileURL5(rootPackageJsonPath).href, {
|
|
1079
1245
|
with: { type: "json" }
|
|
1080
1246
|
});
|
|
1081
1247
|
packagesToCheck.forEach((packageName) => {
|
|
@@ -1083,13 +1249,13 @@ async function checkDependencies(basePath, packagesToCheck) {
|
|
|
1083
1249
|
const rootVersion = rootPackageJson.devDependencies[packageName] || rootPackageJson.dependencies[packageName];
|
|
1084
1250
|
if (!coreVersion || !rootVersion) {
|
|
1085
1251
|
logger.warn(
|
|
1086
|
-
`${
|
|
1252
|
+
`${chalk6.yellow(
|
|
1087
1253
|
"warning"
|
|
1088
1254
|
)} - Package ${packageName} not found in both core or root dependencies.`
|
|
1089
1255
|
);
|
|
1090
1256
|
} else if (coreVersion !== rootVersion) {
|
|
1091
1257
|
logger.warn(
|
|
1092
|
-
`${
|
|
1258
|
+
`${chalk6.yellow(
|
|
1093
1259
|
"warning"
|
|
1094
1260
|
)} - Version mismatch detected for ${packageName}.
|
|
1095
1261
|
Core: ${coreVersion}, Customization: ${rootVersion}. Please align both versions to prevent issues`
|
|
@@ -1099,7 +1265,7 @@ async function checkDependencies(basePath, packagesToCheck) {
|
|
|
1099
1265
|
}
|
|
1100
1266
|
function updateNextConfig(basePath) {
|
|
1101
1267
|
const { tmpDir } = withBasePath(basePath);
|
|
1102
|
-
const nextConfigPath =
|
|
1268
|
+
const nextConfigPath = path7.join(tmpDir, "next.config.js");
|
|
1103
1269
|
let nextConfigData = String(readFileSync(nextConfigPath));
|
|
1104
1270
|
nextConfigData = nextConfigData.replace(
|
|
1105
1271
|
/outputFileTracingRoot\:\s+(.*),/,
|
|
@@ -1109,10 +1275,10 @@ function updateNextConfig(basePath) {
|
|
|
1109
1275
|
}
|
|
1110
1276
|
function getCurrentUserStoreConfigFile(basePath) {
|
|
1111
1277
|
const { userStoreConfigFile, userLegacyStoreConfigFile } = withBasePath(basePath);
|
|
1112
|
-
if (
|
|
1278
|
+
if (existsSync7(userStoreConfigFile)) {
|
|
1113
1279
|
return userStoreConfigFile;
|
|
1114
1280
|
}
|
|
1115
|
-
if (
|
|
1281
|
+
if (existsSync7(userLegacyStoreConfigFile)) {
|
|
1116
1282
|
return userLegacyStoreConfigFile;
|
|
1117
1283
|
}
|
|
1118
1284
|
return null;
|
|
@@ -1123,8 +1289,8 @@ async function validateAndInstallMissingDependencies(basePath) {
|
|
|
1123
1289
|
if (!currentUserStoreConfigFile) {
|
|
1124
1290
|
return;
|
|
1125
1291
|
}
|
|
1126
|
-
const { default: userStoreConfig } = await import(
|
|
1127
|
-
const { default: userPackageJson } = await import(
|
|
1292
|
+
const { default: userStoreConfig } = await import(pathToFileURL5(currentUserStoreConfigFile).href);
|
|
1293
|
+
const { default: userPackageJson } = await import(pathToFileURL5(path7.join(userDir, "package.json")).href, {
|
|
1128
1294
|
with: { type: "json" }
|
|
1129
1295
|
});
|
|
1130
1296
|
const missingDependencies = [];
|
|
@@ -1158,12 +1324,12 @@ async function enableSearchSSR(basePath) {
|
|
|
1158
1324
|
if (!storeConfigPath) {
|
|
1159
1325
|
return;
|
|
1160
1326
|
}
|
|
1161
|
-
const { default: storeConfig } = await import(
|
|
1327
|
+
const { default: storeConfig } = await import(pathToFileURL5(storeConfigPath).href);
|
|
1162
1328
|
if (!storeConfig.experimental.enableSearchSSR) {
|
|
1163
1329
|
return;
|
|
1164
1330
|
}
|
|
1165
1331
|
const { tmpDir } = withBasePath(basePath);
|
|
1166
|
-
const searchPagePath =
|
|
1332
|
+
const searchPagePath = path7.join(tmpDir, "src", "pages", "s.tsx");
|
|
1167
1333
|
const searchPageData = String(readFileSync(searchPagePath));
|
|
1168
1334
|
const searchPageWithSSR = searchPageData.replaceAll(
|
|
1169
1335
|
"getStaticProps",
|
|
@@ -1197,12 +1363,12 @@ async function generate(options) {
|
|
|
1197
1363
|
}
|
|
1198
1364
|
|
|
1199
1365
|
// src/utils/hcms.ts
|
|
1200
|
-
import
|
|
1201
|
-
import
|
|
1366
|
+
import chalk7 from "chalk";
|
|
1367
|
+
import path8 from "path";
|
|
1202
1368
|
import { confirm } from "@inquirer/prompts";
|
|
1203
1369
|
import fsExtra5 from "fs-extra";
|
|
1204
|
-
import { pathToFileURL as
|
|
1205
|
-
var { readFileSync: readFileSync2, existsSync:
|
|
1370
|
+
import { pathToFileURL as pathToFileURL6 } from "url";
|
|
1371
|
+
var { readFileSync: readFileSync2, existsSync: existsSync8, writeFileSync: writeFileSync3, mkdirSync: mkdirSync3 } = fsExtra5;
|
|
1206
1372
|
function splitCustomDefinitions(coreDefinitions, customDefinitions, primaryIdentifier) {
|
|
1207
1373
|
const coreDefinitionIdentifiers = new Set(
|
|
1208
1374
|
coreDefinitions.map((definition) => definition[primaryIdentifier] ?? "")
|
|
@@ -1266,10 +1432,10 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1266
1432
|
getPackagePath,
|
|
1267
1433
|
userStoreConfigFile
|
|
1268
1434
|
} = withBasePath(basePath);
|
|
1269
|
-
const { default: userStoreConfig } = await import(
|
|
1435
|
+
const { default: userStoreConfig } = await import(pathToFileURL6(path8.resolve(userStoreConfigFile)).href);
|
|
1270
1436
|
const cmsProjectName = userStoreConfig.contentSource?.project ?? "faststore";
|
|
1271
|
-
const coreFilePath =
|
|
1272
|
-
const customFilePath =
|
|
1437
|
+
const coreFilePath = path8.join(coreCMSDir, fileName);
|
|
1438
|
+
const customFilePath = path8.join(userCMSDir, fileName);
|
|
1273
1439
|
const coreFile = readFileSync2(coreFilePath, "utf8");
|
|
1274
1440
|
const coreDefinitions = JSON.parse(coreFile);
|
|
1275
1441
|
const primaryIdentifierForDefinitions = fileName === "content-types.json" ? "id" : "name";
|
|
@@ -1279,7 +1445,7 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1279
1445
|
(plugin) => getPackagePath(getPluginName(plugin), "cms", "faststore", fileName)
|
|
1280
1446
|
);
|
|
1281
1447
|
const customizations = [...pluginCMSFilePaths, customFilePath].filter(
|
|
1282
|
-
(pluginCMSFilePath) =>
|
|
1448
|
+
(pluginCMSFilePath) => existsSync8(pluginCMSFilePath)
|
|
1283
1449
|
);
|
|
1284
1450
|
for (const newFilePath of customizations) {
|
|
1285
1451
|
const customFile = readFileSync2(newFilePath, "utf8");
|
|
@@ -1308,7 +1474,7 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1308
1474
|
} catch (err) {
|
|
1309
1475
|
if (err instanceof SyntaxError) {
|
|
1310
1476
|
console.info(
|
|
1311
|
-
`${
|
|
1477
|
+
`${chalk7.red(
|
|
1312
1478
|
"error"
|
|
1313
1479
|
)} - ${fileName} is a malformed JSON file, ignoring its contents.`
|
|
1314
1480
|
);
|
|
@@ -1318,18 +1484,18 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1318
1484
|
}
|
|
1319
1485
|
}
|
|
1320
1486
|
try {
|
|
1321
|
-
if (!
|
|
1322
|
-
|
|
1487
|
+
if (!existsSync8(tmpCMSDir(cmsProjectName))) {
|
|
1488
|
+
mkdirSync3(tmpCMSDir(cmsProjectName));
|
|
1323
1489
|
}
|
|
1324
1490
|
writeFileSync3(
|
|
1325
|
-
|
|
1491
|
+
path8.join(tmpCMSDir(cmsProjectName), fileName),
|
|
1326
1492
|
JSON.stringify(output)
|
|
1327
1493
|
);
|
|
1328
1494
|
console.log(
|
|
1329
|
-
`${
|
|
1495
|
+
`${chalk7.green("success")} - CMS file ${chalk7.dim(fileName)} created`
|
|
1330
1496
|
);
|
|
1331
1497
|
} catch (err) {
|
|
1332
|
-
console.error(`${
|
|
1498
|
+
console.error(`${chalk7.red("error")} - ${err}`);
|
|
1333
1499
|
}
|
|
1334
1500
|
}
|
|
1335
1501
|
async function mergeCMSFiles(basePath) {
|
|
@@ -1337,13 +1503,83 @@ async function mergeCMSFiles(basePath) {
|
|
|
1337
1503
|
await mergeCMSFile("content-types.json", basePath);
|
|
1338
1504
|
await mergeCMSFile("sections.json", basePath);
|
|
1339
1505
|
} catch (err) {
|
|
1340
|
-
console.error(`${
|
|
1506
|
+
console.error(`${chalk7.red("error")} - ${err}`);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// src/utils/vtex.ts
|
|
1511
|
+
import { execSync as execSync2 } from "child_process";
|
|
1512
|
+
import chalk8 from "chalk";
|
|
1513
|
+
function runCapture(cmd) {
|
|
1514
|
+
try {
|
|
1515
|
+
return execSync2(`${cmd} 2>&1`, { stdio: "pipe" }).toString();
|
|
1516
|
+
} catch {
|
|
1517
|
+
return null;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
function isVtexCliInstalled() {
|
|
1521
|
+
return runCapture("vtex --version") !== null;
|
|
1522
|
+
}
|
|
1523
|
+
function parseAccountFromWhoami(output) {
|
|
1524
|
+
if (/not logged|isn't logged|no user|please login/i.test(output)) {
|
|
1525
|
+
return null;
|
|
1526
|
+
}
|
|
1527
|
+
const patterns = [
|
|
1528
|
+
/@\s+([\w.-]+)\s*\//,
|
|
1529
|
+
// "user@vtex.com @ brandless / master"
|
|
1530
|
+
/logged in(?:to)?\s+(?:account\s+)?([\w.-]+)/i,
|
|
1531
|
+
// "Logged into brandless ..."
|
|
1532
|
+
/account[:\s]+([\w.-]+)/i
|
|
1533
|
+
// "... account brandless ..."
|
|
1534
|
+
];
|
|
1535
|
+
for (const pattern of patterns) {
|
|
1536
|
+
const match = output.match(pattern);
|
|
1537
|
+
if (match?.[1]) {
|
|
1538
|
+
return match[1];
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
function getLoggedVtexAccount() {
|
|
1544
|
+
const output = runCapture("vtex whoami");
|
|
1545
|
+
if (!output) {
|
|
1546
|
+
return null;
|
|
1547
|
+
}
|
|
1548
|
+
return parseAccountFromWhoami(output);
|
|
1549
|
+
}
|
|
1550
|
+
function assertVtexReadyForAccount(account) {
|
|
1551
|
+
if (!isVtexCliInstalled()) {
|
|
1552
|
+
logger.error(
|
|
1553
|
+
`${chalk8.red("[Error]")} - The VTEX toolbelt (\`vtex\`) was not found. Install it with ${chalk8.bold("npm i -g vtex")} and try again.
|
|
1554
|
+
${chalk8.dim("Docs: https://developers.vtex.com/docs/guides/vtex-io-documentation-vtex-io-cli-installation-and-command-reference")}`
|
|
1555
|
+
);
|
|
1556
|
+
process.exit(1);
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const loggedAccount = getLoggedVtexAccount();
|
|
1560
|
+
const loginHint = account ? `vtex login ${account}` : "vtex login <account>";
|
|
1561
|
+
if (!loggedAccount) {
|
|
1562
|
+
logger.error(
|
|
1563
|
+
`${chalk8.red("[Error]")} - You are not logged into the VTEX toolbelt.
|
|
1564
|
+
${chalk8.cyan("Required Action:")} log into the store account by running ${chalk8.bold(loginHint)}.`
|
|
1565
|
+
);
|
|
1566
|
+
process.exit(1);
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
if (account && loggedAccount.toLowerCase() !== account.toLowerCase()) {
|
|
1570
|
+
logger.error(
|
|
1571
|
+
`${chalk8.red("[Error]")} - You are logged into ${chalk8.bold(loggedAccount)}, but this store targets ${chalk8.bold(account)} (\`api.storeId\` in discovery.config.js).
|
|
1572
|
+
${chalk8.cyan("Required Action:")} switch accounts with ${chalk8.bold(`vtex switch ${account}`)} or ${chalk8.bold(loginHint)}.`
|
|
1573
|
+
);
|
|
1574
|
+
process.exit(1);
|
|
1341
1575
|
}
|
|
1342
1576
|
}
|
|
1343
1577
|
|
|
1344
1578
|
// src/commands/cms-sync.ts
|
|
1345
|
-
|
|
1346
|
-
|
|
1579
|
+
var CONTENT_SOURCE_ACTION = {
|
|
1580
|
+
CMS: "merging and syncing CMS content",
|
|
1581
|
+
CP: "generating and uploading schema"
|
|
1582
|
+
};
|
|
1347
1583
|
var CmsSync = class _CmsSync extends Command2 {
|
|
1348
1584
|
static flags = {
|
|
1349
1585
|
["dry-run"]: Flags2.boolean({ char: "d" })
|
|
@@ -1357,20 +1593,86 @@ var CmsSync = class _CmsSync extends Command2 {
|
|
|
1357
1593
|
async run() {
|
|
1358
1594
|
const { flags, args } = await this.parse(_CmsSync);
|
|
1359
1595
|
const basePath = getBasePath(args.path);
|
|
1360
|
-
const {
|
|
1361
|
-
const
|
|
1362
|
-
const
|
|
1596
|
+
const { userStoreConfigFile } = withBasePath(basePath);
|
|
1597
|
+
const storeConfig = existsSync9(userStoreConfigFile) ? (await import(pathToFileURL7(path9.resolve(userStoreConfigFile)).href)).default : null;
|
|
1598
|
+
const source = resolveContentSource(storeConfig?.contentSource?.type);
|
|
1599
|
+
logger.info(
|
|
1600
|
+
`${chalk9.blue("[Info]")} - Detected contentSource "${source}" \u2014 ${CONTENT_SOURCE_ACTION[source]}`
|
|
1601
|
+
);
|
|
1602
|
+
switch (source) {
|
|
1603
|
+
case "CMS":
|
|
1604
|
+
return this.runLegacySync({
|
|
1605
|
+
basePath,
|
|
1606
|
+
storeConfig,
|
|
1607
|
+
dryRun: flags["dry-run"]
|
|
1608
|
+
});
|
|
1609
|
+
case "CP":
|
|
1610
|
+
return this.runCpSync({
|
|
1611
|
+
basePath,
|
|
1612
|
+
storeConfig,
|
|
1613
|
+
dryRun: flags["dry-run"]
|
|
1614
|
+
});
|
|
1615
|
+
default: {
|
|
1616
|
+
return source;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
async runLegacySync({
|
|
1621
|
+
basePath,
|
|
1622
|
+
storeConfig,
|
|
1623
|
+
dryRun
|
|
1624
|
+
}) {
|
|
1625
|
+
const { tmpDir } = withBasePath(basePath);
|
|
1626
|
+
const project = storeConfig?.contentSource?.project ?? "faststore";
|
|
1363
1627
|
await generate({ setup: true, basePath });
|
|
1364
1628
|
await mergeCMSFiles(basePath);
|
|
1365
|
-
if (
|
|
1629
|
+
if (dryRun) {
|
|
1366
1630
|
return;
|
|
1367
1631
|
}
|
|
1368
|
-
return spawn(`vtex cms sync ${
|
|
1632
|
+
return spawn(`vtex cms sync ${project}`, {
|
|
1369
1633
|
shell: true,
|
|
1370
1634
|
cwd: tmpDir,
|
|
1371
1635
|
stdio: "inherit"
|
|
1372
1636
|
});
|
|
1373
1637
|
}
|
|
1638
|
+
runCpSync({
|
|
1639
|
+
basePath,
|
|
1640
|
+
storeConfig,
|
|
1641
|
+
dryRun
|
|
1642
|
+
}) {
|
|
1643
|
+
assertVtexReadyForAccount(storeConfig?.api?.storeId);
|
|
1644
|
+
let merge;
|
|
1645
|
+
if (isMyAccountEnabled(storeConfig)) {
|
|
1646
|
+
logger.info(
|
|
1647
|
+
`${chalk9.blue("[Info]")} - Merging My Account sections and content-types into the schema`
|
|
1648
|
+
);
|
|
1649
|
+
merge = prepareMyAccountMergeDir(basePath);
|
|
1650
|
+
}
|
|
1651
|
+
const dirs = merge ? merge.dirs : getExistingCpDirs(basePath);
|
|
1652
|
+
if (dirs.length === 0) {
|
|
1653
|
+
errorNoCustomization();
|
|
1654
|
+
}
|
|
1655
|
+
const schemaOut = getCpSchemaOutputPath(basePath);
|
|
1656
|
+
let cleanup;
|
|
1657
|
+
if (merge) {
|
|
1658
|
+
const { mergeDir } = merge;
|
|
1659
|
+
cleanup = () => cleanupMyAccountMergeDir(mergeDir);
|
|
1660
|
+
process.once("exit", cleanup);
|
|
1661
|
+
}
|
|
1662
|
+
try {
|
|
1663
|
+
generateAndUploadSchema({
|
|
1664
|
+
basePath,
|
|
1665
|
+
dirs,
|
|
1666
|
+
schemaOut,
|
|
1667
|
+
dryRun: dryRun ?? false
|
|
1668
|
+
});
|
|
1669
|
+
} finally {
|
|
1670
|
+
if (cleanup) {
|
|
1671
|
+
process.removeListener("exit", cleanup);
|
|
1672
|
+
cleanup();
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1374
1676
|
};
|
|
1375
1677
|
|
|
1376
1678
|
// src/commands/create.ts
|
|
@@ -1412,12 +1714,12 @@ var Create = class _Create extends Command3 {
|
|
|
1412
1714
|
|
|
1413
1715
|
// src/commands/dev.ts
|
|
1414
1716
|
import { Args as Args4, Command as Command4, Flags as Flags3 } from "@oclif/core";
|
|
1415
|
-
import
|
|
1717
|
+
import chalk10 from "chalk";
|
|
1416
1718
|
import { spawn as spawn2, spawnSync as spawnSync3 } from "child_process";
|
|
1417
1719
|
import chokidar from "chokidar";
|
|
1418
1720
|
import dotenv from "dotenv";
|
|
1419
|
-
import { cpSync, existsSync as
|
|
1420
|
-
import
|
|
1721
|
+
import { cpSync as cpSync2, existsSync as existsSync10, readFileSync as readFileSync3 } from "fs";
|
|
1722
|
+
import path10 from "path";
|
|
1421
1723
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1422
1724
|
var stabilityThreshold = process.platform === "darwin" ? 100 : 200;
|
|
1423
1725
|
var defaultPatterns = ["*/**", "**"];
|
|
@@ -1437,13 +1739,13 @@ var defaultNodeModulesIgnoredExceptVtexPackages = [
|
|
|
1437
1739
|
var devAbortController = new AbortController();
|
|
1438
1740
|
async function storeDev(rootDir, tmpDir, coreDir, port) {
|
|
1439
1741
|
let envVars = {};
|
|
1440
|
-
const vtexEnvPath =
|
|
1441
|
-
if (
|
|
1742
|
+
const vtexEnvPath = path10.join(rootDir, "vtex.env");
|
|
1743
|
+
if (existsSync10(vtexEnvPath)) {
|
|
1442
1744
|
try {
|
|
1443
1745
|
envVars = dotenv.parse(readFileSync3(vtexEnvPath));
|
|
1444
1746
|
} catch (err) {
|
|
1445
1747
|
logger.log(
|
|
1446
|
-
`${
|
|
1748
|
+
`${chalk10.yellow("warn")} - Error parsing vtex.env file: ${err}`
|
|
1447
1749
|
);
|
|
1448
1750
|
}
|
|
1449
1751
|
}
|
|
@@ -1455,15 +1757,15 @@ async function storeDev(rootDir, tmpDir, coreDir, port) {
|
|
|
1455
1757
|
cwd: tmpDir
|
|
1456
1758
|
});
|
|
1457
1759
|
const { success } = copyGenerated(
|
|
1458
|
-
|
|
1459
|
-
|
|
1760
|
+
path10.join(tmpDir, "@generated"),
|
|
1761
|
+
path10.join(coreDir, "@generated")
|
|
1460
1762
|
);
|
|
1461
1763
|
if (!success) {
|
|
1462
1764
|
logger.log(
|
|
1463
|
-
`${
|
|
1765
|
+
`${chalk10.yellow("warn")} - Failed to copy @generated schema back to node_modules, autocomplete and DX might be impacted.`
|
|
1464
1766
|
);
|
|
1465
1767
|
logger.log(
|
|
1466
|
-
`Attempted to copy from ${
|
|
1768
|
+
`Attempted to copy from ${path10.join(tmpDir, "@generated")} to ${path10.join(coreDir, "@generated")}`
|
|
1467
1769
|
);
|
|
1468
1770
|
}
|
|
1469
1771
|
const devProcess = spawn2(`${packageManager} dev-only --port ${port}`, {
|
|
@@ -1495,7 +1797,7 @@ async function storeDev(rootDir, tmpDir, coreDir, port) {
|
|
|
1495
1797
|
}
|
|
1496
1798
|
function copyGenerated(from, to) {
|
|
1497
1799
|
try {
|
|
1498
|
-
|
|
1800
|
+
cpSync2(from, to, { recursive: true, force: true, dereference: true });
|
|
1499
1801
|
return { success: true };
|
|
1500
1802
|
} catch (err) {
|
|
1501
1803
|
return { success: false };
|
|
@@ -1580,13 +1882,13 @@ var Dev = class _Dev extends Command4 {
|
|
|
1580
1882
|
|
|
1581
1883
|
// src/commands/generate.ts
|
|
1582
1884
|
import { Args as Args5, Command as Command5 } from "@oclif/core";
|
|
1583
|
-
import
|
|
1885
|
+
import chalk11 from "chalk";
|
|
1584
1886
|
|
|
1585
1887
|
// src/utils/file.ts
|
|
1586
1888
|
import fs3 from "fs";
|
|
1587
|
-
import
|
|
1889
|
+
import path11 from "path";
|
|
1588
1890
|
function saveFile(fileLocation) {
|
|
1589
|
-
fs3.mkdirSync(
|
|
1891
|
+
fs3.mkdirSync(path11.dirname(fileLocation), { recursive: true });
|
|
1590
1892
|
return (content) => {
|
|
1591
1893
|
fs3.writeFileSync(fileLocation, content);
|
|
1592
1894
|
};
|
|
@@ -1600,17 +1902,17 @@ import {
|
|
|
1600
1902
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
1601
1903
|
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
1602
1904
|
import { buildASTSchema, Kind, parse } from "graphql";
|
|
1603
|
-
import fs4, { existsSync as
|
|
1604
|
-
import
|
|
1905
|
+
import fs4, { existsSync as existsSync11 } from "fs";
|
|
1906
|
+
import path12 from "path";
|
|
1605
1907
|
var schemaFileName = "schema.graphql";
|
|
1606
1908
|
async function genTsTypes(at) {
|
|
1607
1909
|
await generateSchemaFile(at);
|
|
1608
1910
|
generateSchemaTSTypes(at);
|
|
1609
1911
|
}
|
|
1610
1912
|
function generateSchemaTSTypes(root) {
|
|
1611
|
-
let finalRootPath =
|
|
1612
|
-
if (
|
|
1613
|
-
finalRootPath =
|
|
1913
|
+
let finalRootPath = path12.resolve(root);
|
|
1914
|
+
if (existsSync11(path12.resolve(root, ".faststore"))) {
|
|
1915
|
+
finalRootPath = path12.resolve(root, ".faststore");
|
|
1614
1916
|
}
|
|
1615
1917
|
const documents = [`${finalRootPath}/src/**/*.{ts,tsx}`];
|
|
1616
1918
|
const config = {
|
|
@@ -1619,7 +1921,7 @@ function generateSchemaTSTypes(root) {
|
|
|
1619
1921
|
errorsOnly: false,
|
|
1620
1922
|
debug: false,
|
|
1621
1923
|
verbose: true,
|
|
1622
|
-
schema:
|
|
1924
|
+
schema: path12.resolve(finalRootPath, "@generated", schemaFileName),
|
|
1623
1925
|
generates: {
|
|
1624
1926
|
[`${finalRootPath}/@generated/`]: {
|
|
1625
1927
|
preset: "client",
|
|
@@ -1670,7 +1972,7 @@ function getOperationName(document) {
|
|
|
1670
1972
|
async function generateSchemaFile(rootPath) {
|
|
1671
1973
|
const faststoreSchema = printSchemaWithDirectives(GraphqlVtexSchema());
|
|
1672
1974
|
const getMergedSchema = async () => {
|
|
1673
|
-
const root =
|
|
1975
|
+
const root = path12.join(
|
|
1674
1976
|
rootPath.endsWith(".faststore") ? [rootPath, ".."].join("/") : rootPath
|
|
1675
1977
|
);
|
|
1676
1978
|
const customizations = [
|
|
@@ -1689,9 +1991,9 @@ async function generateSchemaFile(rootPath) {
|
|
|
1689
1991
|
throw e;
|
|
1690
1992
|
}
|
|
1691
1993
|
};
|
|
1692
|
-
let pathToSave =
|
|
1693
|
-
if (
|
|
1694
|
-
pathToSave =
|
|
1994
|
+
let pathToSave = path12.resolve(rootPath, "@generated", schemaFileName);
|
|
1995
|
+
if (existsSync11(path12.resolve(rootPath, ".faststore"))) {
|
|
1996
|
+
pathToSave = path12.resolve(
|
|
1695
1997
|
rootPath,
|
|
1696
1998
|
".faststore",
|
|
1697
1999
|
"@generated",
|
|
@@ -1706,7 +2008,7 @@ async function getTypeDefsFromFolder(root, customPath) {
|
|
|
1706
2008
|
const globby = await import("globby");
|
|
1707
2009
|
const basePath = [root, "src", "graphql"];
|
|
1708
2010
|
const pathArray = Array.isArray(customPath) ? customPath : [customPath];
|
|
1709
|
-
return (globby.default ?? globby).globbySync(
|
|
2011
|
+
return (globby.default ?? globby).globbySync(path12.join(...[...basePath, ...pathArray]), {
|
|
1710
2012
|
expandDirectories: {
|
|
1711
2013
|
extensions: ["graphql"]
|
|
1712
2014
|
}
|
|
@@ -1732,7 +2034,7 @@ var Generate = class _Generate extends Command5 {
|
|
|
1732
2034
|
await generate({ setup: true, basePath });
|
|
1733
2035
|
genTsTypes(args.path ?? tmpDir);
|
|
1734
2036
|
logger.log(
|
|
1735
|
-
`${
|
|
2037
|
+
`${chalk11.green(
|
|
1736
2038
|
"success"
|
|
1737
2039
|
)} - GraphQL schema, types, and optimizations successfully generated \u{1F389}`
|
|
1738
2040
|
);
|
|
@@ -1742,7 +2044,7 @@ var Generate = class _Generate extends Command5 {
|
|
|
1742
2044
|
// src/commands/prepare.ts
|
|
1743
2045
|
import { Args as Args6, Command as Command6 } from "@oclif/core";
|
|
1744
2046
|
import fs5 from "fs";
|
|
1745
|
-
import
|
|
2047
|
+
import path13 from "path";
|
|
1746
2048
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1747
2049
|
var Prepare = class _Prepare extends Command6 {
|
|
1748
2050
|
static args = {
|
|
@@ -1754,10 +2056,10 @@ var Prepare = class _Prepare extends Command6 {
|
|
|
1754
2056
|
async run() {
|
|
1755
2057
|
const { args } = await this.parse(_Prepare);
|
|
1756
2058
|
const basePath = getBasePath(args.path);
|
|
1757
|
-
const clientPublicDir =
|
|
1758
|
-
const corePublicDir =
|
|
2059
|
+
const clientPublicDir = path13.join(basePath, "public/");
|
|
2060
|
+
const corePublicDir = path13.resolve(
|
|
1759
2061
|
fileURLToPath4(
|
|
1760
|
-
|
|
2062
|
+
path13.dirname(import.meta.resolve("@faststore/core", import.meta.url))
|
|
1761
2063
|
),
|
|
1762
2064
|
"public"
|
|
1763
2065
|
);
|
|
@@ -1773,8 +2075,8 @@ function copyFolder(sourceDir, targetDir) {
|
|
|
1773
2075
|
}
|
|
1774
2076
|
const files = fs5.readdirSync(sourceDir);
|
|
1775
2077
|
for (const file of files) {
|
|
1776
|
-
const sourcePath =
|
|
1777
|
-
const targetPath =
|
|
2078
|
+
const sourcePath = path13.join(sourceDir, file);
|
|
2079
|
+
const targetPath = path13.join(targetDir, file);
|
|
1778
2080
|
const stat = fs5.statSync(sourcePath);
|
|
1779
2081
|
if (stat.isFile()) {
|
|
1780
2082
|
fs5.copyFileSync(sourcePath, targetPath);
|
|
@@ -1789,8 +2091,8 @@ function copyFolder(sourceDir, targetDir) {
|
|
|
1789
2091
|
import { Args as Args7, Command as Command7 } from "@oclif/core";
|
|
1790
2092
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "child_process";
|
|
1791
2093
|
import fsExtra6 from "fs-extra";
|
|
1792
|
-
import
|
|
1793
|
-
var { existsSync:
|
|
2094
|
+
import path14 from "path";
|
|
2095
|
+
var { existsSync: existsSync12 } = fsExtra6;
|
|
1794
2096
|
var Start = class _Start extends Command7 {
|
|
1795
2097
|
static args = {
|
|
1796
2098
|
account: Args7.string({
|
|
@@ -1809,7 +2111,7 @@ var Start = class _Start extends Command7 {
|
|
|
1809
2111
|
const port = args.port ?? 3e3;
|
|
1810
2112
|
const { getRoot, tmpDir } = withBasePath(basePath);
|
|
1811
2113
|
const packageManager = await getPreferredPackageManager();
|
|
1812
|
-
if (!
|
|
2114
|
+
if (!existsSync12(path14.join(getRoot(), ".next"))) {
|
|
1813
2115
|
spawnSync4(`${packageManager} faststore build`, {
|
|
1814
2116
|
shell: true,
|
|
1815
2117
|
stdio: "inherit"
|
|
@@ -1892,9 +2194,9 @@ var Test = class _Test extends Command8 {
|
|
|
1892
2194
|
};
|
|
1893
2195
|
|
|
1894
2196
|
// src/commands/generate-types.ts
|
|
1895
|
-
import
|
|
2197
|
+
import path15 from "path";
|
|
1896
2198
|
import { Args as Args9, Command as Command9 } from "@oclif/core";
|
|
1897
|
-
import
|
|
2199
|
+
import chalk12 from "chalk";
|
|
1898
2200
|
var Generate2 = class _Generate extends Command9 {
|
|
1899
2201
|
static hidden = true;
|
|
1900
2202
|
static flags = {};
|
|
@@ -1908,10 +2210,10 @@ var Generate2 = class _Generate extends Command9 {
|
|
|
1908
2210
|
async run() {
|
|
1909
2211
|
const { args } = await this.parse(_Generate);
|
|
1910
2212
|
await genTsTypes(
|
|
1911
|
-
|
|
2213
|
+
path15.isAbsolute(args.path) ? args.path : path15.resolve(process.env.PWD ?? process.cwd(), args.path)
|
|
1912
2214
|
);
|
|
1913
2215
|
logger.log(
|
|
1914
|
-
`${
|
|
2216
|
+
`${chalk12.green(
|
|
1915
2217
|
"success"
|
|
1916
2218
|
)} - GraphQL schema, types, and optimizations successfully generated \u{1F389}`
|
|
1917
2219
|
);
|
|
@@ -1920,14 +2222,14 @@ var Generate2 = class _Generate extends Command9 {
|
|
|
1920
2222
|
|
|
1921
2223
|
// src/commands/cache-graphql.ts
|
|
1922
2224
|
import { Args as Args10, Command as Command10, Flags as Flags4 } from "@oclif/core";
|
|
1923
|
-
import
|
|
2225
|
+
import chalk13 from "chalk";
|
|
1924
2226
|
import fsExtra7 from "fs-extra";
|
|
1925
2227
|
import graphql from "graphql";
|
|
1926
|
-
import
|
|
1927
|
-
import { pathToFileURL as
|
|
2228
|
+
import path16 from "path";
|
|
2229
|
+
import { pathToFileURL as pathToFileURL8 } from "url";
|
|
1928
2230
|
var { Kind: Kind2, OperationTypeNode, parse: parseGraphql } = graphql;
|
|
1929
2231
|
var persistedDocumentsName = "persisted-documents.json";
|
|
1930
|
-
var
|
|
2232
|
+
var configFileName2 = "discovery.config.default.js";
|
|
1931
2233
|
var cachedOperationsFileName = "cached-operations.json";
|
|
1932
2234
|
var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
1933
2235
|
static flags = {
|
|
@@ -1949,15 +2251,15 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
1949
2251
|
async run() {
|
|
1950
2252
|
const { args, flags } = await this.parse(_CacheGraphql);
|
|
1951
2253
|
const rootPath = getBasePath();
|
|
1952
|
-
const argPath = args?.store &&
|
|
2254
|
+
const argPath = args?.store && path16.resolve(rootPath, args.store) || rootPath;
|
|
1953
2255
|
const { tmpDir } = withBasePath(argPath);
|
|
1954
|
-
const configPath = this.getConfigFile(flags.config &&
|
|
2256
|
+
const configPath = this.getConfigFile(flags.config && path16.resolve(argPath, flags.config)) || this.getConfigFile(tmpDir) || this.getConfigFile(argPath);
|
|
1955
2257
|
const persistedDocumentsPath = this.getPersistedDocument(
|
|
1956
|
-
flags?.queries &&
|
|
2258
|
+
flags?.queries && path16.resolve(argPath, flags?.queries) || argPath
|
|
1957
2259
|
) || this.getPersistedDocument(tmpDir);
|
|
1958
2260
|
if (!configPath) {
|
|
1959
2261
|
return this.errorFileNotFound(
|
|
1960
|
-
|
|
2262
|
+
configFileName2,
|
|
1961
2263
|
`
|
|
1962
2264
|
${tmpDir}
|
|
1963
2265
|
${argPath}`
|
|
@@ -1969,28 +2271,28 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
1969
2271
|
flags?.queries ?? argPath
|
|
1970
2272
|
);
|
|
1971
2273
|
}
|
|
1972
|
-
const cachedOperationsPath =
|
|
1973
|
-
|
|
2274
|
+
const cachedOperationsPath = path16.join(
|
|
2275
|
+
path16.dirname(persistedDocumentsPath),
|
|
1974
2276
|
cachedOperationsFileName
|
|
1975
2277
|
);
|
|
1976
2278
|
const saveCachedOperationsFile = saveFile(cachedOperationsPath);
|
|
1977
2279
|
if (fsExtra7.pathExistsSync(tmpDir))
|
|
1978
|
-
logger.info(`${
|
|
1979
|
-
logger.info(`${
|
|
2280
|
+
logger.info(`${chalk13.blue("[Info]")} - .faststore Path at: ${tmpDir}`);
|
|
2281
|
+
logger.info(`${chalk13.blue("[Info]")} - Config file location: ${configPath}`);
|
|
1980
2282
|
logger.info(
|
|
1981
|
-
`${
|
|
2283
|
+
`${chalk13.blue("[Info]")} - Persisted documents at: ${persistedDocumentsPath}`
|
|
1982
2284
|
);
|
|
1983
2285
|
logger.info(
|
|
1984
|
-
`${
|
|
2286
|
+
`${chalk13.blue("[Info]")} - Cached operations output: ${cachedOperationsPath}`
|
|
1985
2287
|
);
|
|
1986
|
-
const { default: persistedDocuments } = await import(
|
|
2288
|
+
const { default: persistedDocuments } = await import(pathToFileURL8(persistedDocumentsPath).href, { with: { type: "json" } });
|
|
1987
2289
|
const cachedQueries = getQueries(persistedDocuments);
|
|
1988
2290
|
saveCachedOperationsFile(
|
|
1989
2291
|
`${JSON.stringify(cachedQueries ?? [], null, 2)}
|
|
1990
2292
|
`
|
|
1991
2293
|
);
|
|
1992
2294
|
logger.info(
|
|
1993
|
-
`${
|
|
2295
|
+
`${chalk13.green("[Success]")} - GraphQL queries cached with success: \u{1F389}
|
|
1994
2296
|
Queries: ${cachedQueries.join(", ")}`
|
|
1995
2297
|
);
|
|
1996
2298
|
}
|
|
@@ -2001,7 +2303,7 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2001
2303
|
])(rootPath);
|
|
2002
2304
|
}
|
|
2003
2305
|
getConfigFile(rootPath) {
|
|
2004
|
-
return this.getFile(
|
|
2306
|
+
return this.getFile(configFileName2, [configFileName2])(rootPath);
|
|
2005
2307
|
}
|
|
2006
2308
|
getFile(fileName, pathFromRoot) {
|
|
2007
2309
|
return (rootPath) => {
|
|
@@ -2010,11 +2312,11 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2010
2312
|
return;
|
|
2011
2313
|
case (rootPath?.endsWith(fileName) && fsExtra7.existsSync(rootPath)):
|
|
2012
2314
|
return rootPath;
|
|
2013
|
-
case fsExtra7.existsSync(
|
|
2014
|
-
return
|
|
2315
|
+
case fsExtra7.existsSync(path16.join(rootPath ?? "", fileName)):
|
|
2316
|
+
return path16.join(rootPath, fileName);
|
|
2015
2317
|
default:
|
|
2016
2318
|
if (!pathFromRoot) return;
|
|
2017
|
-
const filePath =
|
|
2319
|
+
const filePath = path16.join(
|
|
2018
2320
|
rootPath,
|
|
2019
2321
|
...Array.isArray(pathFromRoot) ? pathFromRoot : [pathFromRoot]
|
|
2020
2322
|
);
|
|
@@ -2027,7 +2329,7 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2027
2329
|
}
|
|
2028
2330
|
errorFileNotFound(fileName, rootDir) {
|
|
2029
2331
|
logger.error(
|
|
2030
|
-
`${
|
|
2332
|
+
`${chalk13.red("[Error]")} - Couldn't find ${fileName} at ${rootDir}`
|
|
2031
2333
|
);
|
|
2032
2334
|
process.exit(1);
|
|
2033
2335
|
}
|
|
@@ -2058,75 +2360,12 @@ var getQueries = (persistedDocuments) => {
|
|
|
2058
2360
|
// src/commands/generate-i18n.ts
|
|
2059
2361
|
import { Args as Args11, Command as Command11, Flags as Flags5 } from "@oclif/core";
|
|
2060
2362
|
import { FastStoreSDK } from "@vtex/faststore-sdk";
|
|
2061
|
-
import
|
|
2363
|
+
import chalk14 from "chalk";
|
|
2062
2364
|
import dotenv2 from "dotenv";
|
|
2063
2365
|
import fsExtra8 from "fs-extra";
|
|
2064
|
-
import { existsSync as
|
|
2065
|
-
import
|
|
2366
|
+
import { existsSync as existsSync13 } from "fs";
|
|
2367
|
+
import path17 from "path";
|
|
2066
2368
|
import { format } from "prettier";
|
|
2067
|
-
|
|
2068
|
-
// src/utils/config.ts
|
|
2069
|
-
import chalk10 from "chalk";
|
|
2070
|
-
import { existsSync as existsSync10 } from "fs";
|
|
2071
|
-
import path15 from "path";
|
|
2072
|
-
import { pathToFileURL as pathToFileURL8 } from "url";
|
|
2073
|
-
var configFileName2 = "discovery.config.js";
|
|
2074
|
-
async function getDiscoveryConfig(basePath) {
|
|
2075
|
-
const { tmpDir } = withBasePath(basePath);
|
|
2076
|
-
const configPaths = [
|
|
2077
|
-
path15.join(tmpDir, configFileName2),
|
|
2078
|
-
path15.join(basePath, configFileName2)
|
|
2079
|
-
];
|
|
2080
|
-
for (const configPath of configPaths) {
|
|
2081
|
-
if (existsSync10(configPath)) {
|
|
2082
|
-
try {
|
|
2083
|
-
const discoveryConfig = await import(pathToFileURL8(configPath).href);
|
|
2084
|
-
return discoveryConfig?.default ?? discoveryConfig;
|
|
2085
|
-
} catch (error) {
|
|
2086
|
-
logger.warn(
|
|
2087
|
-
`${chalk10.yellow("warning")} - Could not read config file: ${configPath}.`
|
|
2088
|
-
);
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
return null;
|
|
2093
|
-
}
|
|
2094
|
-
function isLocalizationEnabled(config) {
|
|
2095
|
-
return config?.localization?.enabled === true;
|
|
2096
|
-
}
|
|
2097
|
-
function validateContentSourceForLocalization(config) {
|
|
2098
|
-
if (!isLocalizationEnabled(config)) {
|
|
2099
|
-
return;
|
|
2100
|
-
}
|
|
2101
|
-
const currentContentSourceType = config?.contentSource?.type?.toUpperCase();
|
|
2102
|
-
if (currentContentSourceType !== "CP") {
|
|
2103
|
-
logger.error(
|
|
2104
|
-
`
|
|
2105
|
-
${chalk10.red("[Error]")} - Localization is enabled but contentSource is set to "${currentContentSourceType}".
|
|
2106
|
-
|
|
2107
|
-
${chalk10.cyan("Required Action:")}
|
|
2108
|
-
Update your ${chalk10.bold("discovery.config.js")} file:
|
|
2109
|
-
|
|
2110
|
-
contentSource: {
|
|
2111
|
-
type: ${chalk10.green('"CP"')}
|
|
2112
|
-
},
|
|
2113
|
-
|
|
2114
|
-
${chalk10.dim("When localization is enabled, Content Platform (CP) is required.")}
|
|
2115
|
-
`
|
|
2116
|
-
);
|
|
2117
|
-
process.exit(1);
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
async function checkAndValidateLocalization(basePath) {
|
|
2121
|
-
const config = await getDiscoveryConfig(basePath);
|
|
2122
|
-
if (!config) {
|
|
2123
|
-
return false;
|
|
2124
|
-
}
|
|
2125
|
-
validateContentSourceForLocalization(config);
|
|
2126
|
-
return isLocalizationEnabled(config);
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
// src/commands/generate-i18n.ts
|
|
2130
2369
|
import { pathToFileURL as pathToFileURL9 } from "url";
|
|
2131
2370
|
var configFileName3 = "discovery.config.default.js";
|
|
2132
2371
|
var GenerateI18n = class _GenerateI18n extends Command11 {
|
|
@@ -2153,11 +2392,11 @@ var GenerateI18n = class _GenerateI18n extends Command11 {
|
|
|
2153
2392
|
return;
|
|
2154
2393
|
case (rootPath?.endsWith(fileName) && fsExtra8.existsSync(rootPath)):
|
|
2155
2394
|
return rootPath;
|
|
2156
|
-
case fsExtra8.existsSync(
|
|
2157
|
-
return
|
|
2395
|
+
case fsExtra8.existsSync(path17.join(rootPath ?? "", fileName)):
|
|
2396
|
+
return path17.join(rootPath, fileName);
|
|
2158
2397
|
default:
|
|
2159
2398
|
if (!pathFromRoot) return;
|
|
2160
|
-
const filePath =
|
|
2399
|
+
const filePath = path17.join(
|
|
2161
2400
|
rootPath,
|
|
2162
2401
|
...Array.isArray(pathFromRoot) ? pathFromRoot : [pathFromRoot]
|
|
2163
2402
|
);
|
|
@@ -2170,37 +2409,37 @@ var GenerateI18n = class _GenerateI18n extends Command11 {
|
|
|
2170
2409
|
}
|
|
2171
2410
|
errorFileNotFound(fileName, rootDir) {
|
|
2172
2411
|
logger.error(
|
|
2173
|
-
`${
|
|
2412
|
+
`${chalk14.red("[Error]")} - Couldn't find ${fileName} at ${rootDir}`
|
|
2174
2413
|
);
|
|
2175
2414
|
process.exit(1);
|
|
2176
2415
|
}
|
|
2177
2416
|
async run() {
|
|
2178
2417
|
const { args, flags } = await this.parse(_GenerateI18n);
|
|
2179
2418
|
const rootPath = getBasePath();
|
|
2180
|
-
const argPath = args?.path &&
|
|
2419
|
+
const argPath = args?.path && path17.resolve(rootPath, args.path) || rootPath;
|
|
2181
2420
|
const localizationEnabled = await checkAndValidateLocalization(argPath);
|
|
2182
2421
|
if (!localizationEnabled) {
|
|
2183
2422
|
return;
|
|
2184
2423
|
}
|
|
2185
|
-
const vtexEnvPath =
|
|
2186
|
-
if (
|
|
2424
|
+
const vtexEnvPath = path17.join(argPath, "vtex.env");
|
|
2425
|
+
if (existsSync13(vtexEnvPath)) {
|
|
2187
2426
|
dotenv2.config({ path: vtexEnvPath });
|
|
2188
2427
|
}
|
|
2189
2428
|
const { VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, FS_DISCOVERY_APP_TOKEN } = process.env;
|
|
2190
2429
|
const hasCredentials = VTEX_ACCOUNT && FS_DISCOVERY_APP_KEY && FS_DISCOVERY_APP_TOKEN;
|
|
2191
2430
|
if (!hasCredentials) {
|
|
2192
|
-
logger.error(`${
|
|
2431
|
+
logger.error(`${chalk14.red("[Error]")} - Missing VTEX credentials.
|
|
2193
2432
|
|
|
2194
|
-
${
|
|
2433
|
+
${chalk14.cyan("Required Action:")}
|
|
2195
2434
|
|
|
2196
|
-
Check your FastStore WebOps Settings page - to work in production, it should contain the following variables: ${
|
|
2435
|
+
Check your FastStore WebOps Settings page - to work in production, it should contain the following variables: ${chalk14.cyan("VTEX_ACCOUNT")}, ${chalk14.cyan("FS_DISCOVERY_APP_KEY")}, ${chalk14.cyan("FS_DISCOVERY_APP_TOKEN")}.
|
|
2197
2436
|
|
|
2198
|
-
If running locally, please check your ${
|
|
2437
|
+
If running locally, please check your ${chalk14.bold("vtex.env")} file, it should also contain those variables.
|
|
2199
2438
|
`);
|
|
2200
2439
|
process.exit(1);
|
|
2201
2440
|
}
|
|
2202
2441
|
const { tmpDir } = withBasePath(argPath);
|
|
2203
|
-
const configPath = this.getConfigFile(flags.config &&
|
|
2442
|
+
const configPath = this.getConfigFile(flags.config && path17.resolve(argPath, flags.config)) || this.getConfigFile(tmpDir) || this.getConfigFile(argPath);
|
|
2204
2443
|
if (!configPath) {
|
|
2205
2444
|
return this.errorFileNotFound(
|
|
2206
2445
|
configFileName3,
|
|
@@ -2211,8 +2450,8 @@ var GenerateI18n = class _GenerateI18n extends Command11 {
|
|
|
2211
2450
|
}
|
|
2212
2451
|
const saveConfigFile = saveFile(configPath);
|
|
2213
2452
|
if (fsExtra8.pathExistsSync(tmpDir))
|
|
2214
|
-
logger.info(`${
|
|
2215
|
-
logger.info(`${
|
|
2453
|
+
logger.info(`${chalk14.blue("[Info]")} - .faststore Path at: ${tmpDir}`);
|
|
2454
|
+
logger.info(`${chalk14.blue("[Info]")} - Config file location: ${configPath}`);
|
|
2216
2455
|
const discoveryConfig = await import(pathToFileURL9(configPath).href);
|
|
2217
2456
|
const faststore = new FastStoreSDK({
|
|
2218
2457
|
account: VTEX_ACCOUNT,
|
|
@@ -2241,7 +2480,7 @@ var GenerateI18n = class _GenerateI18n extends Command11 {
|
|
|
2241
2480
|
)
|
|
2242
2481
|
);
|
|
2243
2482
|
logger.info(
|
|
2244
|
-
`${
|
|
2483
|
+
`${chalk14.green("success")} - i18n configuration successfully generated \u{1F389}`
|
|
2245
2484
|
);
|
|
2246
2485
|
}
|
|
2247
2486
|
};
|