@constructive-io/cli 5.5.0 → 5.6.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.
@@ -1,13 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
- const graphql_codegen_1 = require("@constructive-io/graphql-codegen");
10
- const graphql_server_1 = require("@constructive-io/graphql-server");
3
+ const child_process_1 = require("child_process");
11
4
  const usage = `
12
5
  Constructive GraphQL Codegen:
13
6
 
@@ -15,117 +8,41 @@ Constructive GraphQL Codegen:
15
8
 
16
9
  Options:
17
10
  --help, -h Show this help message
18
- --config <path> Config file (json|yaml)
19
- --schema <path> Schema SDL file path
20
- --endpoint <url> GraphQL endpoint to fetch schema via introspection
21
- --headerHost <host> Optional Host header to send with endpoint requests
22
- --auth <token> Optional Authorization header value (e.g., "Bearer 123")
23
- --header "Name: Value" Optional HTTP header; repeat to add multiple headers
24
- --out <dir> Output root directory (default: graphql/codegen/dist)
25
- --format <gql|ts> Document format (default: gql)
26
- --convention <style> Filename convention (dashed|underscore|camelcase|camelUpper)
27
- --emitTypes <bool> Emit types (default: true)
28
- --emitOperations <bool> Emit operations (default: true)
29
- --emitSdk <bool> Emit sdk (default: true)
30
- --allowQuery <name> Only generate for this root field (repeatable)
31
- --excludeQuery <name> Exclude this root field (repeatable)
32
- --excludePattern <regex> Exclude fields matching regex (repeatable)
11
+ --config <path> Path to graphql-codegen config file
12
+ --endpoint <url> GraphQL endpoint URL
13
+ --auth <token> Authorization header value (e.g., "Bearer 123")
14
+ --out <dir> Output directory (default: graphql/codegen/dist)
15
+ --dry-run Preview without writing files
16
+ -v, --verbose Verbose output
33
17
  `;
34
- function parseBool(v, d) {
35
- if (v === undefined)
36
- return d;
37
- if (typeof v === 'boolean')
38
- return v;
39
- const s = String(v).toLowerCase();
40
- if (s === 'true')
41
- return true;
42
- if (s === 'false')
43
- return false;
44
- return d;
45
- }
46
- async function loadConfig(path) {
47
- const content = await fs_1.promises.readFile(path, 'utf8');
48
- if (/\.ya?ml$/i.test(path))
49
- return js_yaml_1.default.load(content);
50
- if (/\.json$/i.test(path))
51
- return JSON.parse(content);
52
- return {};
53
- }
54
18
  exports.default = async (argv, _prompter, _options) => {
55
19
  if (argv.help || argv.h) {
56
20
  console.log(usage);
57
21
  process.exit(0);
58
22
  }
59
23
  const cwd = argv.cwd || process.cwd();
24
+ const endpoint = argv.endpoint || '';
25
+ const outDir = argv.out || 'graphql/codegen/dist';
26
+ const auth = argv.auth || '';
60
27
  const configPath = argv.config || '';
61
- let fileOpts = {};
28
+ const dryRun = !!(argv['dry-run'] || argv.dryRun);
29
+ const verbose = !!(argv.verbose || argv.v);
30
+ const envBin = process.env.CONSTRUCTIVE_CODEGEN_BIN;
31
+ const bin = envBin || require.resolve('@constructive-io/graphql-codegen/bin/graphql-codegen.js');
32
+ const args = ['generate'];
62
33
  if (configPath)
63
- fileOpts = await loadConfig(configPath);
64
- const overrides = {};
65
- if (argv.schema)
66
- overrides.input = { ...(overrides.input || {}), schema: String(argv.schema) };
67
- if (argv.endpoint)
68
- overrides.input = { ...(overrides.input || {}), endpoint: String(argv.endpoint) };
69
- const headerHost = argv.headerHost ?? '';
70
- const auth = argv.auth ?? '';
71
- const headerArg = argv.header;
72
- const headerList = Array.isArray(headerArg) ? headerArg : headerArg ? [headerArg] : [];
73
- const headers = {};
34
+ args.push('-c', configPath);
35
+ if (endpoint)
36
+ args.push('-e', endpoint);
37
+ if (outDir)
38
+ args.push('-o', outDir);
74
39
  if (auth)
75
- headers['Authorization'] = auth;
76
- for (const h of headerList) {
77
- const idx = typeof h === 'string' ? h.indexOf(':') : -1;
78
- if (idx <= 0)
79
- continue;
80
- const name = h.slice(0, idx).trim();
81
- const value = h.slice(idx + 1).trim();
82
- if (!name)
83
- continue;
84
- headers[name] = value;
85
- }
86
- if (Object.keys(headers).length)
87
- overrides.input = { ...(overrides.input || {}), headers };
88
- if (argv.out)
89
- overrides.output = { ...(overrides.output || {}), root: String(argv.out) };
90
- if (argv.format)
91
- overrides.documents = { ...(overrides.documents || {}), format: String(argv.format) };
92
- if (argv.convention)
93
- overrides.documents = { ...(overrides.documents || {}), convention: String(argv.convention) };
94
- const allowQueryArg = argv.allowQuery;
95
- const excludeQueryArg = argv.excludeQuery;
96
- const excludePatternArg = argv.excludePattern;
97
- const allowQueries = Array.isArray(allowQueryArg) ? allowQueryArg : allowQueryArg ? [String(allowQueryArg)] : [];
98
- const excludeQueries = Array.isArray(excludeQueryArg) ? excludeQueryArg : excludeQueryArg ? [String(excludeQueryArg)] : [];
99
- const excludePatterns = Array.isArray(excludePatternArg) ? excludePatternArg : excludePatternArg ? [String(excludePatternArg)] : [];
100
- if (allowQueries.length || excludeQueries.length || excludePatterns.length) {
101
- overrides.documents = { ...(overrides.documents || {}), allowQueries, excludeQueries, excludePatterns };
102
- }
103
- const emitTypes = parseBool(argv.emitTypes, true);
104
- const emitOperations = parseBool(argv.emitOperations, true);
105
- const emitSdk = parseBool(argv.emitSdk, true);
106
- overrides.features = { emitTypes, emitOperations, emitSdk };
107
- const merged = (0, graphql_codegen_1.mergeGraphQLCodegenOptions)(graphql_codegen_1.defaultGraphQLCodegenOptions, fileOpts);
108
- const finalOptions = (0, graphql_codegen_1.mergeGraphQLCodegenOptions)(merged, overrides);
109
- if (finalOptions.input.endpoint && headerHost) {
110
- const opts = {};
111
- if (headerHost)
112
- opts.headerHost = headerHost;
113
- if (auth)
114
- opts.auth = auth;
115
- if (Object.keys(headers).length)
116
- opts.headers = headers;
117
- const sdl = await graphql_server_1.fetchEndpointSchemaSDL(String(finalOptions.input.endpoint), opts);
118
- const tmpSchemaPath = (0, path_1.join)(cwd, '.constructive-codegen-schema.graphql');
119
- await fs_1.promises.writeFile(tmpSchemaPath, sdl, 'utf8');
120
- finalOptions.input.schema = tmpSchemaPath;
121
- finalOptions.input.endpoint = '';
122
- }
123
- const hasSchema = !!finalOptions.input.schema && String(finalOptions.input.schema).trim() !== '';
124
- const hasEndpoint = !!finalOptions.input.endpoint && String(finalOptions.input.endpoint).trim() !== '';
125
- if (!hasSchema && !hasEndpoint) {
126
- console.error('Missing --schema or --endpoint or config.input');
127
- process.exit(1);
128
- }
129
- const result = await (0, graphql_codegen_1.runCodegen)(finalOptions, cwd);
130
- console.log(`Generated at ${(0, path_1.join)(result.root)}`);
40
+ args.push('-a', auth);
41
+ if (dryRun)
42
+ args.push('--dry-run');
43
+ if (verbose)
44
+ args.push('-v');
45
+ const res = (0, child_process_1.spawnSync)(process.execPath, [bin, ...args], { cwd, stdio: 'inherit' });
46
+ if ((res.status ?? 0) !== 0)
47
+ process.exit(res.status ?? 1);
131
48
  };
@@ -1,8 +1,4 @@
1
- import { promises as fs } from 'fs';
2
- import { join } from 'path';
3
- import yaml from 'js-yaml';
4
- import { runCodegen, defaultGraphQLCodegenOptions, mergeGraphQLCodegenOptions } from '@constructive-io/graphql-codegen';
5
- import { fetchEndpointSchemaSDL } from '@constructive-io/graphql-server';
1
+ import { spawnSync } from 'child_process';
6
2
  const usage = `
7
3
  Constructive GraphQL Codegen:
8
4
 
@@ -10,117 +6,41 @@ Constructive GraphQL Codegen:
10
6
 
11
7
  Options:
12
8
  --help, -h Show this help message
13
- --config <path> Config file (json|yaml)
14
- --schema <path> Schema SDL file path
15
- --endpoint <url> GraphQL endpoint to fetch schema via introspection
16
- --headerHost <host> Optional Host header to send with endpoint requests
17
- --auth <token> Optional Authorization header value (e.g., "Bearer 123")
18
- --header "Name: Value" Optional HTTP header; repeat to add multiple headers
19
- --out <dir> Output root directory (default: graphql/codegen/dist)
20
- --format <gql|ts> Document format (default: gql)
21
- --convention <style> Filename convention (dashed|underscore|camelcase|camelUpper)
22
- --emitTypes <bool> Emit types (default: true)
23
- --emitOperations <bool> Emit operations (default: true)
24
- --emitSdk <bool> Emit sdk (default: true)
25
- --allowQuery <name> Only generate for this root field (repeatable)
26
- --excludeQuery <name> Exclude this root field (repeatable)
27
- --excludePattern <regex> Exclude fields matching regex (repeatable)
9
+ --config <path> Path to graphql-codegen config file
10
+ --endpoint <url> GraphQL endpoint URL
11
+ --auth <token> Authorization header value (e.g., "Bearer 123")
12
+ --out <dir> Output directory (default: graphql/codegen/dist)
13
+ --dry-run Preview without writing files
14
+ -v, --verbose Verbose output
28
15
  `;
29
- function parseBool(v, d) {
30
- if (v === undefined)
31
- return d;
32
- if (typeof v === 'boolean')
33
- return v;
34
- const s = String(v).toLowerCase();
35
- if (s === 'true')
36
- return true;
37
- if (s === 'false')
38
- return false;
39
- return d;
40
- }
41
- async function loadConfig(path) {
42
- const content = await fs.readFile(path, 'utf8');
43
- if (/\.ya?ml$/i.test(path))
44
- return yaml.load(content);
45
- if (/\.json$/i.test(path))
46
- return JSON.parse(content);
47
- return {};
48
- }
49
16
  export default async (argv, _prompter, _options) => {
50
17
  if (argv.help || argv.h) {
51
18
  console.log(usage);
52
19
  process.exit(0);
53
20
  }
54
21
  const cwd = argv.cwd || process.cwd();
22
+ const endpoint = argv.endpoint || '';
23
+ const outDir = argv.out || 'graphql/codegen/dist';
24
+ const auth = argv.auth || '';
55
25
  const configPath = argv.config || '';
56
- let fileOpts = {};
26
+ const dryRun = !!(argv['dry-run'] || argv.dryRun);
27
+ const verbose = !!(argv.verbose || argv.v);
28
+ const envBin = process.env.CONSTRUCTIVE_CODEGEN_BIN;
29
+ const bin = envBin || require.resolve('@constructive-io/graphql-codegen/bin/graphql-codegen.js');
30
+ const args = ['generate'];
57
31
  if (configPath)
58
- fileOpts = await loadConfig(configPath);
59
- const overrides = {};
60
- if (argv.schema)
61
- overrides.input = { ...(overrides.input || {}), schema: String(argv.schema) };
62
- if (argv.endpoint)
63
- overrides.input = { ...(overrides.input || {}), endpoint: String(argv.endpoint) };
64
- const headerHost = argv.headerHost ?? '';
65
- const auth = argv.auth ?? '';
66
- const headerArg = argv.header;
67
- const headerList = Array.isArray(headerArg) ? headerArg : headerArg ? [headerArg] : [];
68
- const headers = {};
32
+ args.push('-c', configPath);
33
+ if (endpoint)
34
+ args.push('-e', endpoint);
35
+ if (outDir)
36
+ args.push('-o', outDir);
69
37
  if (auth)
70
- headers['Authorization'] = auth;
71
- for (const h of headerList) {
72
- const idx = typeof h === 'string' ? h.indexOf(':') : -1;
73
- if (idx <= 0)
74
- continue;
75
- const name = h.slice(0, idx).trim();
76
- const value = h.slice(idx + 1).trim();
77
- if (!name)
78
- continue;
79
- headers[name] = value;
80
- }
81
- if (Object.keys(headers).length)
82
- overrides.input = { ...(overrides.input || {}), headers };
83
- if (argv.out)
84
- overrides.output = { ...(overrides.output || {}), root: String(argv.out) };
85
- if (argv.format)
86
- overrides.documents = { ...(overrides.documents || {}), format: String(argv.format) };
87
- if (argv.convention)
88
- overrides.documents = { ...(overrides.documents || {}), convention: String(argv.convention) };
89
- const allowQueryArg = argv.allowQuery;
90
- const excludeQueryArg = argv.excludeQuery;
91
- const excludePatternArg = argv.excludePattern;
92
- const allowQueries = Array.isArray(allowQueryArg) ? allowQueryArg : allowQueryArg ? [String(allowQueryArg)] : [];
93
- const excludeQueries = Array.isArray(excludeQueryArg) ? excludeQueryArg : excludeQueryArg ? [String(excludeQueryArg)] : [];
94
- const excludePatterns = Array.isArray(excludePatternArg) ? excludePatternArg : excludePatternArg ? [String(excludePatternArg)] : [];
95
- if (allowQueries.length || excludeQueries.length || excludePatterns.length) {
96
- overrides.documents = { ...(overrides.documents || {}), allowQueries, excludeQueries, excludePatterns };
97
- }
98
- const emitTypes = parseBool(argv.emitTypes, true);
99
- const emitOperations = parseBool(argv.emitOperations, true);
100
- const emitSdk = parseBool(argv.emitSdk, true);
101
- overrides.features = { emitTypes, emitOperations, emitSdk };
102
- const merged = mergeGraphQLCodegenOptions(defaultGraphQLCodegenOptions, fileOpts);
103
- const finalOptions = mergeGraphQLCodegenOptions(merged, overrides);
104
- if (finalOptions.input.endpoint && headerHost) {
105
- const opts = {};
106
- if (headerHost)
107
- opts.headerHost = headerHost;
108
- if (auth)
109
- opts.auth = auth;
110
- if (Object.keys(headers).length)
111
- opts.headers = headers;
112
- const sdl = await fetchEndpointSchemaSDL(String(finalOptions.input.endpoint), opts);
113
- const tmpSchemaPath = join(cwd, '.constructive-codegen-schema.graphql');
114
- await fs.writeFile(tmpSchemaPath, sdl, 'utf8');
115
- finalOptions.input.schema = tmpSchemaPath;
116
- finalOptions.input.endpoint = '';
117
- }
118
- const hasSchema = !!finalOptions.input.schema && String(finalOptions.input.schema).trim() !== '';
119
- const hasEndpoint = !!finalOptions.input.endpoint && String(finalOptions.input.endpoint).trim() !== '';
120
- if (!hasSchema && !hasEndpoint) {
121
- console.error('Missing --schema or --endpoint or config.input');
122
- process.exit(1);
123
- }
124
- const result = await runCodegen(finalOptions, cwd);
125
- console.log(`Generated at ${join(result.root)}`);
38
+ args.push('-a', auth);
39
+ if (dryRun)
40
+ args.push('--dry-run');
41
+ if (verbose)
42
+ args.push('-v');
43
+ const res = spawnSync(process.execPath, [bin, ...args], { cwd, stdio: 'inherit' });
44
+ if ((res.status ?? 0) !== 0)
45
+ process.exit(res.status ?? 1);
126
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/cli",
3
- "version": "5.5.0",
3
+ "version": "5.6.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive CLI",
6
6
  "main": "index.js",
@@ -46,12 +46,12 @@
46
46
  "ts-node": "^10.9.2"
47
47
  },
48
48
  "dependencies": {
49
- "@constructive-io/graphql-codegen": "^2.18.0",
50
- "@constructive-io/graphql-env": "^2.8.15",
51
- "@constructive-io/graphql-explorer": "^2.12.0",
52
- "@constructive-io/graphql-server": "^2.13.0",
49
+ "@constructive-io/graphql-codegen": "^2.20.0",
50
+ "@constructive-io/graphql-env": "^2.8.16",
51
+ "@constructive-io/graphql-explorer": "^2.13.1",
52
+ "@constructive-io/graphql-server": "^2.14.1",
53
53
  "@inquirerer/utils": "^3.1.2",
54
- "@pgpmjs/core": "^4.8.0",
54
+ "@pgpmjs/core": "^4.9.1",
55
55
  "@pgpmjs/logger": "^1.3.7",
56
56
  "@pgpmjs/server-utils": "^2.8.14",
57
57
  "@pgpmjs/types": "^2.14.0",
@@ -61,7 +61,7 @@
61
61
  "minimist": "^1.2.8",
62
62
  "pg-cache": "^1.6.14",
63
63
  "pg-env": "^1.2.5",
64
- "pgpm": "^2.8.0",
64
+ "pgpm": "^2.9.1",
65
65
  "shelljs": "^0.10.0",
66
66
  "yanse": "^0.1.11"
67
67
  },
@@ -76,5 +76,5 @@
76
76
  "postgres",
77
77
  "graphile"
78
78
  ],
79
- "gitHead": "97528ad4eb2f60c16785ffb84af7b61c52cb5ad8"
79
+ "gitHead": "baa2f7598cde3baf3f05f161a11bafa12c66f6aa"
80
80
  }