@faststore/cli 4.3.0-dev.6 → 4.3.0-dev.8
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 +354 -377
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import { run } from "@oclif/core";
|
|
|
3
3
|
|
|
4
4
|
// src/commands/build.ts
|
|
5
5
|
import { Args, Command, Flags } from "@oclif/core";
|
|
6
|
-
import
|
|
6
|
+
import chalk2 from "chalk";
|
|
7
7
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
8
|
-
import { existsSync as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { fileURLToPath as fileURLToPath2, pathToFileURL as
|
|
8
|
+
import { existsSync as existsSync3 } from "fs";
|
|
9
|
+
import fsExtra2 from "fs-extra";
|
|
10
|
+
import path2 from "path";
|
|
11
|
+
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
|
|
12
12
|
|
|
13
13
|
// src/utils/commands.ts
|
|
14
14
|
import fsExtra from "fs-extra";
|
|
@@ -53,11 +53,43 @@ async function getDepPackageJSON(pkg) {
|
|
|
53
53
|
return await loadPackageJsonAt(await getPackageRootDir(pkg));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// src/utils/
|
|
57
|
-
import chalk from "chalk";
|
|
56
|
+
// src/utils/deprecations.ts
|
|
58
57
|
import { existsSync as existsSync2 } from "fs";
|
|
59
|
-
import
|
|
60
|
-
|
|
58
|
+
import chalk from "chalk";
|
|
59
|
+
|
|
60
|
+
// src/utils/logger.ts
|
|
61
|
+
var logger = new Proxy(console, {
|
|
62
|
+
get(target, prop) {
|
|
63
|
+
if (prop === "log") {
|
|
64
|
+
return (...args) => {
|
|
65
|
+
if (process.env.DISCOVERY_DEBUG === "true") {
|
|
66
|
+
target.log(...args);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return target[prop];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// src/utils/deprecations.ts
|
|
75
|
+
function checkDeprecatedSecretFiles(basePath) {
|
|
76
|
+
const secretsFilePath = `${basePath}/secrets.hidden.json`;
|
|
77
|
+
const vtexEnvFilePath = `${basePath}/vtex.env`;
|
|
78
|
+
const secretsFileExists = existsSync2(secretsFilePath);
|
|
79
|
+
const vtexEnvFileExists = existsSync2(vtexEnvFilePath);
|
|
80
|
+
if (secretsFileExists || vtexEnvFileExists) {
|
|
81
|
+
const filesFound = [
|
|
82
|
+
secretsFileExists ? "secrets.hidden.json" : null,
|
|
83
|
+
vtexEnvFileExists ? "vtex.env" : null
|
|
84
|
+
].filter(Boolean).join(" and ");
|
|
85
|
+
logger.warn(
|
|
86
|
+
`${chalk.yellow("warning")} - Deprecated secret files detected: ${chalk.bold(filesFound)}
|
|
87
|
+
Note: 'vtex.env' should only be used for local development and not in production.
|
|
88
|
+
For production environments, please configure your secrets directly in the FastStore WebOps Settings page.`
|
|
89
|
+
);
|
|
90
|
+
logger.log("");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
61
93
|
|
|
62
94
|
// src/utils/directory.ts
|
|
63
95
|
import path from "path";
|
|
@@ -119,102 +151,175 @@ var withBasePath = (basepath) => {
|
|
|
119
151
|
};
|
|
120
152
|
};
|
|
121
153
|
|
|
122
|
-
// src/
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
154
|
+
// src/commands/build.ts
|
|
155
|
+
var { copySync, moveSync, readdirSync, removeSync } = fsExtra2;
|
|
156
|
+
var Build = class _Build extends Command {
|
|
157
|
+
static args = {
|
|
158
|
+
account: Args.string({
|
|
159
|
+
description: "The account for which the Discovery is running. Currently noop."
|
|
160
|
+
}),
|
|
161
|
+
path: Args.string({
|
|
162
|
+
description: "The path where the FastStore being built is. Defaults to cwd."
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
static flags = {
|
|
166
|
+
["no-verify"]: Flags.boolean({
|
|
167
|
+
description: "Skips verification of faststore dependencies version string to prevent usage of packages outside npm registry."
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
async run() {
|
|
171
|
+
const { args, flags } = await this.parse(_Build);
|
|
172
|
+
const basePath = getBasePath(args.path);
|
|
173
|
+
checkDeprecatedSecretFiles(basePath);
|
|
174
|
+
if (!flags["no-verify"]) {
|
|
175
|
+
const invalidPackages = await checkDeps(basePath);
|
|
176
|
+
invalidPackages.forEach(
|
|
177
|
+
(pkg) => logger.warn(
|
|
178
|
+
`${chalk2.yellow(
|
|
179
|
+
"warning"
|
|
180
|
+
)} - Dependency ${pkg} has invalid version signature. Please use a semver like ^1.0.0 (check the official releases on https://github.com/vtex/faststore)`
|
|
181
|
+
)
|
|
182
|
+
);
|
|
131
183
|
}
|
|
132
|
-
|
|
184
|
+
const { tmpDir } = withBasePath(basePath);
|
|
185
|
+
const packageManager = await getPreferredPackageManager();
|
|
186
|
+
const binCli = path2.join(
|
|
187
|
+
fileURLToPath2(
|
|
188
|
+
import.meta.resolve("@faststore/cli/runner", import.meta.url)
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
let scriptResult = spawnSync2("node", [binCli, "generate", basePath], {
|
|
192
|
+
stdio: "inherit"
|
|
193
|
+
});
|
|
194
|
+
if (scriptResult.error || scriptResult.status !== 0) {
|
|
195
|
+
throw "Error: Cant run generate" + (scriptResult.error?.message ?? "");
|
|
196
|
+
}
|
|
197
|
+
scriptResult = spawnSync2("node", [binCli, "cache-graphql", basePath], {
|
|
198
|
+
stdio: "inherit"
|
|
199
|
+
});
|
|
200
|
+
if (scriptResult.error || scriptResult.status !== 0) {
|
|
201
|
+
throw "Error: Unable to run cache-graphql" + (scriptResult.error?.message ?? "");
|
|
202
|
+
}
|
|
203
|
+
scriptResult = spawnSync2("node", [binCli, "generate-i18n", basePath], {
|
|
204
|
+
stdio: "inherit"
|
|
205
|
+
});
|
|
206
|
+
if (scriptResult.error || scriptResult.status !== 0) {
|
|
207
|
+
throw "Error: Unable to run generate-i18n" + (scriptResult.error?.message ?? "");
|
|
208
|
+
}
|
|
209
|
+
scriptResult = spawnSync2(`${packageManager} run build`, {
|
|
210
|
+
shell: true,
|
|
211
|
+
cwd: tmpDir,
|
|
212
|
+
stdio: "inherit"
|
|
213
|
+
});
|
|
214
|
+
if (scriptResult.status && scriptResult.status !== 0) {
|
|
215
|
+
process.exit(scriptResult.status);
|
|
216
|
+
}
|
|
217
|
+
await normalizeStandaloneBuildDir(basePath);
|
|
218
|
+
await copyResources(basePath);
|
|
133
219
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const { tmpDir } = withBasePath(basePath);
|
|
140
|
-
const configPaths = [
|
|
141
|
-
path2.join(tmpDir, configFileName),
|
|
142
|
-
path2.join(basePath, configFileName)
|
|
143
|
-
];
|
|
144
|
-
for (const configPath of configPaths) {
|
|
145
|
-
if (existsSync2(configPath)) {
|
|
146
|
-
try {
|
|
147
|
-
const discoveryConfig = await import(pathToFileURL2(configPath).href);
|
|
148
|
-
return discoveryConfig?.default ?? discoveryConfig;
|
|
149
|
-
} catch (error) {
|
|
150
|
-
logger.warn(
|
|
151
|
-
`${chalk.yellow("warning")} - Could not read config file: ${configPath}.`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
220
|
+
};
|
|
221
|
+
async function copyResource(from, to) {
|
|
222
|
+
try {
|
|
223
|
+
if (existsSync3(to)) {
|
|
224
|
+
removeSync(to);
|
|
154
225
|
}
|
|
226
|
+
copySync(from, to);
|
|
227
|
+
console.log(
|
|
228
|
+
`${chalk2.green("success")} - ${chalk2.dim(from)} copied to ${chalk2.dim(
|
|
229
|
+
to
|
|
230
|
+
)}`
|
|
231
|
+
);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
console.error(`${chalk2.red("error")} - ${err}`);
|
|
155
234
|
}
|
|
156
|
-
return null;
|
|
157
235
|
}
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const currentContentSourceType = config?.contentSource?.type?.toUpperCase();
|
|
166
|
-
if (currentContentSourceType !== "CP") {
|
|
167
|
-
logger.error(
|
|
168
|
-
`
|
|
169
|
-
${chalk.red("[Error]")} - Localization is enabled but contentSource is set to "${currentContentSourceType}".
|
|
170
|
-
|
|
171
|
-
${chalk.cyan("Required Action:")}
|
|
172
|
-
Update your ${chalk.bold("discovery.config.js")} file:
|
|
173
|
-
|
|
174
|
-
contentSource: {
|
|
175
|
-
type: ${chalk.green('"CP"')}
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
${chalk.dim("When localization is enabled, Content Platform (CP) is required.")}
|
|
179
|
-
`
|
|
236
|
+
async function normalizeStandaloneBuildDir(basePath) {
|
|
237
|
+
const { tmpDir } = withBasePath(basePath);
|
|
238
|
+
const isRunningFromMonorepo = process.cwd() !== basePath;
|
|
239
|
+
const prefix = isRunningFromMonorepo ? `${path2.relative(process.cwd(), basePath).replace(/\\/g, "/")}/` : "";
|
|
240
|
+
if (existsSync3(`${tmpDir}/.next/standalone/${prefix}.faststore`)) {
|
|
241
|
+
const standaloneBuildFiles = readdirSync(
|
|
242
|
+
`${tmpDir}/.next/standalone/${prefix}.faststore`
|
|
180
243
|
);
|
|
181
|
-
|
|
244
|
+
await Promise.all(
|
|
245
|
+
standaloneBuildFiles.map(
|
|
246
|
+
(file) => moveSync(
|
|
247
|
+
`${tmpDir}/.next/standalone/${prefix}.faststore/${file}`,
|
|
248
|
+
`${tmpDir}/.next/standalone/${file}`,
|
|
249
|
+
{ overwrite: true }
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
removeSync(`${tmpDir}/.next/standalone/${prefix}.faststore`);
|
|
182
254
|
}
|
|
183
255
|
}
|
|
184
|
-
async function
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
187
|
-
|
|
256
|
+
async function copyResources(basePath) {
|
|
257
|
+
const { tmpDir, userDir } = withBasePath(basePath);
|
|
258
|
+
if (process.env.BUILD_CONTEXT === "vercel") {
|
|
259
|
+
const toDir = process.cwd();
|
|
260
|
+
const nextOutputDirectory = `${tmpDir}/.next`;
|
|
261
|
+
const expectedOutputDirectory = `${toDir}/.faststore/.next`;
|
|
262
|
+
if (nextOutputDirectory !== expectedOutputDirectory) {
|
|
263
|
+
await copyResource(nextOutputDirectory, expectedOutputDirectory);
|
|
264
|
+
}
|
|
265
|
+
await copyResource(`${tmpDir}/public`, `${toDir}/public`);
|
|
266
|
+
} else {
|
|
267
|
+
await copyResource(`${tmpDir}/.next`, `${userDir}/.next`);
|
|
268
|
+
await copyResource(
|
|
269
|
+
`${tmpDir}/lighthouserc.js`,
|
|
270
|
+
`${userDir}/lighthouserc.js`
|
|
271
|
+
);
|
|
272
|
+
await copyResource(`${tmpDir}/public`, `${userDir}/public`);
|
|
188
273
|
}
|
|
189
|
-
validateContentSourceForLocalization(config);
|
|
190
|
-
return isLocalizationEnabled(config);
|
|
191
274
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const secretsFileExists = existsSync3(secretsFilePath);
|
|
200
|
-
const vtexEnvFileExists = existsSync3(vtexEnvFilePath);
|
|
201
|
-
if (secretsFileExists || vtexEnvFileExists) {
|
|
202
|
-
const filesFound = [
|
|
203
|
-
secretsFileExists ? "secrets.hidden.json" : null,
|
|
204
|
-
vtexEnvFileExists ? "vtex.env" : null
|
|
205
|
-
].filter(Boolean).join(" and ");
|
|
206
|
-
logger.warn(
|
|
207
|
-
`${chalk2.yellow("warning")} - Deprecated secret files detected: ${chalk2.bold(filesFound)}
|
|
208
|
-
Note: 'vtex.env' should only be used for local development and not in production.
|
|
209
|
-
For production environments, please configure your secrets directly in the FastStore WebOps Settings page.`
|
|
275
|
+
async function checkDeps(basePath) {
|
|
276
|
+
const packageJsonPath = `${basePath}/package.json`;
|
|
277
|
+
if (!existsSync3(packageJsonPath)) {
|
|
278
|
+
console.log(
|
|
279
|
+
`${chalk2.yellow(
|
|
280
|
+
"warning"
|
|
281
|
+
)} - package.json not found at ${packageJsonPath}`
|
|
210
282
|
);
|
|
211
|
-
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const mod = await import(pathToFileURL2(packageJsonPath).href, {
|
|
286
|
+
with: { type: "json" }
|
|
287
|
+
});
|
|
288
|
+
const pkg = mod.default ?? mod;
|
|
289
|
+
const {
|
|
290
|
+
devDependencies = {},
|
|
291
|
+
dependencies = {},
|
|
292
|
+
peerDependencies = {}
|
|
293
|
+
} = pkg;
|
|
294
|
+
const allDeps = Object.assign(
|
|
295
|
+
{},
|
|
296
|
+
peerDependencies,
|
|
297
|
+
devDependencies,
|
|
298
|
+
dependencies
|
|
299
|
+
);
|
|
300
|
+
const invalidPackages = [];
|
|
301
|
+
Object.entries(allDeps).forEach(([pkg2, version]) => {
|
|
302
|
+
if (/^@faststore\/.+/i.test(pkg2) === false) return;
|
|
303
|
+
if (version && /^(http|https|git):.+/.test(version) === true) {
|
|
304
|
+
invalidPackages.push(pkg2);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return invalidPackages;
|
|
308
|
+
} catch (err) {
|
|
309
|
+
console.log(
|
|
310
|
+
`${chalk2.yellow("warning")} - unable to check @faststore dependencies: ${err}`
|
|
311
|
+
);
|
|
312
|
+
return [];
|
|
212
313
|
}
|
|
213
314
|
}
|
|
214
315
|
|
|
316
|
+
// src/commands/cms-sync.ts
|
|
317
|
+
import { Args as Args2, Command as Command2, Flags as Flags2 } from "@oclif/core";
|
|
318
|
+
import { spawn } from "child_process";
|
|
319
|
+
|
|
215
320
|
// src/utils/generate.ts
|
|
216
321
|
import chalk4 from "chalk";
|
|
217
|
-
import
|
|
322
|
+
import fsExtra4 from "fs-extra";
|
|
218
323
|
import path5 from "path";
|
|
219
324
|
import ora from "ora";
|
|
220
325
|
import { pathToFileURL as pathToFileURL4 } from "url";
|
|
@@ -418,10 +523,10 @@ async function installDependencies({
|
|
|
418
523
|
}
|
|
419
524
|
|
|
420
525
|
// src/utils/plugins.ts
|
|
421
|
-
import
|
|
526
|
+
import fsExtra3 from "fs-extra";
|
|
422
527
|
import path4 from "path";
|
|
423
528
|
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
424
|
-
var { copySync, existsSync: existsSync4, mkdirSync, readdirSync, writeFileSync } =
|
|
529
|
+
var { copySync: copySync2, existsSync: existsSync4, mkdirSync, readdirSync: readdirSync2, writeFileSync } = fsExtra3;
|
|
425
530
|
var PLUGIN_CONFIG_FILE = "plugin.config.js";
|
|
426
531
|
var sanitizePluginName = (pluginName, pascalCase = false) => {
|
|
427
532
|
const sanitized = pluginName.split("/")[1];
|
|
@@ -471,7 +576,7 @@ var copyPluginsSrc = async (basePath, plugins) => {
|
|
|
471
576
|
tmpPluginsDir,
|
|
472
577
|
sanitizePluginName(pluginName)
|
|
473
578
|
);
|
|
474
|
-
|
|
579
|
+
copySync2(pluginSrcPath, pluginDestPath);
|
|
475
580
|
logger.log(`Copied ${pluginName} files`);
|
|
476
581
|
});
|
|
477
582
|
};
|
|
@@ -483,7 +588,7 @@ var copyPluginPublicFiles = async (basePath, plugins) => {
|
|
|
483
588
|
const pluginPath = getPackagePath(getPluginName(pluginName));
|
|
484
589
|
try {
|
|
485
590
|
if (existsSync4(`${pluginPath}/public`)) {
|
|
486
|
-
|
|
591
|
+
copySync2(`${pluginPath}/public`, `${tmpDir}/public`, {
|
|
487
592
|
dereference: true,
|
|
488
593
|
overwrite: true
|
|
489
594
|
});
|
|
@@ -591,7 +696,7 @@ async function addPluginsOverrides(basePath, plugins) {
|
|
|
591
696
|
})).filter(({ pluginOverridesPath }) => existsSync4(pluginOverridesPath)).reverse().forEach(({ pluginName, pluginOverridesPath }) => {
|
|
592
697
|
const overrideFilesAlreadyCopied = [];
|
|
593
698
|
const sanitizedPluginName = sanitizePluginName(pluginName);
|
|
594
|
-
const overrideFiles =
|
|
699
|
+
const overrideFiles = readdirSync2(pluginOverridesPath);
|
|
595
700
|
overrideFiles.filter((file) => !overrideFilesAlreadyCopied.includes(file)).forEach((overrideFileName) => {
|
|
596
701
|
const overrideFileContent = `export { override } from 'src/plugins/${sanitizedPluginName}/components/overrides/${overrideFileName.split(".")[0]}'`;
|
|
597
702
|
writeFileSync(
|
|
@@ -669,16 +774,15 @@ var installPlugins = async (basePath) => {
|
|
|
669
774
|
// src/utils/generate.ts
|
|
670
775
|
var {
|
|
671
776
|
copyFileSync,
|
|
672
|
-
copySync:
|
|
777
|
+
copySync: copySync3,
|
|
673
778
|
existsSync: existsSync5,
|
|
674
779
|
mkdirsSync,
|
|
675
|
-
moveSync,
|
|
676
780
|
readFileSync,
|
|
677
|
-
readdirSync:
|
|
678
|
-
removeSync,
|
|
781
|
+
readdirSync: readdirSync3,
|
|
782
|
+
removeSync: removeSync2,
|
|
679
783
|
writeFileSync: writeFileSync2,
|
|
680
784
|
writeJsonSync
|
|
681
|
-
} =
|
|
785
|
+
} = fsExtra4;
|
|
682
786
|
var ignorePaths = [
|
|
683
787
|
"package.json",
|
|
684
788
|
"node_modules",
|
|
@@ -690,7 +794,7 @@ function createTmpFolder(basePath) {
|
|
|
690
794
|
const { tmpDir, tmpFolderName } = withBasePath(basePath);
|
|
691
795
|
try {
|
|
692
796
|
if (existsSync5(tmpDir)) {
|
|
693
|
-
|
|
797
|
+
removeSync2(tmpDir);
|
|
694
798
|
}
|
|
695
799
|
mkdirsSync(tmpDir);
|
|
696
800
|
logger.log(
|
|
@@ -767,7 +871,7 @@ function disableTsConfigStrictRules(basePath) {
|
|
|
767
871
|
function copyCoreFiles(basePath) {
|
|
768
872
|
const { coreDir, tmpDir } = withBasePath(basePath);
|
|
769
873
|
try {
|
|
770
|
-
|
|
874
|
+
copySync3(coreDir, tmpDir, {
|
|
771
875
|
dereference: true,
|
|
772
876
|
filter(src) {
|
|
773
877
|
const fileOrDirName = path5.basename(src);
|
|
@@ -787,7 +891,7 @@ function copyPublicFiles(basePath) {
|
|
|
787
891
|
const allowList = ["json", "txt", "xml", "ico", "public", "svg"];
|
|
788
892
|
try {
|
|
789
893
|
if (existsSync5(`${userDir}/public`)) {
|
|
790
|
-
|
|
894
|
+
copySync3(`${userDir}/public`, `${tmpDir}/public`, {
|
|
791
895
|
dereference: true,
|
|
792
896
|
overwrite: true,
|
|
793
897
|
filter: (src) => {
|
|
@@ -805,12 +909,12 @@ async function copyCypressFiles(basePath) {
|
|
|
805
909
|
const { userDir, userStoreConfigFile, userLegacyStoreConfigFile, tmpDir } = withBasePath(basePath);
|
|
806
910
|
try {
|
|
807
911
|
if (existsSync5(`${userDir}/cypress.json`)) {
|
|
808
|
-
|
|
912
|
+
copySync3(`${userDir}/cypress.json`, `${tmpDir}/cypress.json`, {
|
|
809
913
|
dereference: true
|
|
810
914
|
});
|
|
811
915
|
}
|
|
812
916
|
if (existsSync5(`${userDir}/cypress.config.ts`)) {
|
|
813
|
-
|
|
917
|
+
copySync3(`${userDir}/cypress.config.ts`, `${tmpDir}/cypress.config.ts`, {
|
|
814
918
|
dereference: true
|
|
815
919
|
});
|
|
816
920
|
}
|
|
@@ -827,14 +931,14 @@ async function copyCypressFiles(basePath) {
|
|
|
827
931
|
);
|
|
828
932
|
}
|
|
829
933
|
if (existsSync5(`${userDir}/cypress`) && userStoreConfig?.experimental?.enableCypressExtension) {
|
|
830
|
-
|
|
934
|
+
copySync3(`${userDir}/cypress`, `${tmpDir}/cypress`, {
|
|
831
935
|
overwrite: true,
|
|
832
936
|
dereference: true
|
|
833
937
|
});
|
|
834
938
|
logger.log(`${chalk4.green("success")} - Cypress test files copied`);
|
|
835
939
|
}
|
|
836
940
|
if (userStoreConfig?.experimental?.cypressVersion > 9) {
|
|
837
|
-
|
|
941
|
+
copySync3(
|
|
838
942
|
`${tmpDir}/cypress/support/index.js`,
|
|
839
943
|
`${tmpDir}/cypress/support/e2e.js`,
|
|
840
944
|
{ overwrite: false }
|
|
@@ -853,17 +957,17 @@ function copyUserStarterToCustomizations(basePath) {
|
|
|
853
957
|
tmpStoreConfigFile
|
|
854
958
|
} = withBasePath(basePath);
|
|
855
959
|
try {
|
|
856
|
-
if (existsSync5(userSrcDir) &&
|
|
857
|
-
|
|
960
|
+
if (existsSync5(userSrcDir) && readdirSync3(userSrcDir).length > 0) {
|
|
961
|
+
copySync3(userSrcDir, tmpCustomizationsSrcDir, { dereference: true });
|
|
858
962
|
createNextJsPages(basePath);
|
|
859
963
|
}
|
|
860
964
|
} catch (err) {
|
|
861
965
|
logger.error(`${chalk4.red("error")} - ${err}`);
|
|
862
966
|
}
|
|
863
967
|
if (existsSync5(userStoreConfigFile)) {
|
|
864
|
-
|
|
968
|
+
copySync3(userStoreConfigFile, tmpStoreConfigFile, { dereference: true });
|
|
865
969
|
} else if (existsSync5(userLegacyStoreConfigFile)) {
|
|
866
|
-
|
|
970
|
+
copySync3(userLegacyStoreConfigFile, tmpStoreConfigFile, {
|
|
867
971
|
dereference: true
|
|
868
972
|
});
|
|
869
973
|
} else {
|
|
@@ -941,7 +1045,7 @@ async function copyTheme(basePath) {
|
|
|
941
1045
|
`${chalk4.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`
|
|
942
1046
|
);
|
|
943
1047
|
}
|
|
944
|
-
} else if (existsSync5(userThemesFileDir) &&
|
|
1048
|
+
} else if (existsSync5(userThemesFileDir) && readdirSync3(userThemesFileDir).length > 0) {
|
|
945
1049
|
logger.info(
|
|
946
1050
|
`${chalk4.blue(
|
|
947
1051
|
"info"
|
|
@@ -1049,24 +1153,6 @@ async function validateAndInstallMissingDependencies(basePath) {
|
|
|
1049
1153
|
}
|
|
1050
1154
|
});
|
|
1051
1155
|
}
|
|
1052
|
-
var DISABLED_PROXY_FILENAME = "proxy__DISABLED.ts";
|
|
1053
|
-
function toggleProxyByLocalizationFlag(basePath, localizationEnabled) {
|
|
1054
|
-
try {
|
|
1055
|
-
const { tmpDir } = withBasePath(basePath);
|
|
1056
|
-
const proxyPath = path5.join(tmpDir, "src", "proxy.ts");
|
|
1057
|
-
const disabledPath = path5.join(tmpDir, "src", DISABLED_PROXY_FILENAME);
|
|
1058
|
-
const shouldEnableProxy = existsSync5(disabledPath) && !existsSync5(proxyPath);
|
|
1059
|
-
const shouldDisableProxy = existsSync5(proxyPath);
|
|
1060
|
-
if (localizationEnabled && shouldEnableProxy) {
|
|
1061
|
-
moveSync(disabledPath, proxyPath);
|
|
1062
|
-
} else if (!localizationEnabled && shouldDisableProxy) {
|
|
1063
|
-
moveSync(proxyPath, disabledPath);
|
|
1064
|
-
}
|
|
1065
|
-
} catch (error) {
|
|
1066
|
-
logger.error(error);
|
|
1067
|
-
throw error;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
1156
|
async function enableSearchSSR(basePath) {
|
|
1071
1157
|
const storeConfigPath = getCurrentUserStoreConfigFile(basePath);
|
|
1072
1158
|
if (!storeConfigPath) {
|
|
@@ -1110,182 +1196,13 @@ async function generate(options) {
|
|
|
1110
1196
|
]);
|
|
1111
1197
|
}
|
|
1112
1198
|
|
|
1113
|
-
// src/commands/build.ts
|
|
1114
|
-
var { copySync: copySync3, moveSync: moveSync2, readdirSync: readdirSync3, removeSync: removeSync2 } = fsExtra4;
|
|
1115
|
-
var Build = class _Build extends Command {
|
|
1116
|
-
static args = {
|
|
1117
|
-
account: Args.string({
|
|
1118
|
-
description: "The account for which the Discovery is running. Currently noop."
|
|
1119
|
-
}),
|
|
1120
|
-
path: Args.string({
|
|
1121
|
-
description: "The path where the FastStore being built is. Defaults to cwd."
|
|
1122
|
-
})
|
|
1123
|
-
};
|
|
1124
|
-
static flags = {
|
|
1125
|
-
["no-verify"]: Flags.boolean({
|
|
1126
|
-
description: "Skips verification of faststore dependencies version string to prevent usage of packages outside npm registry."
|
|
1127
|
-
})
|
|
1128
|
-
};
|
|
1129
|
-
async run() {
|
|
1130
|
-
const { args, flags } = await this.parse(_Build);
|
|
1131
|
-
const basePath = getBasePath(args.path);
|
|
1132
|
-
checkDeprecatedSecretFiles(basePath);
|
|
1133
|
-
if (!flags["no-verify"]) {
|
|
1134
|
-
const invalidPackages = await checkDeps(basePath);
|
|
1135
|
-
invalidPackages.forEach(
|
|
1136
|
-
(pkg) => logger.warn(
|
|
1137
|
-
`${chalk5.yellow(
|
|
1138
|
-
"warning"
|
|
1139
|
-
)} - Dependency ${pkg} has invalid version signature. Please use a semver like ^1.0.0 (check the official releases on https://github.com/vtex/faststore)`
|
|
1140
|
-
)
|
|
1141
|
-
);
|
|
1142
|
-
}
|
|
1143
|
-
const { tmpDir } = withBasePath(basePath);
|
|
1144
|
-
const packageManager = await getPreferredPackageManager();
|
|
1145
|
-
const binCli = path6.join(
|
|
1146
|
-
fileURLToPath2(
|
|
1147
|
-
import.meta.resolve("@faststore/cli/runner", import.meta.url)
|
|
1148
|
-
)
|
|
1149
|
-
);
|
|
1150
|
-
let scriptResult = spawnSync2("node", [binCli, "generate", basePath], {
|
|
1151
|
-
stdio: "inherit"
|
|
1152
|
-
});
|
|
1153
|
-
if (scriptResult.error || scriptResult.status !== 0) {
|
|
1154
|
-
throw "Error: Cant run generate" + (scriptResult.error?.message ?? "");
|
|
1155
|
-
}
|
|
1156
|
-
scriptResult = spawnSync2("node", [binCli, "cache-graphql", basePath], {
|
|
1157
|
-
stdio: "inherit"
|
|
1158
|
-
});
|
|
1159
|
-
if (scriptResult.error || scriptResult.status !== 0) {
|
|
1160
|
-
throw "Error: Unable to run cache-graphql" + (scriptResult.error?.message ?? "");
|
|
1161
|
-
}
|
|
1162
|
-
scriptResult = spawnSync2("node", [binCli, "generate-i18n", basePath], {
|
|
1163
|
-
stdio: "inherit"
|
|
1164
|
-
});
|
|
1165
|
-
if (scriptResult.error || scriptResult.status !== 0) {
|
|
1166
|
-
throw "Error: Unable to run generate-i18n" + (scriptResult.error?.message ?? "");
|
|
1167
|
-
}
|
|
1168
|
-
const config = await getDiscoveryConfig(basePath);
|
|
1169
|
-
const localizationEnabled = config?.localization?.enabled === true;
|
|
1170
|
-
toggleProxyByLocalizationFlag(basePath, localizationEnabled);
|
|
1171
|
-
scriptResult = spawnSync2(`${packageManager} run build`, {
|
|
1172
|
-
shell: true,
|
|
1173
|
-
cwd: tmpDir,
|
|
1174
|
-
stdio: "inherit"
|
|
1175
|
-
});
|
|
1176
|
-
if (scriptResult.status && scriptResult.status !== 0) {
|
|
1177
|
-
process.exit(scriptResult.status);
|
|
1178
|
-
}
|
|
1179
|
-
await normalizeStandaloneBuildDir(basePath);
|
|
1180
|
-
await copyResources(basePath);
|
|
1181
|
-
}
|
|
1182
|
-
};
|
|
1183
|
-
async function copyResource(from, to) {
|
|
1184
|
-
try {
|
|
1185
|
-
if (existsSync6(to)) {
|
|
1186
|
-
removeSync2(to);
|
|
1187
|
-
}
|
|
1188
|
-
copySync3(from, to);
|
|
1189
|
-
console.log(
|
|
1190
|
-
`${chalk5.green("success")} - ${chalk5.dim(from)} copied to ${chalk5.dim(
|
|
1191
|
-
to
|
|
1192
|
-
)}`
|
|
1193
|
-
);
|
|
1194
|
-
} catch (err) {
|
|
1195
|
-
console.error(`${chalk5.red("error")} - ${err}`);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
async function normalizeStandaloneBuildDir(basePath) {
|
|
1199
|
-
const { tmpDir } = withBasePath(basePath);
|
|
1200
|
-
const isRunningFromMonorepo = process.cwd() !== basePath;
|
|
1201
|
-
const prefix = isRunningFromMonorepo ? `${path6.relative(process.cwd(), basePath).replace(/\\/g, "/")}/` : "";
|
|
1202
|
-
if (existsSync6(`${tmpDir}/.next/standalone/${prefix}.faststore`)) {
|
|
1203
|
-
const standaloneBuildFiles = readdirSync3(
|
|
1204
|
-
`${tmpDir}/.next/standalone/${prefix}.faststore`
|
|
1205
|
-
);
|
|
1206
|
-
await Promise.all(
|
|
1207
|
-
standaloneBuildFiles.map(
|
|
1208
|
-
(file) => moveSync2(
|
|
1209
|
-
`${tmpDir}/.next/standalone/${prefix}.faststore/${file}`,
|
|
1210
|
-
`${tmpDir}/.next/standalone/${file}`,
|
|
1211
|
-
{ overwrite: true }
|
|
1212
|
-
)
|
|
1213
|
-
)
|
|
1214
|
-
);
|
|
1215
|
-
removeSync2(`${tmpDir}/.next/standalone/${prefix}.faststore`);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
async function copyResources(basePath) {
|
|
1219
|
-
const { tmpDir, userDir } = withBasePath(basePath);
|
|
1220
|
-
if (process.env.BUILD_CONTEXT === "vercel") {
|
|
1221
|
-
const toDir = process.cwd();
|
|
1222
|
-
const nextOutputDirectory = `${tmpDir}/.next`;
|
|
1223
|
-
const expectedOutputDirectory = `${toDir}/.faststore/.next`;
|
|
1224
|
-
if (nextOutputDirectory !== expectedOutputDirectory) {
|
|
1225
|
-
await copyResource(nextOutputDirectory, expectedOutputDirectory);
|
|
1226
|
-
}
|
|
1227
|
-
await copyResource(`${tmpDir}/public`, `${toDir}/public`);
|
|
1228
|
-
} else {
|
|
1229
|
-
await copyResource(`${tmpDir}/.next`, `${userDir}/.next`);
|
|
1230
|
-
await copyResource(
|
|
1231
|
-
`${tmpDir}/lighthouserc.js`,
|
|
1232
|
-
`${userDir}/lighthouserc.js`
|
|
1233
|
-
);
|
|
1234
|
-
await copyResource(`${tmpDir}/public`, `${userDir}/public`);
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
async function checkDeps(basePath) {
|
|
1238
|
-
const packageJsonPath = `${basePath}/package.json`;
|
|
1239
|
-
if (!existsSync6(packageJsonPath)) {
|
|
1240
|
-
console.log(
|
|
1241
|
-
`${chalk5.yellow(
|
|
1242
|
-
"warning"
|
|
1243
|
-
)} - package.json not found at ${packageJsonPath}`
|
|
1244
|
-
);
|
|
1245
|
-
}
|
|
1246
|
-
try {
|
|
1247
|
-
const mod = await import(pathToFileURL5(packageJsonPath).href, {
|
|
1248
|
-
with: { type: "json" }
|
|
1249
|
-
});
|
|
1250
|
-
const pkg = mod.default ?? mod;
|
|
1251
|
-
const {
|
|
1252
|
-
devDependencies = {},
|
|
1253
|
-
dependencies = {},
|
|
1254
|
-
peerDependencies = {}
|
|
1255
|
-
} = pkg;
|
|
1256
|
-
const allDeps = Object.assign(
|
|
1257
|
-
{},
|
|
1258
|
-
peerDependencies,
|
|
1259
|
-
devDependencies,
|
|
1260
|
-
dependencies
|
|
1261
|
-
);
|
|
1262
|
-
const invalidPackages = [];
|
|
1263
|
-
Object.entries(allDeps).forEach(([pkg2, version]) => {
|
|
1264
|
-
if (/^@faststore\/.+/i.test(pkg2) === false) return;
|
|
1265
|
-
if (version && /^(http|https|git):.+/.test(version) === true) {
|
|
1266
|
-
invalidPackages.push(pkg2);
|
|
1267
|
-
}
|
|
1268
|
-
});
|
|
1269
|
-
return invalidPackages;
|
|
1270
|
-
} catch (err) {
|
|
1271
|
-
console.log(
|
|
1272
|
-
`${chalk5.yellow("warning")} - unable to check @faststore dependencies: ${err}`
|
|
1273
|
-
);
|
|
1274
|
-
return [];
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
// src/commands/cms-sync.ts
|
|
1279
|
-
import { Args as Args2, Command as Command2, Flags as Flags2 } from "@oclif/core";
|
|
1280
|
-
import { spawn } from "child_process";
|
|
1281
|
-
|
|
1282
1199
|
// src/utils/hcms.ts
|
|
1283
|
-
import
|
|
1284
|
-
import
|
|
1200
|
+
import chalk5 from "chalk";
|
|
1201
|
+
import path6 from "path";
|
|
1285
1202
|
import { confirm } from "@inquirer/prompts";
|
|
1286
1203
|
import fsExtra5 from "fs-extra";
|
|
1287
|
-
import { pathToFileURL as
|
|
1288
|
-
var { readFileSync: readFileSync2, existsSync:
|
|
1204
|
+
import { pathToFileURL as pathToFileURL5 } from "url";
|
|
1205
|
+
var { readFileSync: readFileSync2, existsSync: existsSync6, writeFileSync: writeFileSync3, mkdirSync: mkdirSync2 } = fsExtra5;
|
|
1289
1206
|
function splitCustomDefinitions(coreDefinitions, customDefinitions, primaryIdentifier) {
|
|
1290
1207
|
const coreDefinitionIdentifiers = new Set(
|
|
1291
1208
|
coreDefinitions.map((definition) => definition[primaryIdentifier] ?? "")
|
|
@@ -1349,10 +1266,10 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1349
1266
|
getPackagePath,
|
|
1350
1267
|
userStoreConfigFile
|
|
1351
1268
|
} = withBasePath(basePath);
|
|
1352
|
-
const { default: userStoreConfig } = await import(
|
|
1269
|
+
const { default: userStoreConfig } = await import(pathToFileURL5(path6.resolve(userStoreConfigFile)).href);
|
|
1353
1270
|
const cmsProjectName = userStoreConfig.contentSource?.project ?? "faststore";
|
|
1354
|
-
const coreFilePath =
|
|
1355
|
-
const customFilePath =
|
|
1271
|
+
const coreFilePath = path6.join(coreCMSDir, fileName);
|
|
1272
|
+
const customFilePath = path6.join(userCMSDir, fileName);
|
|
1356
1273
|
const coreFile = readFileSync2(coreFilePath, "utf8");
|
|
1357
1274
|
const coreDefinitions = JSON.parse(coreFile);
|
|
1358
1275
|
const primaryIdentifierForDefinitions = fileName === "content-types.json" ? "id" : "name";
|
|
@@ -1362,7 +1279,7 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1362
1279
|
(plugin) => getPackagePath(getPluginName(plugin), "cms", "faststore", fileName)
|
|
1363
1280
|
);
|
|
1364
1281
|
const customizations = [...pluginCMSFilePaths, customFilePath].filter(
|
|
1365
|
-
(pluginCMSFilePath) =>
|
|
1282
|
+
(pluginCMSFilePath) => existsSync6(pluginCMSFilePath)
|
|
1366
1283
|
);
|
|
1367
1284
|
for (const newFilePath of customizations) {
|
|
1368
1285
|
const customFile = readFileSync2(newFilePath, "utf8");
|
|
@@ -1391,7 +1308,7 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1391
1308
|
} catch (err) {
|
|
1392
1309
|
if (err instanceof SyntaxError) {
|
|
1393
1310
|
console.info(
|
|
1394
|
-
`${
|
|
1311
|
+
`${chalk5.red(
|
|
1395
1312
|
"error"
|
|
1396
1313
|
)} - ${fileName} is a malformed JSON file, ignoring its contents.`
|
|
1397
1314
|
);
|
|
@@ -1401,18 +1318,18 @@ async function mergeCMSFile(fileName, basePath) {
|
|
|
1401
1318
|
}
|
|
1402
1319
|
}
|
|
1403
1320
|
try {
|
|
1404
|
-
if (!
|
|
1321
|
+
if (!existsSync6(tmpCMSDir(cmsProjectName))) {
|
|
1405
1322
|
mkdirSync2(tmpCMSDir(cmsProjectName));
|
|
1406
1323
|
}
|
|
1407
1324
|
writeFileSync3(
|
|
1408
|
-
|
|
1325
|
+
path6.join(tmpCMSDir(cmsProjectName), fileName),
|
|
1409
1326
|
JSON.stringify(output)
|
|
1410
1327
|
);
|
|
1411
1328
|
console.log(
|
|
1412
|
-
`${
|
|
1329
|
+
`${chalk5.green("success")} - CMS file ${chalk5.dim(fileName)} created`
|
|
1413
1330
|
);
|
|
1414
1331
|
} catch (err) {
|
|
1415
|
-
console.error(`${
|
|
1332
|
+
console.error(`${chalk5.red("error")} - ${err}`);
|
|
1416
1333
|
}
|
|
1417
1334
|
}
|
|
1418
1335
|
async function mergeCMSFiles(basePath) {
|
|
@@ -1420,13 +1337,13 @@ async function mergeCMSFiles(basePath) {
|
|
|
1420
1337
|
await mergeCMSFile("content-types.json", basePath);
|
|
1421
1338
|
await mergeCMSFile("sections.json", basePath);
|
|
1422
1339
|
} catch (err) {
|
|
1423
|
-
console.error(`${
|
|
1340
|
+
console.error(`${chalk5.red("error")} - ${err}`);
|
|
1424
1341
|
}
|
|
1425
1342
|
}
|
|
1426
1343
|
|
|
1427
1344
|
// src/commands/cms-sync.ts
|
|
1428
|
-
import
|
|
1429
|
-
import { pathToFileURL as
|
|
1345
|
+
import path7 from "path";
|
|
1346
|
+
import { pathToFileURL as pathToFileURL6 } from "url";
|
|
1430
1347
|
var CmsSync = class _CmsSync extends Command2 {
|
|
1431
1348
|
static flags = {
|
|
1432
1349
|
["dry-run"]: Flags2.boolean({ char: "d" })
|
|
@@ -1441,7 +1358,7 @@ var CmsSync = class _CmsSync extends Command2 {
|
|
|
1441
1358
|
const { flags, args } = await this.parse(_CmsSync);
|
|
1442
1359
|
const basePath = getBasePath(args.path);
|
|
1443
1360
|
const { tmpDir, userStoreConfigFile } = withBasePath(basePath);
|
|
1444
|
-
const { default: userStoreConfig } = await import(
|
|
1361
|
+
const { default: userStoreConfig } = await import(pathToFileURL6(path7.resolve(userStoreConfigFile)).href);
|
|
1445
1362
|
const cmsProjectName = userStoreConfig.contentSource?.project ?? "faststore";
|
|
1446
1363
|
await generate({ setup: true, basePath });
|
|
1447
1364
|
await mergeCMSFiles(basePath);
|
|
@@ -1495,12 +1412,12 @@ var Create = class _Create extends Command3 {
|
|
|
1495
1412
|
|
|
1496
1413
|
// src/commands/dev.ts
|
|
1497
1414
|
import { Args as Args4, Command as Command4, Flags as Flags3 } from "@oclif/core";
|
|
1498
|
-
import
|
|
1415
|
+
import chalk6 from "chalk";
|
|
1499
1416
|
import { spawn as spawn2, spawnSync as spawnSync3 } from "child_process";
|
|
1500
1417
|
import chokidar from "chokidar";
|
|
1501
1418
|
import dotenv from "dotenv";
|
|
1502
|
-
import { cpSync, existsSync as
|
|
1503
|
-
import
|
|
1419
|
+
import { cpSync, existsSync as existsSync7, readFileSync as readFileSync3 } from "fs";
|
|
1420
|
+
import path8 from "path";
|
|
1504
1421
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1505
1422
|
var stabilityThreshold = process.platform === "darwin" ? 100 : 200;
|
|
1506
1423
|
var defaultPatterns = ["*/**", "**"];
|
|
@@ -1520,13 +1437,13 @@ var defaultNodeModulesIgnoredExceptVtexPackages = [
|
|
|
1520
1437
|
var devAbortController = new AbortController();
|
|
1521
1438
|
async function storeDev(rootDir, tmpDir, coreDir, port) {
|
|
1522
1439
|
let envVars = {};
|
|
1523
|
-
const vtexEnvPath =
|
|
1524
|
-
if (
|
|
1440
|
+
const vtexEnvPath = path8.join(rootDir, "vtex.env");
|
|
1441
|
+
if (existsSync7(vtexEnvPath)) {
|
|
1525
1442
|
try {
|
|
1526
1443
|
envVars = dotenv.parse(readFileSync3(vtexEnvPath));
|
|
1527
1444
|
} catch (err) {
|
|
1528
1445
|
logger.log(
|
|
1529
|
-
`${
|
|
1446
|
+
`${chalk6.yellow("warn")} - Error parsing vtex.env file: ${err}`
|
|
1530
1447
|
);
|
|
1531
1448
|
}
|
|
1532
1449
|
}
|
|
@@ -1538,15 +1455,15 @@ async function storeDev(rootDir, tmpDir, coreDir, port) {
|
|
|
1538
1455
|
cwd: tmpDir
|
|
1539
1456
|
});
|
|
1540
1457
|
const { success } = copyGenerated(
|
|
1541
|
-
|
|
1542
|
-
|
|
1458
|
+
path8.join(tmpDir, "@generated"),
|
|
1459
|
+
path8.join(coreDir, "@generated")
|
|
1543
1460
|
);
|
|
1544
1461
|
if (!success) {
|
|
1545
1462
|
logger.log(
|
|
1546
|
-
`${
|
|
1463
|
+
`${chalk6.yellow("warn")} - Failed to copy @generated schema back to node_modules, autocomplete and DX might be impacted.`
|
|
1547
1464
|
);
|
|
1548
1465
|
logger.log(
|
|
1549
|
-
`Attempted to copy from ${
|
|
1466
|
+
`Attempted to copy from ${path8.join(tmpDir, "@generated")} to ${path8.join(coreDir, "@generated")}`
|
|
1550
1467
|
);
|
|
1551
1468
|
}
|
|
1552
1469
|
const devProcess = spawn2(`${packageManager} dev-only --port ${port}`, {
|
|
@@ -1645,9 +1562,6 @@ var Dev = class _Dev extends Command4 {
|
|
|
1645
1562
|
spawnSync3("node", [cliPath, "generate-i18n", basePath], {
|
|
1646
1563
|
stdio: "inherit"
|
|
1647
1564
|
});
|
|
1648
|
-
const config = await getDiscoveryConfig(basePath);
|
|
1649
|
-
const localizationEnabled = config?.localization?.enabled === true;
|
|
1650
|
-
toggleProxyByLocalizationFlag(basePath, localizationEnabled);
|
|
1651
1565
|
storeDev(getRoot(), tmpDir, coreDir, port);
|
|
1652
1566
|
return await new Promise((resolve, reject) => {
|
|
1653
1567
|
watcher.on("add", () => queueChange(
|
|
@@ -1666,13 +1580,13 @@ var Dev = class _Dev extends Command4 {
|
|
|
1666
1580
|
|
|
1667
1581
|
// src/commands/generate.ts
|
|
1668
1582
|
import { Args as Args5, Command as Command5 } from "@oclif/core";
|
|
1669
|
-
import
|
|
1583
|
+
import chalk7 from "chalk";
|
|
1670
1584
|
|
|
1671
1585
|
// src/utils/file.ts
|
|
1672
1586
|
import fs3 from "fs";
|
|
1673
|
-
import
|
|
1587
|
+
import path9 from "path";
|
|
1674
1588
|
function saveFile(fileLocation) {
|
|
1675
|
-
fs3.mkdirSync(
|
|
1589
|
+
fs3.mkdirSync(path9.dirname(fileLocation), { recursive: true });
|
|
1676
1590
|
return (content) => {
|
|
1677
1591
|
fs3.writeFileSync(fileLocation, content);
|
|
1678
1592
|
};
|
|
@@ -1686,17 +1600,17 @@ import {
|
|
|
1686
1600
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
1687
1601
|
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
1688
1602
|
import { buildASTSchema, Kind, parse } from "graphql";
|
|
1689
|
-
import fs4, { existsSync as
|
|
1690
|
-
import
|
|
1603
|
+
import fs4, { existsSync as existsSync8 } from "fs";
|
|
1604
|
+
import path10 from "path";
|
|
1691
1605
|
var schemaFileName = "schema.graphql";
|
|
1692
1606
|
async function genTsTypes(at) {
|
|
1693
1607
|
await generateSchemaFile(at);
|
|
1694
1608
|
generateSchemaTSTypes(at);
|
|
1695
1609
|
}
|
|
1696
1610
|
function generateSchemaTSTypes(root) {
|
|
1697
|
-
let finalRootPath =
|
|
1698
|
-
if (
|
|
1699
|
-
finalRootPath =
|
|
1611
|
+
let finalRootPath = path10.resolve(root);
|
|
1612
|
+
if (existsSync8(path10.resolve(root, ".faststore"))) {
|
|
1613
|
+
finalRootPath = path10.resolve(root, ".faststore");
|
|
1700
1614
|
}
|
|
1701
1615
|
const documents = [`${finalRootPath}/src/**/*.{ts,tsx}`];
|
|
1702
1616
|
const config = {
|
|
@@ -1705,7 +1619,7 @@ function generateSchemaTSTypes(root) {
|
|
|
1705
1619
|
errorsOnly: false,
|
|
1706
1620
|
debug: false,
|
|
1707
1621
|
verbose: true,
|
|
1708
|
-
schema:
|
|
1622
|
+
schema: path10.resolve(finalRootPath, "@generated", schemaFileName),
|
|
1709
1623
|
generates: {
|
|
1710
1624
|
[`${finalRootPath}/@generated/`]: {
|
|
1711
1625
|
preset: "client",
|
|
@@ -1756,7 +1670,7 @@ function getOperationName(document) {
|
|
|
1756
1670
|
async function generateSchemaFile(rootPath) {
|
|
1757
1671
|
const faststoreSchema = printSchemaWithDirectives(GraphqlVtexSchema());
|
|
1758
1672
|
const getMergedSchema = async () => {
|
|
1759
|
-
const root =
|
|
1673
|
+
const root = path10.join(
|
|
1760
1674
|
rootPath.endsWith(".faststore") ? [rootPath, ".."].join("/") : rootPath
|
|
1761
1675
|
);
|
|
1762
1676
|
const customizations = [
|
|
@@ -1775,9 +1689,9 @@ async function generateSchemaFile(rootPath) {
|
|
|
1775
1689
|
throw e;
|
|
1776
1690
|
}
|
|
1777
1691
|
};
|
|
1778
|
-
let pathToSave =
|
|
1779
|
-
if (
|
|
1780
|
-
pathToSave =
|
|
1692
|
+
let pathToSave = path10.resolve(rootPath, "@generated", schemaFileName);
|
|
1693
|
+
if (existsSync8(path10.resolve(rootPath, ".faststore"))) {
|
|
1694
|
+
pathToSave = path10.resolve(
|
|
1781
1695
|
rootPath,
|
|
1782
1696
|
".faststore",
|
|
1783
1697
|
"@generated",
|
|
@@ -1792,7 +1706,7 @@ async function getTypeDefsFromFolder(root, customPath) {
|
|
|
1792
1706
|
const globby = await import("globby");
|
|
1793
1707
|
const basePath = [root, "src", "graphql"];
|
|
1794
1708
|
const pathArray = Array.isArray(customPath) ? customPath : [customPath];
|
|
1795
|
-
return (globby.default ?? globby).globbySync(
|
|
1709
|
+
return (globby.default ?? globby).globbySync(path10.join(...[...basePath, ...pathArray]), {
|
|
1796
1710
|
expandDirectories: {
|
|
1797
1711
|
extensions: ["graphql"]
|
|
1798
1712
|
}
|
|
@@ -1818,7 +1732,7 @@ var Generate = class _Generate extends Command5 {
|
|
|
1818
1732
|
await generate({ setup: true, basePath });
|
|
1819
1733
|
genTsTypes(args.path ?? tmpDir);
|
|
1820
1734
|
logger.log(
|
|
1821
|
-
`${
|
|
1735
|
+
`${chalk7.green(
|
|
1822
1736
|
"success"
|
|
1823
1737
|
)} - GraphQL schema, types, and optimizations successfully generated \u{1F389}`
|
|
1824
1738
|
);
|
|
@@ -1828,7 +1742,7 @@ var Generate = class _Generate extends Command5 {
|
|
|
1828
1742
|
// src/commands/prepare.ts
|
|
1829
1743
|
import { Args as Args6, Command as Command6 } from "@oclif/core";
|
|
1830
1744
|
import fs5 from "fs";
|
|
1831
|
-
import
|
|
1745
|
+
import path11 from "path";
|
|
1832
1746
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1833
1747
|
var Prepare = class _Prepare extends Command6 {
|
|
1834
1748
|
static args = {
|
|
@@ -1840,10 +1754,10 @@ var Prepare = class _Prepare extends Command6 {
|
|
|
1840
1754
|
async run() {
|
|
1841
1755
|
const { args } = await this.parse(_Prepare);
|
|
1842
1756
|
const basePath = getBasePath(args.path);
|
|
1843
|
-
const clientPublicDir =
|
|
1844
|
-
const corePublicDir =
|
|
1757
|
+
const clientPublicDir = path11.join(basePath, "public/");
|
|
1758
|
+
const corePublicDir = path11.resolve(
|
|
1845
1759
|
fileURLToPath4(
|
|
1846
|
-
|
|
1760
|
+
path11.dirname(import.meta.resolve("@faststore/core", import.meta.url))
|
|
1847
1761
|
),
|
|
1848
1762
|
"public"
|
|
1849
1763
|
);
|
|
@@ -1859,8 +1773,8 @@ function copyFolder(sourceDir, targetDir) {
|
|
|
1859
1773
|
}
|
|
1860
1774
|
const files = fs5.readdirSync(sourceDir);
|
|
1861
1775
|
for (const file of files) {
|
|
1862
|
-
const sourcePath =
|
|
1863
|
-
const targetPath =
|
|
1776
|
+
const sourcePath = path11.join(sourceDir, file);
|
|
1777
|
+
const targetPath = path11.join(targetDir, file);
|
|
1864
1778
|
const stat = fs5.statSync(sourcePath);
|
|
1865
1779
|
if (stat.isFile()) {
|
|
1866
1780
|
fs5.copyFileSync(sourcePath, targetPath);
|
|
@@ -1875,8 +1789,8 @@ function copyFolder(sourceDir, targetDir) {
|
|
|
1875
1789
|
import { Args as Args7, Command as Command7 } from "@oclif/core";
|
|
1876
1790
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "child_process";
|
|
1877
1791
|
import fsExtra6 from "fs-extra";
|
|
1878
|
-
import
|
|
1879
|
-
var { existsSync:
|
|
1792
|
+
import path12 from "path";
|
|
1793
|
+
var { existsSync: existsSync9 } = fsExtra6;
|
|
1880
1794
|
var Start = class _Start extends Command7 {
|
|
1881
1795
|
static args = {
|
|
1882
1796
|
account: Args7.string({
|
|
@@ -1895,7 +1809,7 @@ var Start = class _Start extends Command7 {
|
|
|
1895
1809
|
const port = args.port ?? 3e3;
|
|
1896
1810
|
const { getRoot, tmpDir } = withBasePath(basePath);
|
|
1897
1811
|
const packageManager = await getPreferredPackageManager();
|
|
1898
|
-
if (!
|
|
1812
|
+
if (!existsSync9(path12.join(getRoot(), ".next"))) {
|
|
1899
1813
|
spawnSync4(`${packageManager} faststore build`, {
|
|
1900
1814
|
shell: true,
|
|
1901
1815
|
stdio: "inherit"
|
|
@@ -1978,9 +1892,9 @@ var Test = class _Test extends Command8 {
|
|
|
1978
1892
|
};
|
|
1979
1893
|
|
|
1980
1894
|
// src/commands/generate-types.ts
|
|
1981
|
-
import
|
|
1895
|
+
import path13 from "path";
|
|
1982
1896
|
import { Args as Args9, Command as Command9 } from "@oclif/core";
|
|
1983
|
-
import
|
|
1897
|
+
import chalk8 from "chalk";
|
|
1984
1898
|
var Generate2 = class _Generate extends Command9 {
|
|
1985
1899
|
static hidden = true;
|
|
1986
1900
|
static flags = {};
|
|
@@ -1994,10 +1908,10 @@ var Generate2 = class _Generate extends Command9 {
|
|
|
1994
1908
|
async run() {
|
|
1995
1909
|
const { args } = await this.parse(_Generate);
|
|
1996
1910
|
await genTsTypes(
|
|
1997
|
-
|
|
1911
|
+
path13.isAbsolute(args.path) ? args.path : path13.resolve(process.env.PWD ?? process.cwd(), args.path)
|
|
1998
1912
|
);
|
|
1999
1913
|
logger.log(
|
|
2000
|
-
`${
|
|
1914
|
+
`${chalk8.green(
|
|
2001
1915
|
"success"
|
|
2002
1916
|
)} - GraphQL schema, types, and optimizations successfully generated \u{1F389}`
|
|
2003
1917
|
);
|
|
@@ -2006,14 +1920,14 @@ var Generate2 = class _Generate extends Command9 {
|
|
|
2006
1920
|
|
|
2007
1921
|
// src/commands/cache-graphql.ts
|
|
2008
1922
|
import { Args as Args10, Command as Command10, Flags as Flags4 } from "@oclif/core";
|
|
2009
|
-
import
|
|
1923
|
+
import chalk9 from "chalk";
|
|
2010
1924
|
import fsExtra7 from "fs-extra";
|
|
2011
1925
|
import graphql from "graphql";
|
|
2012
|
-
import
|
|
2013
|
-
import { pathToFileURL as
|
|
1926
|
+
import path14 from "path";
|
|
1927
|
+
import { pathToFileURL as pathToFileURL7 } from "url";
|
|
2014
1928
|
var { Kind: Kind2, OperationTypeNode, parse: parseGraphql } = graphql;
|
|
2015
1929
|
var persistedDocumentsName = "persisted-documents.json";
|
|
2016
|
-
var
|
|
1930
|
+
var configFileName = "discovery.config.default.js";
|
|
2017
1931
|
var cachedOperationsFileName = "cached-operations.json";
|
|
2018
1932
|
var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
2019
1933
|
static flags = {
|
|
@@ -2035,15 +1949,15 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2035
1949
|
async run() {
|
|
2036
1950
|
const { args, flags } = await this.parse(_CacheGraphql);
|
|
2037
1951
|
const rootPath = getBasePath();
|
|
2038
|
-
const argPath = args?.store &&
|
|
1952
|
+
const argPath = args?.store && path14.resolve(rootPath, args.store) || rootPath;
|
|
2039
1953
|
const { tmpDir } = withBasePath(argPath);
|
|
2040
|
-
const configPath = this.getConfigFile(flags.config &&
|
|
1954
|
+
const configPath = this.getConfigFile(flags.config && path14.resolve(argPath, flags.config)) || this.getConfigFile(tmpDir) || this.getConfigFile(argPath);
|
|
2041
1955
|
const persistedDocumentsPath = this.getPersistedDocument(
|
|
2042
|
-
flags?.queries &&
|
|
1956
|
+
flags?.queries && path14.resolve(argPath, flags?.queries) || argPath
|
|
2043
1957
|
) || this.getPersistedDocument(tmpDir);
|
|
2044
1958
|
if (!configPath) {
|
|
2045
1959
|
return this.errorFileNotFound(
|
|
2046
|
-
|
|
1960
|
+
configFileName,
|
|
2047
1961
|
`
|
|
2048
1962
|
${tmpDir}
|
|
2049
1963
|
${argPath}`
|
|
@@ -2055,28 +1969,28 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2055
1969
|
flags?.queries ?? argPath
|
|
2056
1970
|
);
|
|
2057
1971
|
}
|
|
2058
|
-
const cachedOperationsPath =
|
|
2059
|
-
|
|
1972
|
+
const cachedOperationsPath = path14.join(
|
|
1973
|
+
path14.dirname(persistedDocumentsPath),
|
|
2060
1974
|
cachedOperationsFileName
|
|
2061
1975
|
);
|
|
2062
1976
|
const saveCachedOperationsFile = saveFile(cachedOperationsPath);
|
|
2063
1977
|
if (fsExtra7.pathExistsSync(tmpDir))
|
|
2064
|
-
logger.info(`${
|
|
2065
|
-
logger.info(`${
|
|
1978
|
+
logger.info(`${chalk9.blue("[Info]")} - .faststore Path at: ${tmpDir}`);
|
|
1979
|
+
logger.info(`${chalk9.blue("[Info]")} - Config file location: ${configPath}`);
|
|
2066
1980
|
logger.info(
|
|
2067
|
-
`${
|
|
1981
|
+
`${chalk9.blue("[Info]")} - Persisted documents at: ${persistedDocumentsPath}`
|
|
2068
1982
|
);
|
|
2069
1983
|
logger.info(
|
|
2070
|
-
`${
|
|
1984
|
+
`${chalk9.blue("[Info]")} - Cached operations output: ${cachedOperationsPath}`
|
|
2071
1985
|
);
|
|
2072
|
-
const { default: persistedDocuments } = await import(
|
|
1986
|
+
const { default: persistedDocuments } = await import(pathToFileURL7(persistedDocumentsPath).href, { with: { type: "json" } });
|
|
2073
1987
|
const cachedQueries = getQueries(persistedDocuments);
|
|
2074
1988
|
saveCachedOperationsFile(
|
|
2075
1989
|
`${JSON.stringify(cachedQueries ?? [], null, 2)}
|
|
2076
1990
|
`
|
|
2077
1991
|
);
|
|
2078
1992
|
logger.info(
|
|
2079
|
-
`${
|
|
1993
|
+
`${chalk9.green("[Success]")} - GraphQL queries cached with success: \u{1F389}
|
|
2080
1994
|
Queries: ${cachedQueries.join(", ")}`
|
|
2081
1995
|
);
|
|
2082
1996
|
}
|
|
@@ -2087,7 +2001,7 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2087
2001
|
])(rootPath);
|
|
2088
2002
|
}
|
|
2089
2003
|
getConfigFile(rootPath) {
|
|
2090
|
-
return this.getFile(
|
|
2004
|
+
return this.getFile(configFileName, [configFileName])(rootPath);
|
|
2091
2005
|
}
|
|
2092
2006
|
getFile(fileName, pathFromRoot) {
|
|
2093
2007
|
return (rootPath) => {
|
|
@@ -2096,11 +2010,11 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2096
2010
|
return;
|
|
2097
2011
|
case (rootPath?.endsWith(fileName) && fsExtra7.existsSync(rootPath)):
|
|
2098
2012
|
return rootPath;
|
|
2099
|
-
case fsExtra7.existsSync(
|
|
2100
|
-
return
|
|
2013
|
+
case fsExtra7.existsSync(path14.join(rootPath ?? "", fileName)):
|
|
2014
|
+
return path14.join(rootPath, fileName);
|
|
2101
2015
|
default:
|
|
2102
2016
|
if (!pathFromRoot) return;
|
|
2103
|
-
const filePath =
|
|
2017
|
+
const filePath = path14.join(
|
|
2104
2018
|
rootPath,
|
|
2105
2019
|
...Array.isArray(pathFromRoot) ? pathFromRoot : [pathFromRoot]
|
|
2106
2020
|
);
|
|
@@ -2113,7 +2027,7 @@ var CacheGraphql = class _CacheGraphql extends Command10 {
|
|
|
2113
2027
|
}
|
|
2114
2028
|
errorFileNotFound(fileName, rootDir) {
|
|
2115
2029
|
logger.error(
|
|
2116
|
-
`${
|
|
2030
|
+
`${chalk9.red("[Error]")} - Couldn't find ${fileName} at ${rootDir}`
|
|
2117
2031
|
);
|
|
2118
2032
|
process.exit(1);
|
|
2119
2033
|
}
|
|
@@ -2150,6 +2064,69 @@ import fsExtra8 from "fs-extra";
|
|
|
2150
2064
|
import { existsSync as existsSync11 } from "fs";
|
|
2151
2065
|
import path16 from "path";
|
|
2152
2066
|
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
|
|
2153
2130
|
import { pathToFileURL as pathToFileURL9 } from "url";
|
|
2154
2131
|
var configFileName3 = "discovery.config.default.js";
|
|
2155
2132
|
var GenerateI18n = class _GenerateI18n extends Command11 {
|