@graphcommerce/cli 9.0.0-canary.99 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,89 +1,70 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- /* eslint-disable import/no-extraneous-dependencies */
8
- const promises_1 = __importDefault(require("node:fs/promises"));
9
- const node_path_1 = __importDefault(require("node:path"));
10
- const next_config_1 = require("@graphcommerce/next-config");
11
- const cli_1 = require("@graphql-codegen/cli");
12
- const dotenv_1 = __importDefault(require("dotenv"));
13
- const rimraf_1 = require("rimraf");
14
- const yaml_1 = __importDefault(require("yaml"));
2
+ import { resolveDependenciesSync, packageRoots } from '@graphcommerce/next-config';
3
+ import { cliError, loadCodegenConfig, runCli } from '@graphql-codegen/cli';
4
+ import dotenv from 'dotenv';
5
+ import fs from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { rimraf } from 'rimraf';
8
+ import yaml from 'yaml';
9
+
15
10
  const [, , cmd] = process.argv;
16
- dotenv_1.default.config();
11
+ dotenv.config();
17
12
  const root = process.cwd();
18
- const configLocation = node_path_1.default.join(root, `._tmp_codegen.yml`);
13
+ const configLocation = path.join(root, "._tmp_codegen.yml");
19
14
  async function cleanup() {
20
- try {
21
- await promises_1.default.stat(configLocation).then((r) => {
22
- if (r.isFile())
23
- return promises_1.default.unlink(configLocation);
24
- return undefined;
25
- });
26
- }
27
- catch (e) {
28
- // ignore
29
- }
30
- return undefined;
15
+ try {
16
+ await fs.stat(configLocation).then((r) => {
17
+ if (r.isFile()) return fs.unlink(configLocation);
18
+ return void 0;
19
+ });
20
+ } catch (e) {
21
+ }
22
+ return void 0;
31
23
  }
32
24
  function appendDocumentLocations(conf, packages) {
33
- const documents = Array.isArray(conf.documents) ? conf.documents : [conf.documents];
34
- documents.push(...packages.map((p) => `${p}/**/*.graphql`));
35
- return conf;
25
+ const documents = Array.isArray(conf.documents) ? conf.documents : [conf.documents];
26
+ documents.push(...packages.map((p) => `${p}/**/*.graphql`));
27
+ return conf;
36
28
  }
37
29
  async function main() {
38
- // Make sure we dont already have a --config or -c cli argument as we're going to override it.
39
- if (process.argv.includes('--config') || process.argv.includes('-c')) {
40
- throw Error('--config or -c argument is not supported, modify codegen.yml to make changes');
41
- }
42
- const deps = (0, next_config_1.resolveDependenciesSync)();
43
- const packages = [...deps.values()].filter((p) => p !== '.');
44
- // Load the current codegen.yml
45
- // Todo: implement loading with a custom --config or -c here.
46
- const conf = await (0, cli_1.loadCodegenConfig)({ configFilePath: root });
47
- // Get a a list of all generates configurations.
48
- const generates = Object.entries(conf.config.generates).map(([generatedPath, value]) => {
49
- const found = [...deps.entries()].find((dep) => generatedPath.startsWith(`node_modules/${dep[0]}`));
50
- if (!found)
51
- return [generatedPath, value];
52
- const newPath = generatedPath.replace(`node_modules/${found[0]}`, found[1]);
53
- return [newPath, value];
54
- });
55
- let extension;
56
- // Find the file extension used for the generated graphql files and cleanup if not used anymore.
57
- generates.forEach(([, gen]) => {
58
- if (Array.isArray(gen))
59
- return;
60
- if (gen.presetConfig?.extension)
61
- extension = gen.presetConfig.extension;
62
- });
63
- const isWatching = process.argv.includes('--watch') || process.argv.includes('-w');
64
- if (!isWatching && extension)
65
- await (0, rimraf_1.rimraf)(node_path_1.default.join(root, `**/*${extension}`));
66
- // - Prepend the all targets with ../../ if we're running in a monorepo setup.
67
- // - Append all the Graphcommerce packages to the configuration
68
- conf.config.generates = Object.fromEntries(generates.map(([generateTarget, generateConf]) => [
69
- generateTarget,
70
- Array.isArray(generateConf) ? generateConf : appendDocumentLocations(generateConf, packages),
71
- ]));
72
- (0, next_config_1.packageRoots)(packages).forEach((r) => {
73
- conf.config.generates[r] = conf.config.generates['.'];
74
- });
75
- // Reexport the mesh to is can be used by codegen
76
- await promises_1.default.writeFile(configLocation, yaml_1.default.stringify(conf.config));
77
- // Append the new cli argument
78
- process.argv.push('--config');
79
- process.argv.push(configLocation);
80
- // Run the cli
81
- const result = await (0, cli_1.runCli)(cmd);
82
- await cleanup();
83
- process.exit(result);
30
+ if (process.argv.includes("--config") || process.argv.includes("-c")) {
31
+ throw Error("--config or -c argument is not supported, modify codegen.yml to make changes");
32
+ }
33
+ const deps = resolveDependenciesSync();
34
+ const packages = [...deps.values()].filter((p) => p !== ".");
35
+ const conf = await loadCodegenConfig({ configFilePath: root });
36
+ const generates = Object.entries(conf.config.generates).map(([generatedPath, value]) => {
37
+ const found = [...deps.entries()].find(
38
+ (dep) => generatedPath.startsWith(`node_modules/${dep[0]}`)
39
+ );
40
+ if (!found) return [generatedPath, value];
41
+ const newPath = generatedPath.replace(`node_modules/${found[0]}`, found[1]);
42
+ return [newPath, value];
43
+ });
44
+ let extension;
45
+ generates.forEach(([, gen]) => {
46
+ if (Array.isArray(gen)) return;
47
+ if (gen.presetConfig?.extension) extension = gen.presetConfig.extension;
48
+ });
49
+ const isWatching = process.argv.includes("--watch") || process.argv.includes("-w");
50
+ if (!isWatching && extension) await rimraf(path.join(root, `**/*${extension}`));
51
+ conf.config.generates = Object.fromEntries(
52
+ generates.map(([generateTarget, generateConf]) => [
53
+ generateTarget,
54
+ Array.isArray(generateConf) ? generateConf : appendDocumentLocations(generateConf, packages)
55
+ ])
56
+ );
57
+ packageRoots(packages).forEach((r) => {
58
+ conf.config.generates[r] = conf.config.generates["."];
59
+ });
60
+ await fs.writeFile(configLocation, yaml.stringify(conf.config));
61
+ process.argv.push("--config");
62
+ process.argv.push(configLocation);
63
+ const result = await runCli(cmd);
64
+ await cleanup();
65
+ process.exit(result);
84
66
  }
85
67
  main().catch((e) => {
86
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
87
- cleanup();
88
- (0, cli_1.cliError)(e);
68
+ cleanup();
69
+ cliError(e);
89
70
  });
@@ -1,43 +1,21 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
2
  const commands = {
27
- 'codegen-config': () => Promise.resolve().then(() => __importStar(require('@graphcommerce/next-config'))).then((m) => m.generateConfig),
28
- 'codegen-interceptors': () => Promise.resolve().then(() => __importStar(require('@graphcommerce/next-config'))).then((m) => m.codegenInterceptors),
29
- 'export-config': () => Promise.resolve().then(() => __importStar(require('@graphcommerce/next-config'))).then((m) => m.exportConfig),
30
- 'hygraph-migrate': () => Promise.resolve().then(() => __importStar(require('@graphcommerce/hygraph-cli'))).then((m) => m.migrateHygraph),
3
+ codegen: () => import('@graphcommerce/next-config').then((m) => m.codegen),
4
+ "codegen-config": () => import('@graphcommerce/next-config').then((m) => m.generateConfig),
5
+ "copy-files": () => import('@graphcommerce/next-config').then((m) => m.copyFiles),
6
+ "codegen-interceptors": () => import('@graphcommerce/next-config').then((m) => m.codegenInterceptors),
7
+ "export-config": () => import('@graphcommerce/next-config').then((m) => m.exportConfig),
8
+ "hygraph-migrate": () => import('@graphcommerce/hygraph-cli').then((m) => m.migrateHygraph)
31
9
  };
32
10
  const args = process.argv.slice(2);
33
11
  const command = args[0];
34
12
  if (!(command in commands)) {
35
- console.error(`Unknown command: ${args.join(' ')}, possible commands: ${Object.keys(commands).join(', ')}`);
36
- process.exit(1);
13
+ console.error(
14
+ `Unknown command: ${args.join(" ")}, possible commands: ${Object.keys(commands).join(", ")}`
15
+ );
16
+ process.exit(1);
37
17
  }
38
- commands[command]()
39
- .then((c) => c())
40
- .catch((e) => {
41
- console.error(e);
42
- process.exit(1);
18
+ commands[command]().then((c) => c()).catch((e) => {
19
+ console.error(e);
20
+ process.exit(1);
43
21
  });
@@ -1,40 +1,42 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const node_child_process_1 = require("node:child_process");
5
- const next_config_1 = require("@graphcommerce/next-config");
6
- const detect_package_manager_1 = require("detect-package-manager");
7
- /**
8
- * Executes a command dependening if we're running in a monorepo or not Usage:
9
- *
10
- * is-monorepo '[pkgrun] run my-script' '[pkgrun] run my-other-script'
11
- *
12
- * We're using the `[pkgrun]` placeholder to replace it with the package manager we're using. For
13
- * example, if we're using `yarn` it will replace `[pkgrun]` with `yarn`. If we're using `npm` it
14
- * will replace `[pkgrun]` with `npm run`.
15
- */
2
+ import { spawn } from 'node:child_process';
3
+ import path from 'node:path';
4
+ import { findParentPath } from '@graphcommerce/next-config';
5
+ import { detect } from 'detect-package-manager';
6
+
7
+ const debug = process.env.DEBUG === "1";
8
+ const log = (message) => debug && console.log(`is-monorepo: ${message}`);
9
+ const logError = (message) => console.error(`is-monorepo: ${message}`);
16
10
  async function main() {
17
- const isMono = (0, next_config_1.isMonorepo)();
18
- const command = isMono ? process.argv.slice(2)[0] : process.argv.slice(2)[1];
19
- let packageManager = 'yarn';
20
- try {
21
- packageManager = await (0, detect_package_manager_1.detect)({ cwd: isMono ? `../..` : `.` });
22
- }
23
- catch {
24
- console.error('Could not detect package manager, defaulting to yarn');
25
- }
26
- const commandArray = command
27
- .split(' ')
28
- .map((arg) => arg.replace('[pkgrun]', `${packageManager} run`));
29
- if (isMono)
30
- commandArray.unshift('cd', '../..', '&&');
31
- const [cmd, ...args] = commandArray;
32
- const childProcess = (0, node_child_process_1.spawn)(cmd, args, { shell: true, stdio: 'inherit' });
33
- childProcess.on('exit', (code) => {
34
- process.exit(code ?? 0);
35
- });
36
- }
37
- main().catch((error) => {
38
- console.error(error);
11
+ const parentPath = findParentPath(process.cwd());
12
+ const command = parentPath ? process.argv.slice(2)[0] : process.argv.slice(2)[1];
13
+ if (!command) {
14
+ logError("No command provided");
39
15
  process.exit(1);
16
+ }
17
+ let packageManager = "yarn";
18
+ try {
19
+ packageManager = await detect({ cwd: "." });
20
+ } catch {
21
+ log("Could not detect package manager, defaulting to yarn");
22
+ }
23
+ const relativePath = parentPath ? `cd ${path.relative(process.cwd(), parentPath)}/` : "cd .";
24
+ const commandArray = command.split(" ").map(
25
+ (arg) => arg.replace("[pkgrun]", `${packageManager}${packageManager === "npm" ? " run" : ""}`)
26
+ );
27
+ log(`Command: ${commandArray.join(" ")}`);
28
+ const finalCommand = `${relativePath} && ${commandArray.join(" ")}`;
29
+ log(`Executing: ${finalCommand}`);
30
+ const childProcess = spawn(finalCommand, [], { shell: true, stdio: "inherit" });
31
+ childProcess.on("exit", (code) => {
32
+ process.exit(code ?? 0);
33
+ });
34
+ }
35
+ main().catch((err) => {
36
+ if (err instanceof Error) {
37
+ logError(err.message);
38
+ } else {
39
+ logError("An unknown error occurred");
40
+ }
41
+ process.exit(1);
40
42
  });
package/dist/bin/mesh.js CHANGED
@@ -1,162 +1,187 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
2
+ import { promises } from 'node:fs';
3
+ import path$1 from 'node:path';
4
+ import { exit } from 'node:process';
5
+ import { loadConfig, resolveDependenciesSync, sig, packageRoots, replaceConfigInString } from '@graphcommerce/next-config';
6
+ import { DEFAULT_CLI_PARAMS, graphqlMesh } from '@graphql-mesh/cli';
7
+ import { DefaultLogger, defaultImportFn, loadYaml, fileURLToPath } from '@graphql-mesh/utils';
8
+ import dotenv from 'dotenv';
9
+ import 'tsx/cjs';
10
+ import 'tsx/esm';
11
+ import yaml from 'yaml';
12
+ import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
13
+ import path from 'path';
14
+
15
+ function customLoader(ext, importFn = defaultImportFn, initialLoggerPrefix = "\u{1F578}\uFE0F Mesh") {
16
+ const logger = new DefaultLogger(initialLoggerPrefix).child("config");
17
+ function loader(filepath, content) {
18
+ if (process.env) {
19
+ content = content.replace(/\$\{(.*?)\}/g, (_, variable) => {
20
+ let varName = variable;
21
+ let defaultValue = "";
22
+ if (variable.includes(":")) {
23
+ const spl = variable.split(":");
24
+ varName = spl.shift();
25
+ defaultValue = spl.join(":");
26
+ }
27
+ return process.env[varName] || defaultValue;
28
+ });
8
29
  }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.handleFatalError = handleFatalError;
31
- /* eslint-disable import/no-extraneous-dependencies */
32
- const node_fs_1 = require("node:fs");
33
- const node_path_1 = __importDefault(require("node:path"));
34
- const node_process_1 = require("node:process");
35
- const next_config_1 = require("@graphcommerce/next-config");
36
- const cli_1 = require("@graphql-mesh/cli");
37
- const utils_1 = require("@graphql-mesh/utils");
38
- const dotenv_1 = __importDefault(require("dotenv"));
39
- const yaml_1 = __importDefault(require("yaml"));
40
- const findConfig_1 = require("../utils/findConfig");
41
- // eslint-disable-next-line import/no-unresolved
42
- require("tsx/cjs"); // support importing typescript configs in CommonJS
43
- // eslint-disable-next-line import/no-unresolved
44
- require("tsx/esm"); // support importing typescript configs in ESM
45
- dotenv_1.default.config();
46
- function handleFatalError(e, logger = new utils_1.DefaultLogger('◈')) {
47
- logger.error(e.stack || e.message);
48
- // eslint-disable-next-line no-console
49
- console.log(e);
50
- if (process.env.JEST == null)
51
- (0, node_process_1.exit)(1);
30
+ if (ext === "json") {
31
+ return defaultLoaders[".json"](filepath, content);
32
+ }
33
+ if (ext === "yaml") {
34
+ return loadYaml(filepath, content, logger);
35
+ }
36
+ if (ext === "js") {
37
+ return importFn(filepath);
38
+ }
39
+ }
40
+ return loader;
41
+ }
42
+ async function findConfig(options) {
43
+ const { configName = "mesh", dir: configDir = "", initialLoggerPrefix } = options || {};
44
+ const dir = path.isAbsolute(configDir) ? configDir : path.join(process.cwd(), configDir);
45
+ const explorer = cosmiconfig(configName, {
46
+ searchPlaces: [
47
+ "package.json",
48
+ `.${configName}rc`,
49
+ `.${configName}rc.json`,
50
+ `.${configName}rc.yaml`,
51
+ `.${configName}rc.yml`,
52
+ `.${configName}rc.js`,
53
+ `.${configName}rc.ts`,
54
+ `.${configName}rc.cjs`,
55
+ `${configName}.config.js`,
56
+ `${configName}.config.cjs`
57
+ ],
58
+ loaders: {
59
+ ".json": customLoader("json", options?.importFn, initialLoggerPrefix),
60
+ ".yaml": customLoader("yaml", options?.importFn, initialLoggerPrefix),
61
+ ".yml": customLoader("yaml", options?.importFn, initialLoggerPrefix),
62
+ ".js": customLoader("js", options?.importFn, initialLoggerPrefix),
63
+ ".ts": customLoader("js", options?.importFn, initialLoggerPrefix),
64
+ noExt: customLoader("yaml", options?.importFn, initialLoggerPrefix)
65
+ }
66
+ });
67
+ const results = await explorer.search(dir);
68
+ if (!results) {
69
+ throw new Error(`No ${configName} config file found in "${dir}"!`);
70
+ }
71
+ const { config } = results;
72
+ return config;
73
+ }
74
+
75
+ dotenv.config();
76
+ function resolvePath(pathStr) {
77
+ return fileURLToPath(import.meta.resolve(pathStr));
78
+ }
79
+ function handleFatalError(e, logger = new DefaultLogger("\u25C8")) {
80
+ logger.error(e.stack || e.message);
81
+ console.log(e);
82
+ if (process.env.JEST == null) exit(1);
52
83
  }
53
84
  const root = process.cwd();
54
- const meshDir = node_path_1.default.dirname(require.resolve('@graphcommerce/graphql-mesh'));
55
- const relativePath = node_path_1.default.join(node_path_1.default.relative(meshDir, root), '/');
85
+ const meshDir = path$1.dirname(resolvePath("@graphcommerce/graphql-mesh"));
86
+ const relativePath = path$1.join(path$1.relative(meshDir, root), "/");
56
87
  const cliParams = {
57
- ...cli_1.DEFAULT_CLI_PARAMS,
58
- playgroundTitle: 'GraphCommerce® Mesh',
88
+ ...DEFAULT_CLI_PARAMS,
89
+ playgroundTitle: "GraphCommerce\xAE Mesh"
59
90
  };
60
- const tmpMesh = `_tmp_mesh`;
61
- const tmpMeshLocation = node_path_1.default.join(root, `.${tmpMesh}rc.yml`);
91
+ const tmpMesh = "_tmp_mesh";
92
+ const tmpMeshLocation = path$1.join(root, `.${tmpMesh}rc.yml`);
62
93
  async function cleanup() {
63
- try {
64
- await node_fs_1.promises.stat(tmpMeshLocation).then((r) => {
65
- if (r.isFile())
66
- return node_fs_1.promises.unlink(tmpMeshLocation);
67
- return undefined;
68
- });
69
- }
70
- catch (e) {
71
- // ignore
72
- }
73
- return undefined;
94
+ try {
95
+ await promises.stat(tmpMeshLocation).then((r) => {
96
+ if (r.isFile()) return promises.unlink(tmpMeshLocation);
97
+ return void 0;
98
+ });
99
+ } catch (e) {
100
+ }
101
+ return void 0;
74
102
  }
75
103
  const main = async () => {
76
- const baseConf = (await (0, findConfig_1.findConfig)({}));
77
- const graphCommerce = (0, next_config_1.loadConfig)(root);
78
- // eslint-disable-next-line global-require
79
- // @ts-ignore Might not exist
80
- const { meshConfig } = (await Promise.resolve().then(() => __importStar(require('@graphcommerce/graphql-mesh/meshConfig.interceptor'))));
81
- const conf = meshConfig(baseConf, graphCommerce);
82
- // We're configuring a custom fetch function
83
- conf.customFetch = '@graphcommerce/graphql-mesh/customFetch';
84
- conf.serve = { ...conf.serve, endpoint: '/api/graphql' };
85
- // Rewrite additionalResolvers so we can use module resolution more easily
86
- conf.additionalResolvers = conf.additionalResolvers ?? [];
87
- conf.additionalResolvers = conf.additionalResolvers?.map((additionalResolver) => {
88
- if (typeof additionalResolver !== 'string')
89
- return additionalResolver;
90
- if (additionalResolver.startsWith('@'))
91
- return node_path_1.default.relative(root, require.resolve(additionalResolver));
92
- return additionalResolver;
93
- });
94
- conf.sources = conf.sources.map((source) => {
95
- const definedHandlers = Object.entries(source.handler);
96
- return {
97
- ...source,
98
- handler: Object.fromEntries(definedHandlers.map(([key, value]) => {
99
- if (key === 'openapi' && value) {
100
- const openapi = value;
101
- if (openapi.source.startsWith('@')) {
102
- return [
103
- key,
104
- { ...openapi, source: node_path_1.default.relative(root, require.resolve(openapi.source)) },
105
- ];
106
- }
107
- }
108
- return [key, value];
109
- })),
110
- };
111
- });
112
- // Rewrite additionalTypeDefs so we can use module resolution more easily
113
- if (!conf.additionalTypeDefs)
114
- conf.additionalTypeDefs = [];
115
- conf.additionalTypeDefs = (Array.isArray(conf.additionalTypeDefs) ? conf.additionalTypeDefs : [conf.additionalTypeDefs]).map((additionalTypeDef) => {
116
- if (typeof additionalTypeDef === 'string' && additionalTypeDef.startsWith('@'))
117
- return node_path_1.default.relative(root, require.resolve(additionalTypeDef));
118
- return additionalTypeDef;
119
- });
120
- // Scan the current working directory to also read all graphqls files.
121
- conf.additionalTypeDefs.push('graphql/**/*.graphqls');
122
- conf.additionalTypeDefs.push('components/**/*.graphqls');
123
- conf.additionalTypeDefs.push('lib/**/*.graphqls');
124
- conf.additionalTypeDefs.push('app/**/*.graphqls');
125
- const deps = (0, next_config_1.resolveDependenciesSync)();
126
- const packages = [...deps.values()].filter((p) => p !== '.');
127
- const mV = graphCommerce.magentoVersion ?? 246;
128
- (0, next_config_1.packageRoots)(packages).forEach((r) => {
129
- const alsoScan = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254]
130
- .filter((v) => v > mV)
131
- .map((v) => `${r}/*/schema-${v}/**/*.graphqls`);
132
- conf.additionalTypeDefs.push(`${r}/*/schema/**/*.graphqls`);
133
- conf.additionalTypeDefs.push(...alsoScan);
134
- });
135
- if (!conf.serve)
136
- conf.serve = {};
137
- if (!conf.serve.playgroundTitle)
138
- conf.serve.playgroundTitle = 'GraphCommerce® Mesh';
139
- conf.plugins = [
140
- ...(conf.plugins ?? []),
141
- {
142
- httpDetailsExtensions: {
143
- if: "env.NODE_ENV === 'development'",
144
- },
145
- },
146
- ];
147
- const yamlString = (0, next_config_1.replaceConfigInString)(yaml_1.default.stringify(conf), graphCommerce);
148
- await node_fs_1.promises.writeFile(tmpMeshLocation, yamlString);
149
- // Reexport the mesh to is can be used by packages
150
- await node_fs_1.promises.writeFile(`${meshDir}/.mesh.ts`, `export * from '${relativePath.split(node_path_1.default.sep).join('/')}.mesh'`, { encoding: 'utf8' });
151
- await (0, cli_1.graphqlMesh)({ ...cliParams, configName: tmpMesh });
152
- await cleanup();
104
+ const baseConf = await findConfig({});
105
+ const graphCommerce = loadConfig(root);
106
+ const meshConfigf = await import('@graphcommerce/graphql-mesh/meshConfig.interceptor');
107
+ const conf = meshConfigf.default.meshConfig(baseConf, graphCommerce);
108
+ conf.customFetch = "@graphcommerce/graphql-mesh/customFetch";
109
+ conf.serve = { ...conf.serve, endpoint: "/api/graphql" };
110
+ conf.additionalResolvers = conf.additionalResolvers ?? [];
111
+ conf.additionalResolvers = conf.additionalResolvers?.map((additionalResolver) => {
112
+ if (typeof additionalResolver !== "string") return additionalResolver;
113
+ if (additionalResolver.startsWith("@"))
114
+ return path$1.relative(root, resolvePath(additionalResolver));
115
+ return additionalResolver;
116
+ });
117
+ conf.sources = conf.sources.map((source) => {
118
+ const definedHandlers = Object.entries(source.handler);
119
+ return {
120
+ ...source,
121
+ handler: Object.fromEntries(
122
+ definedHandlers.map(([key, value]) => {
123
+ if (key === "openapi" && value) {
124
+ const openapi = value;
125
+ if (openapi.source.startsWith("@")) {
126
+ return [key, { ...openapi, source: path$1.relative(root, resolvePath(openapi.source)) }];
127
+ }
128
+ }
129
+ return [key, value];
130
+ })
131
+ )
132
+ };
133
+ });
134
+ if (!conf.additionalTypeDefs) conf.additionalTypeDefs = [];
135
+ conf.additionalTypeDefs = (Array.isArray(conf.additionalTypeDefs) ? conf.additionalTypeDefs : [conf.additionalTypeDefs]).map((additionalTypeDef) => {
136
+ if (typeof additionalTypeDef === "string" && additionalTypeDef.startsWith("@"))
137
+ return path$1.relative(root, resolvePath(additionalTypeDef));
138
+ return additionalTypeDef;
139
+ });
140
+ conf.additionalTypeDefs.push("graphql/**/*.graphqls");
141
+ conf.additionalTypeDefs.push("components/**/*.graphqls");
142
+ conf.additionalTypeDefs.push("lib/**/*.graphqls");
143
+ conf.additionalTypeDefs.push("app/**/*.graphqls");
144
+ const deps = resolveDependenciesSync();
145
+ const packages = [...deps.values()].filter((p) => p !== ".");
146
+ const mV = graphCommerce.magentoVersion ?? 246;
147
+ sig();
148
+ packageRoots(packages).forEach((r) => {
149
+ conf.additionalTypeDefs.push(`${r}/*/schema/**/*.graphqls`);
150
+ const scanVersions = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254].filter((v) => v > mV).map((v) => `${r}/*/schema-${v}/**/*.graphqls`);
151
+ conf.additionalTypeDefs.push(...scanVersions);
152
+ if (globalThis.gcl?.includes(atob("QGdyYXBoY29tbWVyY2UvYWRvYmUtY29tbWVyY2U="))) {
153
+ conf.additionalTypeDefs.push(`${r}/*/schema-ac/**/*.graphqls`);
154
+ const scanVersionAC = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254].filter((v) => v > mV).map((v) => `${r}/*/schema-ac-${v}/**/*.graphqls`);
155
+ conf.additionalTypeDefs.push(...scanVersionAC);
156
+ }
157
+ });
158
+ if (!conf.serve) conf.serve = {};
159
+ if (!conf.serve.playgroundTitle) conf.serve.playgroundTitle = "GraphCommerce\xAE Mesh";
160
+ conf.plugins = [
161
+ ...conf.plugins ?? [],
162
+ {
163
+ httpDetailsExtensions: {
164
+ if: "env.NODE_ENV === 'development'"
165
+ }
166
+ }
167
+ ];
168
+ const yamlString = replaceConfigInString(yaml.stringify(conf), graphCommerce);
169
+ await promises.writeFile(tmpMeshLocation, yamlString);
170
+ await promises.writeFile(
171
+ `${meshDir}/.mesh.ts`,
172
+ `export * from '${relativePath.split(path$1.sep).join("/")}.mesh'`,
173
+ { encoding: "utf8" }
174
+ );
175
+ await graphqlMesh({ ...cliParams, configName: tmpMesh });
176
+ await cleanup();
153
177
  };
154
- process.on('SIGINT', cleanup);
155
- process.on('SIGTERM', cleanup);
178
+ process.on("SIGINT", cleanup);
179
+ process.on("SIGTERM", cleanup);
156
180
  main().catch((e) => {
157
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
158
- cleanup();
159
- if (e instanceof Error) {
160
- handleFatalError(e, new utils_1.DefaultLogger(cli_1.DEFAULT_CLI_PARAMS.initialLoggerPrefix));
161
- }
181
+ cleanup();
182
+ if (e instanceof Error) {
183
+ handleFatalError(e, new DefaultLogger(DEFAULT_CLI_PARAMS.initialLoggerPrefix));
184
+ }
162
185
  });
186
+
187
+ export { handleFatalError };