@graphcommerce/cli 9.0.0-canary.98 → 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.
- package/CHANGELOG.md +55 -998
- package/dist/bin/codegen.js +59 -78
- package/dist/bin/graphcommerce.js +13 -35
- package/dist/bin/is-monorepo.js +38 -36
- package/dist/bin/mesh.js +175 -150
- package/package.json +28 -32
- package/src/bin/codegen.ts +6 -5
- package/src/bin/graphcommerce.ts +2 -0
- package/src/bin/is-monorepo.ts +38 -18
- package/src/bin/mesh.ts +40 -28
- package/src/utils/findConfig.ts +3 -3
- package/tsconfig.json +3 -1
- package/dist/index.js +0 -2
- package/dist/utils/findConfig.js +0 -71
package/dist/bin/codegen.js
CHANGED
|
@@ -1,89 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
11
|
+
dotenv.config();
|
|
17
12
|
const root = process.cwd();
|
|
18
|
-
const configLocation =
|
|
13
|
+
const configLocation = path.join(root, "._tmp_codegen.yml");
|
|
19
14
|
async function cleanup() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
});
|
package/dist/bin/is-monorepo.js
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 =
|
|
55
|
-
const relativePath =
|
|
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
|
-
|
|
58
|
-
|
|
88
|
+
...DEFAULT_CLI_PARAMS,
|
|
89
|
+
playgroundTitle: "GraphCommerce\xAE Mesh"
|
|
59
90
|
};
|
|
60
|
-
const tmpMesh =
|
|
61
|
-
const tmpMeshLocation =
|
|
91
|
+
const tmpMesh = "_tmp_mesh";
|
|
92
|
+
const tmpMeshLocation = path$1.join(root, `.${tmpMesh}rc.yml`);
|
|
62
93
|
async function cleanup() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
conf.additionalTypeDefs.push(
|
|
122
|
-
|
|
123
|
-
conf.additionalTypeDefs.push(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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(
|
|
155
|
-
process.on(
|
|
178
|
+
process.on("SIGINT", cleanup);
|
|
179
|
+
process.on("SIGTERM", cleanup);
|
|
156
180
|
main().catch((e) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
181
|
+
cleanup();
|
|
182
|
+
if (e instanceof Error) {
|
|
183
|
+
handleFatalError(e, new DefaultLogger(DEFAULT_CLI_PARAMS.initialLoggerPrefix));
|
|
184
|
+
}
|
|
162
185
|
});
|
|
186
|
+
|
|
187
|
+
export { handleFatalError };
|