@graphcommerce/cli 1.0.10 → 4.30.0-canary.1

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @graphcommerce/cli
2
2
 
3
+ ## 4.30.0-canary.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`abb15ef4a`](https://github.com/graphcommerce-org/graphcommerce/commit/abb15ef4a79b12eddb32cc006e5d1d31dd06ac2d) Thanks [@paales](https://github.com/paales)! - Added canary releases to GraphCommerce
8
+
9
+ ## 4.30.0-canary.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#1613](https://github.com/graphcommerce-org/graphcommerce/pull/1613) [`1ef81efa2`](https://github.com/graphcommerce-org/graphcommerce/commit/1ef81efa238b2e79312ab35c6829abec266e4ad1) Thanks [@paales](https://github.com/paales)! - All codegen files that need to be scanned will be handled by a new resolveDependenciesSync method
14
+
15
+ - [#1613](https://github.com/graphcommerce-org/graphcommerce/pull/1613) [`da20e4e72`](https://github.com/graphcommerce-org/graphcommerce/commit/da20e4e72ca3f29216592e0ecfb59c0e44bcbe20) Thanks [@paales](https://github.com/paales)! - Created an is-monorepo command to exectute scripts based if they are in the monorepo or in a project
16
+
17
+ ### Patch Changes
18
+
19
+ - [#1613](https://github.com/graphcommerce-org/graphcommerce/pull/1613) [`6c1c69ca4`](https://github.com/graphcommerce-org/graphcommerce/commit/6c1c69ca45ea1c8737cc7dcdc341fe5d825ed380) Thanks [@paales](https://github.com/paales)! - Refactor next-config to also use the new resolveDependenciesSync by exposing withGraphCommerce
20
+
3
21
  ## 1.0.10
4
22
 
5
23
  ### Patch Changes
package/bin/codegen.ts CHANGED
@@ -1,15 +1,91 @@
1
1
  #!/usr/bin/env node
2
-
3
- import { runCli, cliError } from '@graphql-codegen/cli'
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ import fs from 'node:fs/promises'
4
+ import path from 'node:path'
5
+ import { resolveDependenciesSync } from '@graphcommerce/next-config'
6
+ import { runCli, cliError, loadCodegenConfig } from '@graphql-codegen/cli'
7
+ import { Types } from '@graphql-codegen/plugin-helpers'
8
+ import rimraf from 'rimraf'
9
+ import yaml from 'yaml'
4
10
 
5
11
  const [, , cmd] = process.argv
6
12
 
7
- // console.log(process.argv)
13
+ const root = process.cwd()
14
+ const configLocation = path.join(root, `._tmp_codegen.yml`)
8
15
 
9
- runCli(cmd)
10
- .then((result) => {
11
- process.exit(result)
12
- })
13
- .catch((error) => {
14
- cliError(error)
16
+ async function cleanup() {
17
+ try {
18
+ await fs.stat(configLocation).then((r) => {
19
+ if (r.isFile()) return fs.unlink(configLocation)
20
+ return undefined
21
+ })
22
+ } catch (e) {
23
+ // ignore
24
+ }
25
+ return undefined
26
+ }
27
+
28
+ function appendDocumentLocations(
29
+ conf: Types.ConfiguredOutput,
30
+ packages: string[],
31
+ ): Types.ConfiguredOutput {
32
+ const documents = Array.isArray(conf.documents) ? conf.documents : [conf.documents]
33
+ documents.push(...packages.map((p) => `${p}/**/*.graphql`))
34
+
35
+ return conf
36
+ }
37
+
38
+ async function main() {
39
+ // Make sure we dont already have a --config or -c cli argument as we're going to override it.
40
+ if (process.argv.includes('--config') || process.argv.includes('-c')) {
41
+ throw Error('--config or -c argument is not supported, modify codegen.yml to make changes')
42
+ }
43
+
44
+ const packages = [...resolveDependenciesSync().values()].filter((p) => p !== '.')
45
+
46
+ // Detect if we're operating in the monorepo environment or in an installation
47
+ const isMono = !!packages.find((p) => p.startsWith('../..'))
48
+
49
+ // Load the current codegen.yml
50
+ // Todo: implement loading with a custom --config or -c here.
51
+ const conf = await loadCodegenConfig({ configFilePath: root })
52
+
53
+ // Get a a list of all generates configurations.
54
+ const generates = Object.entries(conf.config.generates)
55
+
56
+ let extension: string | undefined
57
+
58
+ // Find the file extension used for the generated graphql files and cleanup if not used anymore.
59
+ generates.forEach(([, gen]) => {
60
+ if (Array.isArray(gen)) return
61
+ if (gen.presetConfig?.extension) extension = gen.presetConfig.extension
15
62
  })
63
+ if (extension) rimraf(path.join(root, `**/*${extension}`), console.error)
64
+
65
+ // - Prepend the all targets with ../../ if we're running in a monorepo setup.
66
+ // - Append all the Graphcommerce packages to the configuration
67
+ conf.config.generates = Object.fromEntries(
68
+ generates.map(([generateTarget, generateConf]) => [
69
+ isMono ? `../../${generateTarget}` : generateTarget,
70
+ Array.isArray(generateConf) ? generateConf : appendDocumentLocations(generateConf, packages),
71
+ ]),
72
+ )
73
+
74
+ // Reexport the mesh to is can be used by codegen
75
+ await fs.writeFile(configLocation, yaml.stringify(conf.config))
76
+
77
+ // Append the new cli argument
78
+ process.argv.push('--config')
79
+ process.argv.push(configLocation)
80
+
81
+ // Run the cli
82
+ const result = await runCli(cmd)
83
+ await cleanup()
84
+ process.exit(result)
85
+ }
86
+
87
+ main().catch((e) => {
88
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
89
+ cleanup()
90
+ cliError(e)
91
+ })
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ process.exit(1)
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { ChildProcess, spawn } from 'node:child_process'
4
+ import { isMonorepo } from '@graphcommerce/next-config'
5
+ import { detect } from 'detect-package-manager'
6
+
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
+ */
16
+ async function main() {
17
+ const isMono = isMonorepo()
18
+ const command = isMono ? process.argv.slice(2)[0] : process.argv.slice(2)[1]
19
+
20
+ let packageManager = 'yarn'
21
+ try {
22
+ packageManager = await detect({ cwd: isMono ? `../..` : `.` })
23
+ } catch {
24
+ console.error('Could not detect package manager, defaulting to yarn')
25
+ }
26
+
27
+ const commandArray = command
28
+ .split(' ')
29
+ .map((arg) => arg.replace('[pkgrun]', `${packageManager} run`))
30
+
31
+ if (isMono) commandArray.unshift('cd', '../..', '&&')
32
+
33
+ const [cmd, ...args] = commandArray
34
+ const childProcess: ChildProcess = spawn(cmd, args, { shell: true, stdio: 'inherit' })
35
+
36
+ childProcess.on('exit', (code) => {
37
+ process.exit(code ?? 0)
38
+ })
39
+ }
40
+
41
+ main().catch((error) => {
42
+ console.error(error)
43
+ process.exit(1)
44
+ })
package/bin/mesh.ts CHANGED
@@ -4,12 +4,13 @@
4
4
  import { promises as fs } from 'node:fs'
5
5
  import path from 'node:path'
6
6
  import { exit } from 'node:process'
7
+ import { isMonorepo } from '@graphcommerce/next-config'
7
8
  import { graphqlMesh, DEFAULT_CLI_PARAMS, GraphQLMeshCLIParams } from '@graphql-mesh/cli'
8
9
  import { Logger, YamlConfig } from '@graphql-mesh/types'
9
10
  import { DefaultLogger } from '@graphql-mesh/utils'
10
11
  import dotenv from 'dotenv'
11
12
  import yaml from 'yaml'
12
- import { findConfig } from '../mesh/findConfig'
13
+ import { findConfig } from '../utils/findConfig'
13
14
 
14
15
  dotenv.config()
15
16
 
@@ -24,14 +25,12 @@ const root = process.cwd()
24
25
  const meshDir = path.dirname(require.resolve('@graphcommerce/graphql-mesh'))
25
26
  const relativePath = path.join(path.relative(meshDir, root), '/')
26
27
 
27
- const isMonoRepo = relativePath.startsWith(`..${path.sep}..${path.sep}examples`)
28
-
29
28
  const cliParams: GraphQLMeshCLIParams = {
30
29
  ...DEFAULT_CLI_PARAMS,
31
30
  playgroundTitle: 'GraphCommerce® Mesh',
32
31
  }
33
32
 
34
- const tmpMesh = `_tmp_mesh_${Math.random().toString(36).substring(2, 15)}`
33
+ const tmpMesh = `_tmp_codegen`
35
34
  const tmpMeshLocation = path.join(root, `.${tmpMesh}rc.yml`)
36
35
 
37
36
  async function cleanup() {
@@ -71,7 +70,7 @@ const main = async () => {
71
70
 
72
71
  // Scan the current working directory to also read all graphqls files.
73
72
  conf.additionalTypeDefs.push('**/*.graphqls')
74
- if (isMonoRepo) {
73
+ if (isMonorepo()) {
75
74
  conf.additionalTypeDefs.push('../../packages/**/*.graphqls')
76
75
  conf.additionalTypeDefs.push('../../packagesDev/**/*.graphqls')
77
76
  } else {
@@ -98,4 +97,7 @@ const main = async () => {
98
97
  process.on('SIGINT', cleanup)
99
98
  process.on('SIGTERM', cleanup)
100
99
 
101
- main().catch((e) => handleFatalError(e, new DefaultLogger(DEFAULT_CLI_PARAMS.initialLoggerPrefix)))
100
+ main().catch((e) => {
101
+ cleanup()
102
+ return handleFatalError(e, new DefaultLogger(DEFAULT_CLI_PARAMS.initialLoggerPrefix))
103
+ })
@@ -1,13 +1,78 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
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");
4
11
  const cli_1 = require("@graphql-codegen/cli");
12
+ const rimraf_1 = __importDefault(require("rimraf"));
13
+ const yaml_1 = __importDefault(require("yaml"));
5
14
  const [, , cmd] = process.argv;
6
- // console.log(process.argv)
7
- (0, cli_1.runCli)(cmd)
8
- .then((result) => {
15
+ const root = process.cwd();
16
+ const configLocation = node_path_1.default.join(root, `._tmp_codegen.yml`);
17
+ async function cleanup() {
18
+ try {
19
+ await promises_1.default.stat(configLocation).then((r) => {
20
+ if (r.isFile())
21
+ return promises_1.default.unlink(configLocation);
22
+ return undefined;
23
+ });
24
+ }
25
+ catch (e) {
26
+ // ignore
27
+ }
28
+ return undefined;
29
+ }
30
+ function appendDocumentLocations(conf, packages) {
31
+ const documents = Array.isArray(conf.documents) ? conf.documents : [conf.documents];
32
+ documents.push(...packages.map((p) => `${p}/**/*.graphql`));
33
+ return conf;
34
+ }
35
+ async function main() {
36
+ // Make sure we dont already have a --config or -c cli argument as we're going to override it.
37
+ if (process.argv.includes('--config') || process.argv.includes('-c')) {
38
+ throw Error('--config or -c argument is not supported, modify codegen.yml to make changes');
39
+ }
40
+ const packages = [...(0, next_config_1.resolveDependenciesSync)().values()].filter((p) => p !== '.');
41
+ // Detect if we're operating in the monorepo environment or in an installation
42
+ const isMono = !!packages.find((p) => p.startsWith('../..'));
43
+ // Load the current codegen.yml
44
+ // Todo: implement loading with a custom --config or -c here.
45
+ const conf = await (0, cli_1.loadCodegenConfig)({ configFilePath: root });
46
+ // Get a a list of all generates configurations.
47
+ const generates = Object.entries(conf.config.generates);
48
+ let extension;
49
+ // Find the file extension used for the generated graphql files and cleanup if not used anymore.
50
+ generates.forEach(([, gen]) => {
51
+ if (Array.isArray(gen))
52
+ return;
53
+ if (gen.presetConfig?.extension)
54
+ extension = gen.presetConfig.extension;
55
+ });
56
+ if (extension)
57
+ (0, rimraf_1.default)(node_path_1.default.join(root, `**/*${extension}`), console.error);
58
+ // - Prepend the all targets with ../../ if we're running in a monorepo setup.
59
+ // - Append all the Graphcommerce packages to the configuration
60
+ conf.config.generates = Object.fromEntries(generates.map(([generateTarget, generateConf]) => [
61
+ isMono ? `../../${generateTarget}` : generateTarget,
62
+ Array.isArray(generateConf) ? generateConf : appendDocumentLocations(generateConf, packages),
63
+ ]));
64
+ // Reexport the mesh to is can be used by codegen
65
+ await promises_1.default.writeFile(configLocation, yaml_1.default.stringify(conf.config));
66
+ // Append the new cli argument
67
+ process.argv.push('--config');
68
+ process.argv.push(configLocation);
69
+ // Run the cli
70
+ const result = await (0, cli_1.runCli)(cmd);
71
+ await cleanup();
9
72
  process.exit(result);
10
- })
11
- .catch((error) => {
12
- (0, cli_1.cliError)(error);
73
+ }
74
+ main().catch((e) => {
75
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
76
+ cleanup();
77
+ (0, cli_1.cliError)(e);
13
78
  });
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ process.exit(1);
@@ -0,0 +1,40 @@
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
+ */
16
+ 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);
39
+ process.exit(1);
40
+ });
package/dist/bin/mesh.js CHANGED
@@ -10,11 +10,12 @@ exports.handleFatalError = void 0;
10
10
  const node_fs_1 = require("node:fs");
11
11
  const node_path_1 = __importDefault(require("node:path"));
12
12
  const node_process_1 = require("node:process");
13
+ const next_config_1 = require("@graphcommerce/next-config");
13
14
  const cli_1 = require("@graphql-mesh/cli");
14
15
  const utils_1 = require("@graphql-mesh/utils");
15
16
  const dotenv_1 = __importDefault(require("dotenv"));
16
17
  const yaml_1 = __importDefault(require("yaml"));
17
- const findConfig_1 = require("../mesh/findConfig");
18
+ const findConfig_1 = require("../utils/findConfig");
18
19
  dotenv_1.default.config();
19
20
  function handleFatalError(e, logger = new utils_1.DefaultLogger('◈')) {
20
21
  logger.error(e.stack || e.message);
@@ -27,12 +28,11 @@ exports.handleFatalError = handleFatalError;
27
28
  const root = process.cwd();
28
29
  const meshDir = node_path_1.default.dirname(require.resolve('@graphcommerce/graphql-mesh'));
29
30
  const relativePath = node_path_1.default.join(node_path_1.default.relative(meshDir, root), '/');
30
- const isMonoRepo = relativePath.startsWith(`..${node_path_1.default.sep}..${node_path_1.default.sep}examples`);
31
31
  const cliParams = {
32
32
  ...cli_1.DEFAULT_CLI_PARAMS,
33
33
  playgroundTitle: 'GraphCommerce® Mesh',
34
34
  };
35
- const tmpMesh = `_tmp_mesh_${Math.random().toString(36).substring(2, 15)}`;
35
+ const tmpMesh = `_tmp_codegen`;
36
36
  const tmpMeshLocation = node_path_1.default.join(root, `.${tmpMesh}rc.yml`);
37
37
  async function cleanup() {
38
38
  try {
@@ -67,7 +67,7 @@ const main = async () => {
67
67
  });
68
68
  // Scan the current working directory to also read all graphqls files.
69
69
  conf.additionalTypeDefs.push('**/*.graphqls');
70
- if (isMonoRepo) {
70
+ if ((0, next_config_1.isMonorepo)()) {
71
71
  conf.additionalTypeDefs.push('../../packages/**/*.graphqls');
72
72
  conf.additionalTypeDefs.push('../../packagesDev/**/*.graphqls');
73
73
  }
@@ -86,4 +86,7 @@ const main = async () => {
86
86
  };
87
87
  process.on('SIGINT', cleanup);
88
88
  process.on('SIGTERM', cleanup);
89
- main().catch((e) => handleFatalError(e, new utils_1.DefaultLogger(cli_1.DEFAULT_CLI_PARAMS.initialLoggerPrefix)));
89
+ main().catch((e) => {
90
+ cleanup();
91
+ return handleFatalError(e, new utils_1.DefaultLogger(cli_1.DEFAULT_CLI_PARAMS.initialLoggerPrefix));
92
+ });
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/cli",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "1.0.10",
5
+ "version": "4.30.0-canary.1",
6
6
  "author": "",
7
7
  "license": "MIT",
8
8
  "scripts": {
@@ -10,25 +10,33 @@
10
10
  "build": "tsc --outDir dist",
11
11
  "prepack": "yarn build"
12
12
  },
13
+ "main": "dist/index.js",
13
14
  "bin": {
14
15
  "mesh": "dist/bin/mesh.js",
15
16
  "gql-mesh": "dist/bin/mesh.js",
16
17
  "graphql-mesh": "dist/bin/mesh.js",
17
18
  "gql-gen": "dist/bin/codegen.js",
18
19
  "graphql-codegen": "dist/bin/codegen.js",
19
- "graphql-code-generator": "dist/bin/codegen.js"
20
+ "graphql-code-generator": "dist/bin/codegen.js",
21
+ "is-monorepo": "dist/bin/is-monorepo.js",
22
+ "graphcommerce": "dist/bin/graphcommerce.js"
20
23
  },
21
24
  "dependencies": {
25
+ "@graphcommerce/next-config": "4.30.0-canary.1",
22
26
  "@graphql-codegen/cli": "2.11.8",
23
27
  "@graphql-mesh/cli": "0.76.2",
24
28
  "@graphql-mesh/types": "0.80.2",
25
- "@graphql-mesh/utils": "0.40.0"
29
+ "@graphql-mesh/utils": "0.40.0",
30
+ "cosmiconfig": "^7.0.1",
31
+ "detect-package-manager": "^2.0.1",
32
+ "rimraf": "^3.0.2"
26
33
  },
27
34
  "devDependencies": {
28
- "@graphcommerce/eslint-config-pwa": "^4.1.10",
29
- "@graphcommerce/prettier-config-pwa": "^4.0.6",
30
- "@graphcommerce/typescript-config-pwa": "^4.0.4",
35
+ "@graphcommerce/eslint-config-pwa": "^4.1.11-canary.0",
36
+ "@graphcommerce/prettier-config-pwa": "^4.0.7-canary.0",
37
+ "@graphcommerce/typescript-config-pwa": "^4.0.5-canary.0",
31
38
  "@playwright/test": "^1.21.1",
39
+ "@types/rimraf": "^3.0.2",
32
40
  "typescript": "4.7.4"
33
41
  },
34
42
  "sideEffects": false,
package/tsconfig.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "exclude": ["**/node_modules", "**/.*/"],
3
3
  "include": ["**/*.ts", "**/*.tsx"],
4
+ "files": [
5
+ "bin/codegen.ts",
6
+ "bin/mesh.ts",
7
+ "bin/graphcommerce.ts",
8
+ "bin/is-monorepo.ts",
9
+ "index.ts"
10
+ ],
4
11
  "extends": "@graphcommerce/typescript-config-pwa/node.json",
5
12
  "compilerOptions": {
6
13
  "noEmit": false,
File without changes