@constructive-io/cli 5.10.8 → 5.11.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.
@@ -36,8 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const fs = __importStar(require("node:fs"));
37
37
  const path = __importStar(require("node:path"));
38
38
  const graphql_server_1 = require("@constructive-io/graphql-server");
39
- const generate_1 = require("@constructive-io/graphql-codegen/cli/commands/generate");
40
- const init_1 = require("@constructive-io/graphql-codegen/cli/commands/init");
39
+ const graphql_codegen_1 = require("@constructive-io/graphql-codegen");
41
40
  const graphql_env_1 = require("@constructive-io/graphql-env");
42
41
  const usage = `
43
42
  Constructive GraphQL Codegen:
@@ -50,10 +49,12 @@ Options:
50
49
  --target <name> Target name in config file
51
50
  --endpoint <url> GraphQL endpoint URL
52
51
  --auth <token> Authorization header value (e.g., "Bearer 123")
53
- --out <dir> Output directory (default: graphql/codegen/dist)
52
+ --out <dir> Output directory (default: codegen)
54
53
  --dry-run Preview without writing files
55
54
  -v, --verbose Verbose output
56
55
 
56
+ --orm Generate Prisma-like ORM client instead of React Query hooks
57
+
57
58
  --database <name> Database override for DB mode (defaults to PGDATABASE)
58
59
  --schemas <list> Comma-separated schemas (required for DB mode)
59
60
  `;
@@ -62,90 +63,105 @@ exports.default = async (argv, _prompter, _options) => {
62
63
  console.log(usage);
63
64
  process.exit(0);
64
65
  }
65
- const endpointArg = argv.endpoint || '';
66
- const outputArg = argv.out;
67
- const outDir = outputArg || 'codegen';
68
- const auth = argv.auth || '';
69
- const configPath = argv.config || '';
70
- const target = argv.target || '';
71
- const dryRun = !!(argv['dry-run'] || argv.dryRun);
72
- const verbose = !!(argv.verbose || argv.v);
73
- const resolvedConfigPath = configPath || (0, init_1.findConfigFile)() || '';
74
- const hasConfigFile = Boolean(resolvedConfigPath);
75
- const outputForGenerate = outputArg || !hasConfigFile ? outDir : undefined;
76
- const selectedDb = argv.database || undefined;
77
- const options = selectedDb
78
- ? (0, graphql_env_1.getEnvOptions)({ pg: { database: selectedDb } })
79
- : (0, graphql_env_1.getEnvOptions)();
66
+ const opts = parseArgs(argv);
67
+ const mode = determineMode(opts);
68
+ if (mode.type === 'none') {
69
+ console.error('Error: No source specified. Use --endpoint, --config, or --schemas for database mode.');
70
+ process.exit(1);
71
+ }
72
+ // Build schema from database if needed
73
+ const outDir = opts.output || 'codegen';
74
+ const schemaPath = mode.type === 'database'
75
+ ? await buildSchemaFromDatabase(mode.database, mode.schemas, outDir)
76
+ : undefined;
77
+ const commandOptions = {
78
+ config: opts.config,
79
+ target: opts.target,
80
+ endpoint: mode.type === 'endpoint' ? mode.endpoint : undefined,
81
+ schema: schemaPath,
82
+ output: opts.config ? opts.output : outDir,
83
+ authorization: opts.auth,
84
+ verbose: opts.verbose,
85
+ dryRun: opts.dryRun,
86
+ };
87
+ const result = opts.orm
88
+ ? await (0, graphql_codegen_1.generateOrmCommand)(commandOptions)
89
+ : await (0, graphql_codegen_1.generateCommand)(commandOptions);
90
+ printResult(result);
91
+ if (!result.success) {
92
+ process.exit(1);
93
+ }
94
+ };
95
+ function parseArgs(argv) {
80
96
  const schemasArg = argv.schemas || '';
81
- const runGenerate = async ({ endpoint, schema, }) => {
82
- const result = await (0, generate_1.generateCommand)({
83
- config: configPath || undefined,
84
- target: target || undefined,
85
- endpoint,
86
- schema,
87
- output: outputForGenerate,
88
- authorization: auth || undefined,
89
- verbose,
90
- dryRun,
91
- });
92
- const targetResults = result.targets ?? [];
93
- const hasNamedTargets = targetResults.length > 0 &&
94
- (targetResults.length > 1 || targetResults[0]?.name !== 'default');
95
- if (hasNamedTargets) {
96
- console.log(result.message);
97
- targetResults.forEach((target) => {
98
- const status = target.success ? '[ok]' : 'x';
99
- console.log(`\n${status} ${target.message}`);
100
- if (target.tables?.length) {
101
- console.log(' Tables:');
102
- target.tables.forEach((table) => console.log(` - ${table}`));
103
- }
104
- if (target.filesWritten?.length) {
105
- console.log(' Files written:');
106
- target.filesWritten.forEach((file) => console.log(` - ${file}`));
107
- }
108
- if (!target.success && target.errors?.length) {
109
- target.errors.forEach((error) => console.error(` - ${error}`));
110
- }
111
- });
112
- if (!result.success) {
113
- process.exit(1);
114
- }
115
- return;
116
- }
117
- if (!result.success) {
118
- console.error(result.message);
119
- if (result.errors?.length)
120
- result.errors.forEach((e) => console.error(' -', e));
121
- process.exit(1);
122
- }
123
- console.log(result.message);
124
- if (result.filesWritten?.length) {
125
- result.filesWritten.forEach((f) => console.log(f));
126
- }
97
+ return {
98
+ endpoint: argv.endpoint || undefined,
99
+ config: argv.config || (0, graphql_codegen_1.findConfigFile)() || undefined,
100
+ target: argv.target || undefined,
101
+ output: argv.out || undefined,
102
+ auth: argv.auth || undefined,
103
+ database: argv.database || undefined,
104
+ schemas: schemasArg
105
+ ? schemasArg.split(',').map((s) => s.trim()).filter(Boolean)
106
+ : undefined,
107
+ dryRun: !!(argv['dry-run'] || argv.dryRun),
108
+ verbose: !!(argv.verbose || argv.v),
109
+ orm: !!argv.orm,
127
110
  };
128
- if (endpointArg) {
129
- await runGenerate({ endpoint: endpointArg });
111
+ }
112
+ function determineMode(opts) {
113
+ if (opts.endpoint) {
114
+ return { type: 'endpoint', endpoint: opts.endpoint };
115
+ }
116
+ if (opts.schemas?.length) {
117
+ const database = opts.database || (0, graphql_env_1.getEnvOptions)().pg.database;
118
+ return { type: 'database', database, schemas: opts.schemas };
119
+ }
120
+ if (opts.config) {
121
+ return { type: 'config', configPath: opts.config };
122
+ }
123
+ return { type: 'none' };
124
+ }
125
+ function printTargetResult(target) {
126
+ const status = target.success ? '[ok]' : 'x';
127
+ console.log(`\n${status} ${target.message}`);
128
+ if (target.tables?.length) {
129
+ console.log(' Tables:');
130
+ target.tables.forEach((t) => console.log(` - ${t}`));
131
+ }
132
+ if (target.filesWritten?.length) {
133
+ console.log(' Files written:');
134
+ target.filesWritten.forEach((f) => console.log(` - ${f}`));
135
+ }
136
+ if (!target.success && target.errors?.length) {
137
+ target.errors.forEach((e) => console.error(` - ${e}`));
138
+ }
139
+ }
140
+ function printResult(result) {
141
+ const targets = result.targets ?? [];
142
+ const isMultiTarget = targets.length > 1 || (targets.length === 1 && targets[0]?.name !== 'default');
143
+ if (isMultiTarget) {
144
+ console.log(result.message);
145
+ targets.forEach(printTargetResult);
130
146
  return;
131
147
  }
132
- if (!schemasArg.trim()) {
133
- console.error('Error: --schemas is required when building from database. Provide a comma-separated list of schemas.');
134
- process.exit(1);
148
+ if (!result.success) {
149
+ console.error(result.message);
150
+ result.errors?.forEach((e) => console.error(' -', e));
151
+ }
152
+ else {
153
+ console.log(result.message);
154
+ result.filesWritten?.forEach((f) => console.log(f));
135
155
  }
136
- const schemas = schemasArg
137
- .split(',')
138
- .map((s) => s.trim())
139
- .filter(Boolean);
156
+ }
157
+ async function buildSchemaFromDatabase(database, schemas, outDir) {
140
158
  await fs.promises.mkdir(outDir, { recursive: true });
141
159
  const sdl = await (0, graphql_server_1.buildSchemaSDL)({
142
- database: options.pg.database,
160
+ database,
143
161
  schemas,
144
- graphile: {
145
- pgSettings: async () => ({ role: 'administrator' }),
146
- },
162
+ graphile: { pgSettings: async () => ({ role: 'administrator' }) },
147
163
  });
148
164
  const schemaPath = path.join(outDir, 'schema.graphql');
149
165
  await fs.promises.writeFile(schemaPath, sdl, 'utf-8');
150
- await runGenerate({ schema: schemaPath });
151
- };
166
+ return schemaPath;
167
+ }
@@ -1,9 +1,8 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
3
  import { buildSchemaSDL } from '@constructive-io/graphql-server';
4
- import { generateCommand, } from '@constructive-io/graphql-codegen/cli/commands/generate';
5
- import { findConfigFile } from '@constructive-io/graphql-codegen/cli/commands/init';
6
- import { getEnvOptions, } from '@constructive-io/graphql-env';
4
+ import { generateCommand, generateOrmCommand, findConfigFile, } from '@constructive-io/graphql-codegen';
5
+ import { getEnvOptions } from '@constructive-io/graphql-env';
7
6
  const usage = `
8
7
  Constructive GraphQL Codegen:
9
8
 
@@ -15,10 +14,12 @@ Options:
15
14
  --target <name> Target name in config file
16
15
  --endpoint <url> GraphQL endpoint URL
17
16
  --auth <token> Authorization header value (e.g., "Bearer 123")
18
- --out <dir> Output directory (default: graphql/codegen/dist)
17
+ --out <dir> Output directory (default: codegen)
19
18
  --dry-run Preview without writing files
20
19
  -v, --verbose Verbose output
21
20
 
21
+ --orm Generate Prisma-like ORM client instead of React Query hooks
22
+
22
23
  --database <name> Database override for DB mode (defaults to PGDATABASE)
23
24
  --schemas <list> Comma-separated schemas (required for DB mode)
24
25
  `;
@@ -27,90 +28,105 @@ export default async (argv, _prompter, _options) => {
27
28
  console.log(usage);
28
29
  process.exit(0);
29
30
  }
30
- const endpointArg = argv.endpoint || '';
31
- const outputArg = argv.out;
32
- const outDir = outputArg || 'codegen';
33
- const auth = argv.auth || '';
34
- const configPath = argv.config || '';
35
- const target = argv.target || '';
36
- const dryRun = !!(argv['dry-run'] || argv.dryRun);
37
- const verbose = !!(argv.verbose || argv.v);
38
- const resolvedConfigPath = configPath || findConfigFile() || '';
39
- const hasConfigFile = Boolean(resolvedConfigPath);
40
- const outputForGenerate = outputArg || !hasConfigFile ? outDir : undefined;
41
- const selectedDb = argv.database || undefined;
42
- const options = selectedDb
43
- ? getEnvOptions({ pg: { database: selectedDb } })
44
- : getEnvOptions();
31
+ const opts = parseArgs(argv);
32
+ const mode = determineMode(opts);
33
+ if (mode.type === 'none') {
34
+ console.error('Error: No source specified. Use --endpoint, --config, or --schemas for database mode.');
35
+ process.exit(1);
36
+ }
37
+ // Build schema from database if needed
38
+ const outDir = opts.output || 'codegen';
39
+ const schemaPath = mode.type === 'database'
40
+ ? await buildSchemaFromDatabase(mode.database, mode.schemas, outDir)
41
+ : undefined;
42
+ const commandOptions = {
43
+ config: opts.config,
44
+ target: opts.target,
45
+ endpoint: mode.type === 'endpoint' ? mode.endpoint : undefined,
46
+ schema: schemaPath,
47
+ output: opts.config ? opts.output : outDir,
48
+ authorization: opts.auth,
49
+ verbose: opts.verbose,
50
+ dryRun: opts.dryRun,
51
+ };
52
+ const result = opts.orm
53
+ ? await generateOrmCommand(commandOptions)
54
+ : await generateCommand(commandOptions);
55
+ printResult(result);
56
+ if (!result.success) {
57
+ process.exit(1);
58
+ }
59
+ };
60
+ function parseArgs(argv) {
45
61
  const schemasArg = argv.schemas || '';
46
- const runGenerate = async ({ endpoint, schema, }) => {
47
- const result = await generateCommand({
48
- config: configPath || undefined,
49
- target: target || undefined,
50
- endpoint,
51
- schema,
52
- output: outputForGenerate,
53
- authorization: auth || undefined,
54
- verbose,
55
- dryRun,
56
- });
57
- const targetResults = result.targets ?? [];
58
- const hasNamedTargets = targetResults.length > 0 &&
59
- (targetResults.length > 1 || targetResults[0]?.name !== 'default');
60
- if (hasNamedTargets) {
61
- console.log(result.message);
62
- targetResults.forEach((target) => {
63
- const status = target.success ? '[ok]' : 'x';
64
- console.log(`\n${status} ${target.message}`);
65
- if (target.tables?.length) {
66
- console.log(' Tables:');
67
- target.tables.forEach((table) => console.log(` - ${table}`));
68
- }
69
- if (target.filesWritten?.length) {
70
- console.log(' Files written:');
71
- target.filesWritten.forEach((file) => console.log(` - ${file}`));
72
- }
73
- if (!target.success && target.errors?.length) {
74
- target.errors.forEach((error) => console.error(` - ${error}`));
75
- }
76
- });
77
- if (!result.success) {
78
- process.exit(1);
79
- }
80
- return;
81
- }
82
- if (!result.success) {
83
- console.error(result.message);
84
- if (result.errors?.length)
85
- result.errors.forEach((e) => console.error(' -', e));
86
- process.exit(1);
87
- }
88
- console.log(result.message);
89
- if (result.filesWritten?.length) {
90
- result.filesWritten.forEach((f) => console.log(f));
91
- }
62
+ return {
63
+ endpoint: argv.endpoint || undefined,
64
+ config: argv.config || findConfigFile() || undefined,
65
+ target: argv.target || undefined,
66
+ output: argv.out || undefined,
67
+ auth: argv.auth || undefined,
68
+ database: argv.database || undefined,
69
+ schemas: schemasArg
70
+ ? schemasArg.split(',').map((s) => s.trim()).filter(Boolean)
71
+ : undefined,
72
+ dryRun: !!(argv['dry-run'] || argv.dryRun),
73
+ verbose: !!(argv.verbose || argv.v),
74
+ orm: !!argv.orm,
92
75
  };
93
- if (endpointArg) {
94
- await runGenerate({ endpoint: endpointArg });
76
+ }
77
+ function determineMode(opts) {
78
+ if (opts.endpoint) {
79
+ return { type: 'endpoint', endpoint: opts.endpoint };
80
+ }
81
+ if (opts.schemas?.length) {
82
+ const database = opts.database || getEnvOptions().pg.database;
83
+ return { type: 'database', database, schemas: opts.schemas };
84
+ }
85
+ if (opts.config) {
86
+ return { type: 'config', configPath: opts.config };
87
+ }
88
+ return { type: 'none' };
89
+ }
90
+ function printTargetResult(target) {
91
+ const status = target.success ? '[ok]' : 'x';
92
+ console.log(`\n${status} ${target.message}`);
93
+ if (target.tables?.length) {
94
+ console.log(' Tables:');
95
+ target.tables.forEach((t) => console.log(` - ${t}`));
96
+ }
97
+ if (target.filesWritten?.length) {
98
+ console.log(' Files written:');
99
+ target.filesWritten.forEach((f) => console.log(` - ${f}`));
100
+ }
101
+ if (!target.success && target.errors?.length) {
102
+ target.errors.forEach((e) => console.error(` - ${e}`));
103
+ }
104
+ }
105
+ function printResult(result) {
106
+ const targets = result.targets ?? [];
107
+ const isMultiTarget = targets.length > 1 || (targets.length === 1 && targets[0]?.name !== 'default');
108
+ if (isMultiTarget) {
109
+ console.log(result.message);
110
+ targets.forEach(printTargetResult);
95
111
  return;
96
112
  }
97
- if (!schemasArg.trim()) {
98
- console.error('Error: --schemas is required when building from database. Provide a comma-separated list of schemas.');
99
- process.exit(1);
113
+ if (!result.success) {
114
+ console.error(result.message);
115
+ result.errors?.forEach((e) => console.error(' -', e));
116
+ }
117
+ else {
118
+ console.log(result.message);
119
+ result.filesWritten?.forEach((f) => console.log(f));
100
120
  }
101
- const schemas = schemasArg
102
- .split(',')
103
- .map((s) => s.trim())
104
- .filter(Boolean);
121
+ }
122
+ async function buildSchemaFromDatabase(database, schemas, outDir) {
105
123
  await fs.promises.mkdir(outDir, { recursive: true });
106
124
  const sdl = await buildSchemaSDL({
107
- database: options.pg.database,
125
+ database,
108
126
  schemas,
109
- graphile: {
110
- pgSettings: async () => ({ role: 'administrator' }),
111
- },
127
+ graphile: { pgSettings: async () => ({ role: 'administrator' }) },
112
128
  });
113
129
  const schemaPath = path.join(outDir, 'schema.graphql');
114
130
  await fs.promises.writeFile(schemaPath, sdl, 'utf-8');
115
- await runGenerate({ schema: schemaPath });
116
- };
131
+ return schemaPath;
132
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/cli",
3
- "version": "5.10.8",
3
+ "version": "5.11.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive CLI",
6
6
  "main": "index.js",
@@ -45,11 +45,11 @@
45
45
  "ts-node": "^10.9.2"
46
46
  },
47
47
  "dependencies": {
48
- "@constructive-io/graphql-codegen": "^2.29.0",
49
- "@constructive-io/graphql-env": "^2.9.2",
50
- "@constructive-io/graphql-explorer": "^2.15.2",
51
- "@constructive-io/graphql-server": "^2.19.8",
52
- "@constructive-io/knative-job-service": "^0.9.8",
48
+ "@constructive-io/graphql-codegen": "^2.31.0",
49
+ "@constructive-io/graphql-env": "^2.9.3",
50
+ "@constructive-io/graphql-explorer": "^2.15.3",
51
+ "@constructive-io/graphql-server": "^2.19.10",
52
+ "@constructive-io/knative-job-service": "^0.9.10",
53
53
  "@inquirerer/utils": "^3.2.0",
54
54
  "@pgpmjs/core": "^4.17.0",
55
55
  "@pgpmjs/logger": "^1.5.0",
@@ -75,5 +75,5 @@
75
75
  "postgres",
76
76
  "graphile"
77
77
  ],
78
- "gitHead": "17c82525efb87a39529a02bf24c096bf75597fae"
78
+ "gitHead": "57fdad16730e5a09c033ac218c8674e7599db7da"
79
79
  }