@soda-gql/cli 0.7.0 → 0.8.2
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/dist/index.cjs +512 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -1
- package/dist/index.d.cts.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -26,16 +26,292 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
+
let neverthrow = require("neverthrow");
|
|
30
|
+
let node_fs_promises = require("node:fs/promises");
|
|
29
31
|
let node_path = require("node:path");
|
|
30
|
-
let
|
|
32
|
+
let __soda_gql_builder = require("@soda-gql/builder");
|
|
31
33
|
let __soda_gql_config = require("@soda-gql/config");
|
|
32
|
-
let
|
|
34
|
+
let __soda_gql_codegen = require("@soda-gql/codegen");
|
|
33
35
|
let zod = require("zod");
|
|
34
|
-
let node_fs_promises = require("node:fs/promises");
|
|
35
36
|
let fast_glob = require("fast-glob");
|
|
36
37
|
fast_glob = __toESM(fast_glob);
|
|
37
38
|
let node_fs = require("node:fs");
|
|
38
39
|
|
|
40
|
+
//#region packages/cli/src/errors.ts
|
|
41
|
+
/**
|
|
42
|
+
* Error constructor helpers for concise error creation.
|
|
43
|
+
* Each function returns a specific error type for better type inference.
|
|
44
|
+
*/
|
|
45
|
+
const cliErrors = {
|
|
46
|
+
argsInvalid: (command, message) => ({
|
|
47
|
+
category: "cli",
|
|
48
|
+
code: "CLI_ARGS_INVALID",
|
|
49
|
+
message,
|
|
50
|
+
command
|
|
51
|
+
}),
|
|
52
|
+
unknownCommand: (command) => ({
|
|
53
|
+
category: "cli",
|
|
54
|
+
code: "CLI_UNKNOWN_COMMAND",
|
|
55
|
+
message: `Unknown command: ${command}`,
|
|
56
|
+
command
|
|
57
|
+
}),
|
|
58
|
+
unknownSubcommand: (parent, subcommand) => ({
|
|
59
|
+
category: "cli",
|
|
60
|
+
code: "CLI_UNKNOWN_SUBCOMMAND",
|
|
61
|
+
message: `Unknown subcommand: ${subcommand}`,
|
|
62
|
+
parent,
|
|
63
|
+
subcommand
|
|
64
|
+
}),
|
|
65
|
+
fileExists: (filePath, message) => ({
|
|
66
|
+
category: "cli",
|
|
67
|
+
code: "CLI_FILE_EXISTS",
|
|
68
|
+
message: message ?? `File already exists: ${filePath}. Use --force to overwrite.`,
|
|
69
|
+
filePath
|
|
70
|
+
}),
|
|
71
|
+
fileNotFound: (filePath, message) => ({
|
|
72
|
+
category: "cli",
|
|
73
|
+
code: "CLI_FILE_NOT_FOUND",
|
|
74
|
+
message: message ?? `File not found: ${filePath}`,
|
|
75
|
+
filePath
|
|
76
|
+
}),
|
|
77
|
+
writeFailed: (filePath, message, cause) => ({
|
|
78
|
+
category: "cli",
|
|
79
|
+
code: "CLI_WRITE_FAILED",
|
|
80
|
+
message: message ?? `Failed to write file: ${filePath}`,
|
|
81
|
+
filePath,
|
|
82
|
+
cause
|
|
83
|
+
}),
|
|
84
|
+
readFailed: (filePath, message, cause) => ({
|
|
85
|
+
category: "cli",
|
|
86
|
+
code: "CLI_READ_FAILED",
|
|
87
|
+
message: message ?? `Failed to read file: ${filePath}`,
|
|
88
|
+
filePath,
|
|
89
|
+
cause
|
|
90
|
+
}),
|
|
91
|
+
noPatterns: (message) => ({
|
|
92
|
+
category: "cli",
|
|
93
|
+
code: "CLI_NO_PATTERNS",
|
|
94
|
+
message: message ?? "No patterns provided and config not found. Usage: soda-gql format [patterns...] [--check]"
|
|
95
|
+
}),
|
|
96
|
+
formatterNotInstalled: (message) => ({
|
|
97
|
+
category: "cli",
|
|
98
|
+
code: "CLI_FORMATTER_NOT_INSTALLED",
|
|
99
|
+
message: message ?? "@soda-gql/formatter is not installed. Run: bun add @soda-gql/formatter"
|
|
100
|
+
}),
|
|
101
|
+
parseError: (message, filePath) => ({
|
|
102
|
+
category: "cli",
|
|
103
|
+
code: "CLI_PARSE_ERROR",
|
|
104
|
+
message,
|
|
105
|
+
filePath
|
|
106
|
+
}),
|
|
107
|
+
formatError: (message, filePath) => ({
|
|
108
|
+
category: "cli",
|
|
109
|
+
code: "CLI_FORMAT_ERROR",
|
|
110
|
+
message,
|
|
111
|
+
filePath
|
|
112
|
+
}),
|
|
113
|
+
unexpected: (message, cause) => ({
|
|
114
|
+
category: "cli",
|
|
115
|
+
code: "CLI_UNEXPECTED",
|
|
116
|
+
message,
|
|
117
|
+
cause
|
|
118
|
+
}),
|
|
119
|
+
fromCodegen: (error) => ({
|
|
120
|
+
category: "codegen",
|
|
121
|
+
error
|
|
122
|
+
}),
|
|
123
|
+
fromBuilder: (error) => ({
|
|
124
|
+
category: "builder",
|
|
125
|
+
error
|
|
126
|
+
}),
|
|
127
|
+
fromArtifact: (error) => ({
|
|
128
|
+
category: "artifact",
|
|
129
|
+
error
|
|
130
|
+
}),
|
|
131
|
+
fromConfig: (error) => ({
|
|
132
|
+
category: "config",
|
|
133
|
+
error
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region packages/cli/src/commands/artifact/build.ts
|
|
139
|
+
const BUILD_HELP = `Usage: soda-gql artifact build [options]
|
|
140
|
+
|
|
141
|
+
Build and validate soda-gql artifacts.
|
|
142
|
+
|
|
143
|
+
Options:
|
|
144
|
+
--config <path> Path to soda-gql.config.ts
|
|
145
|
+
--output, -o Output file path (default: ./soda-gql-artifact.json)
|
|
146
|
+
--version, -v Custom version string for the artifact (default: package version)
|
|
147
|
+
--dry-run Validate only, don't write output
|
|
148
|
+
--help, -h Show this help message
|
|
149
|
+
|
|
150
|
+
Examples:
|
|
151
|
+
soda-gql artifact build
|
|
152
|
+
soda-gql artifact build --output ./dist/artifact.json
|
|
153
|
+
soda-gql artifact build --version "1.0.0"
|
|
154
|
+
soda-gql artifact build --dry-run
|
|
155
|
+
soda-gql artifact build --config ./soda-gql.config.ts
|
|
156
|
+
`;
|
|
157
|
+
const DEFAULT_OUTPUT_PATH = "./soda-gql-artifact.json";
|
|
158
|
+
/**
|
|
159
|
+
* Parse build command arguments.
|
|
160
|
+
*/
|
|
161
|
+
const parseBuildArgs = (argv) => {
|
|
162
|
+
const args = {
|
|
163
|
+
configPath: void 0,
|
|
164
|
+
outputPath: DEFAULT_OUTPUT_PATH,
|
|
165
|
+
version: void 0,
|
|
166
|
+
dryRun: false,
|
|
167
|
+
help: false
|
|
168
|
+
};
|
|
169
|
+
for (let i = 0; i < argv.length; i++) {
|
|
170
|
+
const arg = argv[i];
|
|
171
|
+
if (arg === "--config" || arg === "-c") args.configPath = argv[++i];
|
|
172
|
+
else if (arg === "--output" || arg === "-o") args.outputPath = argv[++i] ?? DEFAULT_OUTPUT_PATH;
|
|
173
|
+
else if (arg === "--version" || arg === "-v") args.version = argv[++i];
|
|
174
|
+
else if (arg === "--dry-run") args.dryRun = true;
|
|
175
|
+
else if (arg === "--help" || arg === "-h") args.help = true;
|
|
176
|
+
}
|
|
177
|
+
return args;
|
|
178
|
+
};
|
|
179
|
+
const formatSuccess$3 = (data) => {
|
|
180
|
+
const { artifact, outputPath, dryRun } = data;
|
|
181
|
+
const fragmentCount = Object.values(artifact.elements).filter((e) => e.type === "fragment").length;
|
|
182
|
+
const operationCount = Object.values(artifact.elements).filter((e) => e.type === "operation").length;
|
|
183
|
+
const lines = [];
|
|
184
|
+
if (dryRun) lines.push(`Validation passed: ${fragmentCount} fragments, ${operationCount} operations`);
|
|
185
|
+
else lines.push(`Build complete: ${fragmentCount} fragments, ${operationCount} operations`);
|
|
186
|
+
if (artifact.meta?.version) lines.push(` Version: ${artifact.meta.version}`);
|
|
187
|
+
if (outputPath && !dryRun) lines.push(`Artifact written to: ${outputPath}`);
|
|
188
|
+
return lines.join("\n");
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Build command - builds and validates soda-gql artifacts.
|
|
192
|
+
*/
|
|
193
|
+
const buildCommand = async (argv) => {
|
|
194
|
+
const args = parseBuildArgs(argv);
|
|
195
|
+
if (args.help) return (0, neverthrow.ok)({ message: BUILD_HELP });
|
|
196
|
+
const configResult = (0, __soda_gql_config.loadConfig)(args.configPath);
|
|
197
|
+
if (configResult.isErr()) return (0, neverthrow.err)(cliErrors.fromConfig(configResult.error));
|
|
198
|
+
const config = configResult.value;
|
|
199
|
+
const buildResult = await (0, __soda_gql_builder.createBuilderService)({ config }).buildAsync();
|
|
200
|
+
if (buildResult.isErr()) return (0, neverthrow.err)(cliErrors.fromBuilder(buildResult.error));
|
|
201
|
+
const artifact = buildResult.value;
|
|
202
|
+
const meta = args.version ? {
|
|
203
|
+
version: args.version,
|
|
204
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
205
|
+
} : void 0;
|
|
206
|
+
const artifactWithMeta = {
|
|
207
|
+
...meta ? { meta } : {},
|
|
208
|
+
...artifact
|
|
209
|
+
};
|
|
210
|
+
if (args.dryRun) {
|
|
211
|
+
const data$1 = {
|
|
212
|
+
artifact: artifactWithMeta,
|
|
213
|
+
dryRun: true
|
|
214
|
+
};
|
|
215
|
+
return (0, neverthrow.ok)({
|
|
216
|
+
message: formatSuccess$3(data$1),
|
|
217
|
+
data: data$1
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const outputPath = (0, node_path.resolve)(process.cwd(), args.outputPath);
|
|
221
|
+
const outputDir = (0, node_path.dirname)(outputPath);
|
|
222
|
+
try {
|
|
223
|
+
await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
|
|
224
|
+
await (0, node_fs_promises.writeFile)(outputPath, JSON.stringify(artifactWithMeta, null, 2));
|
|
225
|
+
} catch (error) {
|
|
226
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
+
return (0, neverthrow.err)(cliErrors.writeFailed(outputPath, `Failed to write artifact: ${message}`, error));
|
|
228
|
+
}
|
|
229
|
+
const data = {
|
|
230
|
+
artifact: artifactWithMeta,
|
|
231
|
+
outputPath,
|
|
232
|
+
dryRun: false
|
|
233
|
+
};
|
|
234
|
+
return (0, neverthrow.ok)({
|
|
235
|
+
message: formatSuccess$3(data),
|
|
236
|
+
data
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region packages/cli/src/commands/artifact/validate.ts
|
|
242
|
+
const VALIDATE_HELP = `Usage: soda-gql artifact validate [options] <path>
|
|
243
|
+
|
|
244
|
+
Validate a pre-built soda-gql artifact file.
|
|
245
|
+
|
|
246
|
+
Arguments:
|
|
247
|
+
<path> Path to artifact JSON file
|
|
248
|
+
|
|
249
|
+
Options:
|
|
250
|
+
--help, -h Show this help message
|
|
251
|
+
|
|
252
|
+
Examples:
|
|
253
|
+
soda-gql artifact validate ./soda-gql-artifact.json
|
|
254
|
+
soda-gql artifact validate ./dist/artifact.json
|
|
255
|
+
`;
|
|
256
|
+
/**
|
|
257
|
+
* Parse validate command arguments.
|
|
258
|
+
*/
|
|
259
|
+
const parseValidateArgs = (argv) => {
|
|
260
|
+
const args = {
|
|
261
|
+
artifactPath: void 0,
|
|
262
|
+
help: false
|
|
263
|
+
};
|
|
264
|
+
for (const arg of argv) if (arg === "--help" || arg === "-h") args.help = true;
|
|
265
|
+
else if (!arg.startsWith("-")) args.artifactPath = arg;
|
|
266
|
+
return args;
|
|
267
|
+
};
|
|
268
|
+
const formatSuccess$2 = (artifact) => {
|
|
269
|
+
const lines = [`Artifact valid: ${Object.values(artifact.elements).filter((e) => e.type === "fragment").length} fragments, ${Object.values(artifact.elements).filter((e) => e.type === "operation").length} operations`];
|
|
270
|
+
if (artifact.meta) {
|
|
271
|
+
lines.push(` Version: ${artifact.meta.version}`);
|
|
272
|
+
lines.push(` Created: ${artifact.meta.createdAt}`);
|
|
273
|
+
} else lines.push(` (No metadata - legacy artifact format)`);
|
|
274
|
+
return lines.join("\n");
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Validate command - validates a pre-built artifact file.
|
|
278
|
+
*/
|
|
279
|
+
const validateCommand = async (argv) => {
|
|
280
|
+
const args = parseValidateArgs(argv);
|
|
281
|
+
if (args.help) return (0, neverthrow.ok)({ message: VALIDATE_HELP });
|
|
282
|
+
if (!args.artifactPath) return (0, neverthrow.err)(cliErrors.argsInvalid("artifact validate", "Missing artifact path argument"));
|
|
283
|
+
const result = await (0, __soda_gql_builder.loadArtifact)((0, node_path.resolve)(process.cwd(), args.artifactPath));
|
|
284
|
+
if (result.isErr()) return (0, neverthrow.err)(cliErrors.fromArtifact(result.error));
|
|
285
|
+
return (0, neverthrow.ok)({
|
|
286
|
+
message: formatSuccess$2(result.value),
|
|
287
|
+
data: result.value
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region packages/cli/src/commands/artifact/index.ts
|
|
293
|
+
const ARTIFACT_HELP = `Usage: soda-gql artifact <subcommand> [options]
|
|
294
|
+
|
|
295
|
+
Manage soda-gql artifacts.
|
|
296
|
+
|
|
297
|
+
Subcommands:
|
|
298
|
+
build Build artifacts (validate definitions)
|
|
299
|
+
validate Validate a pre-built artifact file
|
|
300
|
+
|
|
301
|
+
Run 'soda-gql artifact <subcommand> --help' for more information.
|
|
302
|
+
`;
|
|
303
|
+
/**
|
|
304
|
+
* Dispatcher for artifact subcommands.
|
|
305
|
+
*/
|
|
306
|
+
const artifactCommand = async (argv) => {
|
|
307
|
+
const [subcommand, ...rest] = argv;
|
|
308
|
+
if (!subcommand || subcommand === "--help" || subcommand === "-h") return (0, neverthrow.ok)({ message: ARTIFACT_HELP });
|
|
309
|
+
if (subcommand === "build") return buildCommand(rest);
|
|
310
|
+
if (subcommand === "validate") return validateCommand(rest);
|
|
311
|
+
return (0, neverthrow.err)(cliErrors.unknownSubcommand("artifact", subcommand));
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
//#endregion
|
|
39
315
|
//#region packages/cli/src/schemas/args.ts
|
|
40
316
|
const CodegenArgsSchema = zod.z.object({
|
|
41
317
|
config: zod.z.string().optional(),
|
|
@@ -82,28 +358,16 @@ const parseArgs = (args, schema) => {
|
|
|
82
358
|
//#region packages/cli/src/commands/codegen.ts
|
|
83
359
|
const parseCodegenArgs = (argv) => {
|
|
84
360
|
const parsed = parseArgs([...argv], CodegenArgsSchema);
|
|
85
|
-
if (!parsed.isOk()) return (0, neverthrow.err)(
|
|
86
|
-
code: "EMIT_FAILED",
|
|
87
|
-
message: parsed.error,
|
|
88
|
-
outPath: ""
|
|
89
|
-
});
|
|
361
|
+
if (!parsed.isOk()) return (0, neverthrow.err)(cliErrors.argsInvalid("codegen", parsed.error));
|
|
90
362
|
const args = parsed.value;
|
|
91
363
|
if (args["emit-inject-template"]) return (0, neverthrow.ok)({
|
|
92
364
|
kind: "emitInjectTemplate",
|
|
93
365
|
outPath: args["emit-inject-template"]
|
|
94
366
|
});
|
|
95
367
|
const configResult = (0, __soda_gql_config.loadConfig)(args.config);
|
|
96
|
-
if (configResult.isErr()) return (0, neverthrow.err)(
|
|
97
|
-
code: "EMIT_FAILED",
|
|
98
|
-
message: `Failed to load config: ${configResult.error.message}`,
|
|
99
|
-
outPath: ""
|
|
100
|
-
});
|
|
368
|
+
if (configResult.isErr()) return (0, neverthrow.err)(cliErrors.fromConfig(configResult.error));
|
|
101
369
|
const config = configResult.value;
|
|
102
|
-
if (!config.schemas || Object.keys(config.schemas).length === 0) return (0, neverthrow.err)(
|
|
103
|
-
code: "EMIT_FAILED",
|
|
104
|
-
message: "schemas configuration is required in soda-gql.config.ts",
|
|
105
|
-
outPath: ""
|
|
106
|
-
});
|
|
370
|
+
if (!config.schemas || Object.keys(config.schemas).length === 0) return (0, neverthrow.err)(cliErrors.argsInvalid("codegen", "schemas configuration is required in soda-gql.config.ts"));
|
|
107
371
|
const schemas = {};
|
|
108
372
|
for (const [name, schemaConfig] of Object.entries(config.schemas)) schemas[name] = {
|
|
109
373
|
schema: schemaConfig.schema,
|
|
@@ -125,20 +389,6 @@ const formatSuccess$1 = (success) => {
|
|
|
125
389
|
const formatTemplateSuccess = (outPath) => {
|
|
126
390
|
return `Created inject template → ${outPath}`;
|
|
127
391
|
};
|
|
128
|
-
const errorHints = {
|
|
129
|
-
SCHEMA_NOT_FOUND: "Verify the schema path in soda-gql.config.ts",
|
|
130
|
-
SCHEMA_INVALID: "Check your GraphQL schema for syntax errors",
|
|
131
|
-
INJECT_MODULE_NOT_FOUND: "Run: soda-gql codegen --emit-inject-template <path>",
|
|
132
|
-
INJECT_MODULE_REQUIRED: "Add inject configuration to your schema in soda-gql.config.ts",
|
|
133
|
-
INJECT_TEMPLATE_EXISTS: "Delete the existing file to regenerate, or use a different path",
|
|
134
|
-
EMIT_FAILED: "Check write permissions and that the output directory exists"
|
|
135
|
-
};
|
|
136
|
-
const formatCodegenError = (error) => {
|
|
137
|
-
const message = "message" in error ? error.message : "Unknown error";
|
|
138
|
-
const hint = errorHints[error.code];
|
|
139
|
-
const hintLine = hint ? `\n Hint: ${hint}` : "";
|
|
140
|
-
return `${error.code}: ${message}${hintLine}`;
|
|
141
|
-
};
|
|
142
392
|
const CODEGEN_HELP = `Usage: soda-gql codegen [options]
|
|
143
393
|
|
|
144
394
|
Generate graphql-system runtime module from GraphQL schema.
|
|
@@ -153,58 +403,37 @@ Examples:
|
|
|
153
403
|
soda-gql codegen --emit-inject-template ./src/graphql/scalars.ts
|
|
154
404
|
`;
|
|
155
405
|
const codegenCommand = async (argv) => {
|
|
156
|
-
if (argv.includes("--help") || argv.includes("-h")) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
const command = parsed.value;
|
|
167
|
-
if (command.kind === "emitInjectTemplate") {
|
|
168
|
-
const outPath = (0, node_path.resolve)(command.outPath);
|
|
169
|
-
const result$1 = (0, __soda_gql_codegen.writeInjectTemplate)(outPath);
|
|
170
|
-
if (result$1.isErr()) {
|
|
171
|
-
process.stderr.write(`${formatCodegenError(result$1.error)}\n`);
|
|
172
|
-
return 1;
|
|
173
|
-
}
|
|
174
|
-
process.stdout.write(`${formatTemplateSuccess(outPath)}\n`);
|
|
175
|
-
return 0;
|
|
176
|
-
}
|
|
177
|
-
const resolvedSchemas = {};
|
|
178
|
-
for (const [name, schemaConfig] of Object.entries(command.schemas)) resolvedSchemas[name] = {
|
|
179
|
-
schema: (0, node_path.resolve)(schemaConfig.schema),
|
|
180
|
-
inject: {
|
|
181
|
-
scalars: (0, node_path.resolve)(schemaConfig.inject.scalars),
|
|
182
|
-
...schemaConfig.inject.adapter ? { adapter: (0, node_path.resolve)(schemaConfig.inject.adapter) } : {}
|
|
183
|
-
},
|
|
184
|
-
defaultInputDepth: schemaConfig.defaultInputDepth,
|
|
185
|
-
inputDepthOverrides: schemaConfig.inputDepthOverrides
|
|
186
|
-
};
|
|
187
|
-
const result = await (0, __soda_gql_codegen.runCodegen)({
|
|
188
|
-
schemas: resolvedSchemas,
|
|
189
|
-
outPath: (0, node_path.resolve)(command.outPath),
|
|
190
|
-
format: "human",
|
|
191
|
-
importExtension: command.importExtension
|
|
192
|
-
});
|
|
193
|
-
if (result.isErr()) {
|
|
194
|
-
process.stderr.write(`${formatCodegenError(result.error)}\n`);
|
|
195
|
-
return 1;
|
|
196
|
-
}
|
|
197
|
-
process.stdout.write(`${formatSuccess$1(result.value)}\n`);
|
|
198
|
-
return 0;
|
|
199
|
-
} catch (error) {
|
|
200
|
-
const unexpectedError = {
|
|
201
|
-
code: "EMIT_FAILED",
|
|
202
|
-
message: error instanceof Error ? error.message : String(error),
|
|
203
|
-
outPath: ""
|
|
204
|
-
};
|
|
205
|
-
process.stderr.write(`${formatCodegenError(unexpectedError)}\n`);
|
|
206
|
-
return 1;
|
|
406
|
+
if (argv.includes("--help") || argv.includes("-h")) return (0, neverthrow.ok)({ message: CODEGEN_HELP });
|
|
407
|
+
const parsed = parseCodegenArgs(argv);
|
|
408
|
+
if (parsed.isErr()) return (0, neverthrow.err)(parsed.error);
|
|
409
|
+
const command = parsed.value;
|
|
410
|
+
if (command.kind === "emitInjectTemplate") {
|
|
411
|
+
const outPath = (0, node_path.resolve)(command.outPath);
|
|
412
|
+
const result$1 = (0, __soda_gql_codegen.writeInjectTemplate)(outPath);
|
|
413
|
+
if (result$1.isErr()) return (0, neverthrow.err)(cliErrors.fromCodegen(result$1.error));
|
|
414
|
+
return (0, neverthrow.ok)({ message: formatTemplateSuccess(outPath) });
|
|
207
415
|
}
|
|
416
|
+
const resolvedSchemas = {};
|
|
417
|
+
for (const [name, schemaConfig] of Object.entries(command.schemas)) resolvedSchemas[name] = {
|
|
418
|
+
schema: (0, node_path.resolve)(schemaConfig.schema),
|
|
419
|
+
inject: {
|
|
420
|
+
scalars: (0, node_path.resolve)(schemaConfig.inject.scalars),
|
|
421
|
+
...schemaConfig.inject.adapter ? { adapter: (0, node_path.resolve)(schemaConfig.inject.adapter) } : {}
|
|
422
|
+
},
|
|
423
|
+
defaultInputDepth: schemaConfig.defaultInputDepth,
|
|
424
|
+
inputDepthOverrides: schemaConfig.inputDepthOverrides
|
|
425
|
+
};
|
|
426
|
+
const result = await (0, __soda_gql_codegen.runCodegen)({
|
|
427
|
+
schemas: resolvedSchemas,
|
|
428
|
+
outPath: (0, node_path.resolve)(command.outPath),
|
|
429
|
+
format: "human",
|
|
430
|
+
importExtension: command.importExtension
|
|
431
|
+
});
|
|
432
|
+
if (result.isErr()) return (0, neverthrow.err)(cliErrors.fromCodegen(result.error));
|
|
433
|
+
return (0, neverthrow.ok)({
|
|
434
|
+
message: formatSuccess$1(result.value),
|
|
435
|
+
data: result.value
|
|
436
|
+
});
|
|
208
437
|
};
|
|
209
438
|
|
|
210
439
|
//#endregion
|
|
@@ -216,22 +445,19 @@ const loadFormatter = async () => {
|
|
|
216
445
|
return null;
|
|
217
446
|
}
|
|
218
447
|
};
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
if (result.unformatted.length > 0) {
|
|
225
|
-
const files = result.unformatted.map((f) => ` ${f}`).join("\n");
|
|
226
|
-
return `${result.unformatted.length} file(s) need formatting:\n${files}`;
|
|
448
|
+
const formatResultMessage = (data) => {
|
|
449
|
+
if (data.mode === "check") {
|
|
450
|
+
if (data.unformatted.length > 0) {
|
|
451
|
+
const files = data.unformatted.map((f) => ` ${f}`).join("\n");
|
|
452
|
+
return `${data.unformatted.length} file(s) need formatting:\n${files}`;
|
|
227
453
|
}
|
|
228
|
-
return `All ${
|
|
454
|
+
return `All ${data.total} file(s) are properly formatted`;
|
|
229
455
|
}
|
|
230
456
|
const parts = [];
|
|
231
|
-
if (
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
234
|
-
return `${
|
|
457
|
+
if (data.modified > 0) parts.push(`${data.modified} formatted`);
|
|
458
|
+
if (data.unchanged > 0) parts.push(`${data.unchanged} unchanged`);
|
|
459
|
+
if (data.errors > 0) parts.push(`${data.errors} errors`);
|
|
460
|
+
return `${data.total} file(s) checked: ${parts.join(", ")}`;
|
|
235
461
|
};
|
|
236
462
|
const isGlobPattern = (pattern) => {
|
|
237
463
|
return /[*?[\]{}]/.test(pattern);
|
|
@@ -269,19 +495,9 @@ Examples:
|
|
|
269
495
|
soda-gql format --check # Check mode with config
|
|
270
496
|
`;
|
|
271
497
|
const formatCommand = async (argv) => {
|
|
272
|
-
if (argv.includes("--help") || argv.includes("-h")) {
|
|
273
|
-
process.stdout.write(FORMAT_HELP);
|
|
274
|
-
return 0;
|
|
275
|
-
}
|
|
498
|
+
if (argv.includes("--help") || argv.includes("-h")) return (0, neverthrow.ok)({ message: FORMAT_HELP });
|
|
276
499
|
const parsed = parseArgs([...argv], FormatArgsSchema);
|
|
277
|
-
if (!parsed.isOk())
|
|
278
|
-
const error = {
|
|
279
|
-
code: "PARSE_ERROR",
|
|
280
|
-
message: parsed.error
|
|
281
|
-
};
|
|
282
|
-
process.stderr.write(`${formatFormatError(error)}\n`);
|
|
283
|
-
return 1;
|
|
284
|
-
}
|
|
500
|
+
if (!parsed.isOk()) return (0, neverthrow.err)(cliErrors.argsInvalid("format", parsed.error));
|
|
285
501
|
const args = parsed.value;
|
|
286
502
|
const isCheckMode = args.check === true;
|
|
287
503
|
const explicitPatterns = args._ ?? [];
|
|
@@ -290,36 +506,27 @@ const formatCommand = async (argv) => {
|
|
|
290
506
|
if (explicitPatterns.length > 0) targetPatterns = explicitPatterns;
|
|
291
507
|
else {
|
|
292
508
|
const configResult = (0, __soda_gql_config.loadConfig)(args.config);
|
|
293
|
-
if (configResult.isErr())
|
|
294
|
-
process.stderr.write(`${formatFormatError({
|
|
295
|
-
code: "NO_PATTERNS",
|
|
296
|
-
message: "No patterns provided and config not found. Usage: soda-gql format [patterns...] [--check]"
|
|
297
|
-
})}\n`);
|
|
298
|
-
return 1;
|
|
299
|
-
}
|
|
509
|
+
if (configResult.isErr()) return (0, neverthrow.err)(cliErrors.noPatterns());
|
|
300
510
|
targetPatterns = configResult.value.include;
|
|
301
511
|
excludePatterns = configResult.value.exclude;
|
|
302
512
|
}
|
|
303
513
|
const formatter = await loadFormatter();
|
|
304
|
-
if (!formatter)
|
|
305
|
-
process.stderr.write(`${formatFormatError({
|
|
306
|
-
code: "FORMATTER_NOT_INSTALLED",
|
|
307
|
-
message: "@soda-gql/formatter is not installed. Run: npm install @soda-gql/formatter"
|
|
308
|
-
})}\n`);
|
|
309
|
-
return 1;
|
|
310
|
-
}
|
|
514
|
+
if (!formatter) return (0, neverthrow.err)(cliErrors.formatterNotInstalled());
|
|
311
515
|
const files = await expandGlobPatterns(targetPatterns, excludePatterns);
|
|
312
516
|
if (files.length === 0) {
|
|
313
|
-
const
|
|
517
|
+
const data$1 = {
|
|
314
518
|
mode: isCheckMode ? "check" : "format",
|
|
315
519
|
total: 0,
|
|
316
520
|
modified: 0,
|
|
317
521
|
unchanged: 0,
|
|
318
522
|
errors: 0,
|
|
319
|
-
unformatted: []
|
|
523
|
+
unformatted: [],
|
|
524
|
+
hasFormattingIssues: false
|
|
320
525
|
};
|
|
321
|
-
|
|
322
|
-
|
|
526
|
+
return (0, neverthrow.ok)({
|
|
527
|
+
message: formatResultMessage(data$1),
|
|
528
|
+
data: data$1
|
|
529
|
+
});
|
|
323
530
|
}
|
|
324
531
|
let modified = 0;
|
|
325
532
|
let unchanged = 0;
|
|
@@ -328,44 +535,46 @@ const formatCommand = async (argv) => {
|
|
|
328
535
|
for (const filePath of files) {
|
|
329
536
|
const sourceCode = await (0, node_fs_promises.readFile)(filePath, "utf-8");
|
|
330
537
|
if (isCheckMode) {
|
|
331
|
-
const result
|
|
538
|
+
const result = formatter.needsFormat({
|
|
332
539
|
sourceCode,
|
|
333
540
|
filePath
|
|
334
541
|
});
|
|
335
|
-
if (result
|
|
542
|
+
if (result.isErr()) {
|
|
336
543
|
errors++;
|
|
337
544
|
continue;
|
|
338
545
|
}
|
|
339
|
-
if (result
|
|
546
|
+
if (result.value) {
|
|
340
547
|
unformatted.push(filePath);
|
|
341
548
|
modified++;
|
|
342
549
|
} else unchanged++;
|
|
343
550
|
} else {
|
|
344
|
-
const result
|
|
551
|
+
const result = formatter.format({
|
|
345
552
|
sourceCode,
|
|
346
553
|
filePath
|
|
347
554
|
});
|
|
348
|
-
if (result
|
|
555
|
+
if (result.isErr()) {
|
|
349
556
|
errors++;
|
|
350
557
|
continue;
|
|
351
558
|
}
|
|
352
|
-
if (result
|
|
353
|
-
await (0, node_fs_promises.writeFile)(filePath, result
|
|
559
|
+
if (result.value.modified) {
|
|
560
|
+
await (0, node_fs_promises.writeFile)(filePath, result.value.sourceCode, "utf-8");
|
|
354
561
|
modified++;
|
|
355
562
|
} else unchanged++;
|
|
356
563
|
}
|
|
357
564
|
}
|
|
358
|
-
const
|
|
565
|
+
const data = {
|
|
359
566
|
mode: isCheckMode ? "check" : "format",
|
|
360
567
|
total: files.length,
|
|
361
568
|
modified,
|
|
362
569
|
unchanged,
|
|
363
570
|
errors,
|
|
364
|
-
unformatted
|
|
571
|
+
unformatted,
|
|
572
|
+
hasFormattingIssues: isCheckMode && unformatted.length > 0 || errors > 0
|
|
365
573
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
574
|
+
return (0, neverthrow.ok)({
|
|
575
|
+
message: formatResultMessage(data),
|
|
576
|
+
data
|
|
577
|
+
});
|
|
369
578
|
};
|
|
370
579
|
|
|
371
580
|
//#endregion
|
|
@@ -439,11 +648,7 @@ Generated files:
|
|
|
439
648
|
`;
|
|
440
649
|
const checkFilesExist = (files, force) => {
|
|
441
650
|
if (force) return (0, neverthrow.ok)(void 0);
|
|
442
|
-
for (const file of files) if ((0, node_fs.existsSync)(file.path)) return (0, neverthrow.err)(
|
|
443
|
-
code: "FILE_EXISTS",
|
|
444
|
-
message: `File already exists: ${file.path}. Use --force to overwrite.`,
|
|
445
|
-
filePath: file.path
|
|
446
|
-
});
|
|
651
|
+
for (const file of files) if ((0, node_fs.existsSync)(file.path)) return (0, neverthrow.err)(cliErrors.fileExists(file.path));
|
|
447
652
|
return (0, neverthrow.ok)(void 0);
|
|
448
653
|
};
|
|
449
654
|
const writeFiles = (files) => {
|
|
@@ -454,11 +659,7 @@ const writeFiles = (files) => {
|
|
|
454
659
|
createdPaths.push(file.path);
|
|
455
660
|
} catch (error) {
|
|
456
661
|
const message = error instanceof Error ? error.message : String(error);
|
|
457
|
-
return (0, neverthrow.err)({
|
|
458
|
-
code: "WRITE_FAILED",
|
|
459
|
-
message: `Failed to write ${file.description}: ${message}`,
|
|
460
|
-
filePath: file.path
|
|
461
|
-
});
|
|
662
|
+
return (0, neverthrow.err)(cliErrors.writeFailed(file.path, `Failed to write ${file.description}: ${message}`, error));
|
|
462
663
|
}
|
|
463
664
|
return (0, neverthrow.ok)({ filesCreated: createdPaths });
|
|
464
665
|
};
|
|
@@ -475,23 +676,10 @@ const formatSuccess = (result) => {
|
|
|
475
676
|
lines.push(" 3. Import gql from ./graphql-system");
|
|
476
677
|
return lines.join("\n");
|
|
477
678
|
};
|
|
478
|
-
const formatInitError = (error) => {
|
|
479
|
-
return `${error.code}: ${error.message}`;
|
|
480
|
-
};
|
|
481
679
|
const initCommand = async (argv) => {
|
|
482
|
-
if (argv.includes("--help") || argv.includes("-h")) {
|
|
483
|
-
process.stdout.write(INIT_HELP);
|
|
484
|
-
return 0;
|
|
485
|
-
}
|
|
680
|
+
if (argv.includes("--help") || argv.includes("-h")) return (0, neverthrow.ok)({ message: INIT_HELP });
|
|
486
681
|
const parsed = parseArgs([...argv], InitArgsSchema);
|
|
487
|
-
if (!parsed.isOk())
|
|
488
|
-
const error = {
|
|
489
|
-
code: "PARSE_ERROR",
|
|
490
|
-
message: parsed.error
|
|
491
|
-
};
|
|
492
|
-
process.stderr.write(`${formatInitError(error)}\n`);
|
|
493
|
-
return 1;
|
|
494
|
-
}
|
|
682
|
+
if (!parsed.isOk()) return (0, neverthrow.err)(cliErrors.argsInvalid("init", parsed.error));
|
|
495
683
|
const force = parsed.value.force === true;
|
|
496
684
|
const cwd = process.cwd();
|
|
497
685
|
const files = [
|
|
@@ -517,52 +705,180 @@ const initCommand = async (argv) => {
|
|
|
517
705
|
}
|
|
518
706
|
];
|
|
519
707
|
const existsCheck = checkFilesExist(files, force);
|
|
520
|
-
if (existsCheck.isErr())
|
|
521
|
-
process.stderr.write(`${formatInitError(existsCheck.error)}\n`);
|
|
522
|
-
return 1;
|
|
523
|
-
}
|
|
708
|
+
if (existsCheck.isErr()) return (0, neverthrow.err)(existsCheck.error);
|
|
524
709
|
const writeResult = writeFiles(files);
|
|
525
|
-
if (writeResult.isErr())
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return 0;
|
|
710
|
+
if (writeResult.isErr()) return (0, neverthrow.err)(writeResult.error);
|
|
711
|
+
return (0, neverthrow.ok)({
|
|
712
|
+
message: formatSuccess(writeResult.value),
|
|
713
|
+
data: writeResult.value
|
|
714
|
+
});
|
|
531
715
|
};
|
|
532
716
|
|
|
533
717
|
//#endregion
|
|
534
718
|
//#region packages/cli/src/utils/format.ts
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
719
|
+
/**
|
|
720
|
+
* CLI-specific error hints to help users fix issues.
|
|
721
|
+
*/
|
|
722
|
+
const cliErrorHints = {
|
|
723
|
+
CLI_ARGS_INVALID: "Check command usage with --help",
|
|
724
|
+
CLI_UNKNOWN_COMMAND: "Run 'soda-gql --help' for available commands",
|
|
725
|
+
CLI_UNKNOWN_SUBCOMMAND: "Run the parent command with --help for available subcommands",
|
|
726
|
+
CLI_FILE_EXISTS: "Use --force flag to overwrite existing files",
|
|
727
|
+
CLI_FILE_NOT_FOUND: "Verify the file path exists",
|
|
728
|
+
CLI_WRITE_FAILED: "Check write permissions and disk space",
|
|
729
|
+
CLI_READ_FAILED: "Check file permissions and verify the file is not locked",
|
|
730
|
+
CLI_NO_PATTERNS: "Provide file patterns or create soda-gql.config.ts",
|
|
731
|
+
CLI_FORMATTER_NOT_INSTALLED: "Install with: bun add @soda-gql/formatter",
|
|
732
|
+
CLI_PARSE_ERROR: "Check the file for syntax errors",
|
|
733
|
+
CLI_FORMAT_ERROR: "Verify the file contains valid soda-gql code",
|
|
734
|
+
CLI_UNEXPECTED: "This is an unexpected error. Please report at https://github.com/soda-gql/soda-gql/issues"
|
|
735
|
+
};
|
|
736
|
+
/**
|
|
737
|
+
* Codegen-specific error hints.
|
|
738
|
+
*/
|
|
739
|
+
const codegenErrorHints = {
|
|
740
|
+
SCHEMA_NOT_FOUND: "Verify the schema path in soda-gql.config.ts",
|
|
741
|
+
SCHEMA_INVALID: "Check your GraphQL schema for syntax errors",
|
|
742
|
+
INJECT_MODULE_NOT_FOUND: "Run: soda-gql codegen --emit-inject-template <path>",
|
|
743
|
+
INJECT_MODULE_REQUIRED: "Add inject configuration to your schema in soda-gql.config.ts",
|
|
744
|
+
INJECT_TEMPLATE_EXISTS: "Delete the existing file to regenerate, or use a different path",
|
|
745
|
+
EMIT_FAILED: "Check write permissions and that the output directory exists",
|
|
746
|
+
INJECT_TEMPLATE_FAILED: "Check write permissions for the output path"
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Config-specific error hints.
|
|
750
|
+
*/
|
|
751
|
+
const configErrorHints = {
|
|
752
|
+
CONFIG_NOT_FOUND: "Create a soda-gql.config.ts file in your project root",
|
|
753
|
+
CONFIG_LOAD_FAILED: "Check your configuration file for syntax errors",
|
|
754
|
+
CONFIG_VALIDATION_FAILED: "Verify your configuration matches the expected schema",
|
|
755
|
+
CONFIG_INVALID_PATH: "Verify the path in your configuration exists"
|
|
756
|
+
};
|
|
757
|
+
/**
|
|
758
|
+
* Artifact-specific error hints.
|
|
759
|
+
*/
|
|
760
|
+
const artifactErrorHints = {
|
|
761
|
+
ARTIFACT_NOT_FOUND: "Verify the artifact file path exists",
|
|
762
|
+
ARTIFACT_PARSE_ERROR: "Check that the artifact file is valid JSON",
|
|
763
|
+
ARTIFACT_VALIDATION_ERROR: "Verify the artifact was built with a compatible version of soda-gql"
|
|
764
|
+
};
|
|
765
|
+
/**
|
|
766
|
+
* Get hint for any error type.
|
|
767
|
+
*/
|
|
768
|
+
const getErrorHint = (error) => {
|
|
769
|
+
if (error.category === "cli") return cliErrorHints[error.code];
|
|
770
|
+
if (error.category === "codegen") return codegenErrorHints[error.error.code];
|
|
771
|
+
if (error.category === "config") return configErrorHints[error.error.code];
|
|
772
|
+
if (error.category === "artifact") return artifactErrorHints[error.error.code];
|
|
773
|
+
};
|
|
774
|
+
/**
|
|
775
|
+
* Format CliError to human-readable string with hints.
|
|
776
|
+
*/
|
|
777
|
+
const formatCliErrorHuman = (error) => {
|
|
778
|
+
if (error.category === "builder") return (0, __soda_gql_builder.formatBuilderErrorForCLI)(error.error);
|
|
779
|
+
const lines = [];
|
|
780
|
+
if (error.category === "codegen") {
|
|
781
|
+
const codegenError = error.error;
|
|
782
|
+
lines.push(`Error [${codegenError.code}]: ${codegenError.message}`);
|
|
783
|
+
if ("schemaPath" in codegenError) lines.push(` Schema: ${codegenError.schemaPath}`);
|
|
784
|
+
if ("outPath" in codegenError && codegenError.outPath) lines.push(` Output: ${codegenError.outPath}`);
|
|
785
|
+
if ("injectPath" in codegenError) lines.push(` Inject: ${codegenError.injectPath}`);
|
|
786
|
+
} else if (error.category === "config") {
|
|
787
|
+
const configError = error.error;
|
|
788
|
+
lines.push(`Error [${configError.code}]: ${configError.message}`);
|
|
789
|
+
if (configError.filePath) lines.push(` Config: ${configError.filePath}`);
|
|
790
|
+
} else if (error.category === "artifact") {
|
|
791
|
+
const artifactError = error.error;
|
|
792
|
+
lines.push(`Error [${artifactError.code}]: ${artifactError.message}`);
|
|
793
|
+
if (artifactError.filePath) lines.push(` Artifact: ${artifactError.filePath}`);
|
|
794
|
+
} else {
|
|
795
|
+
lines.push(`Error [${error.code}]: ${error.message}`);
|
|
796
|
+
if ("filePath" in error && error.filePath) lines.push(` File: ${error.filePath}`);
|
|
797
|
+
if ("command" in error && error.code !== "CLI_UNKNOWN_COMMAND") lines.push(` Command: ${error.command}`);
|
|
798
|
+
if ("parent" in error) lines.push(` Parent: ${error.parent}`);
|
|
799
|
+
}
|
|
800
|
+
const hint = getErrorHint(error);
|
|
801
|
+
if (hint) {
|
|
802
|
+
lines.push("");
|
|
803
|
+
lines.push(` Hint: ${hint}`);
|
|
804
|
+
}
|
|
805
|
+
return lines.join("\n");
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Format CliError to JSON string.
|
|
809
|
+
*/
|
|
810
|
+
const formatCliErrorJson = (error) => {
|
|
811
|
+
if (error.category === "cli") {
|
|
812
|
+
const { category: _category, ...rest } = error;
|
|
813
|
+
return JSON.stringify({ error: rest }, null, 2);
|
|
814
|
+
}
|
|
815
|
+
return JSON.stringify({ error: error.error }, null, 2);
|
|
816
|
+
};
|
|
817
|
+
/**
|
|
818
|
+
* Format CliError with output format preference.
|
|
819
|
+
*/
|
|
820
|
+
const formatCliError = (error, format = "human") => {
|
|
821
|
+
return format === "json" ? formatCliErrorJson(error) : formatCliErrorHuman(error);
|
|
538
822
|
};
|
|
539
823
|
|
|
540
824
|
//#endregion
|
|
541
825
|
//#region packages/cli/src/index.ts
|
|
826
|
+
const MAIN_HELP = `Usage: soda-gql <command> [options]
|
|
827
|
+
|
|
828
|
+
Commands:
|
|
829
|
+
init Initialize a new soda-gql project
|
|
830
|
+
codegen Generate graphql-system runtime module
|
|
831
|
+
format Format soda-gql field selections
|
|
832
|
+
artifact Manage soda-gql artifacts
|
|
833
|
+
|
|
834
|
+
Run 'soda-gql <command> --help' for more information on a specific command.
|
|
835
|
+
`;
|
|
836
|
+
/**
|
|
837
|
+
* Parse output format from argv.
|
|
838
|
+
* Returns "json" if --format=json or --json flag is present, otherwise "human".
|
|
839
|
+
*/
|
|
840
|
+
const getOutputFormat = (argv) => {
|
|
841
|
+
for (const arg of argv) {
|
|
842
|
+
if (arg === "--format=json" || arg === "--json") return "json";
|
|
843
|
+
if (arg === "--format=human") return "human";
|
|
844
|
+
}
|
|
845
|
+
return "human";
|
|
846
|
+
};
|
|
542
847
|
const dispatch = async (argv) => {
|
|
543
848
|
const [command, ...rest] = argv;
|
|
544
|
-
if (!command || command === "--help" || command === "-h") {
|
|
545
|
-
process.stdout.write(`Usage: soda-gql <command> [options]\n`);
|
|
546
|
-
process.stdout.write(`\nCommands:\n`);
|
|
547
|
-
process.stdout.write(` init Initialize a new soda-gql project\n`);
|
|
548
|
-
process.stdout.write(` codegen Generate graphql-system runtime module\n`);
|
|
549
|
-
process.stdout.write(` format Format soda-gql field selections\n`);
|
|
550
|
-
return 0;
|
|
551
|
-
}
|
|
849
|
+
if (!command || command === "--help" || command === "-h") return (0, neverthrow.ok)({ message: MAIN_HELP });
|
|
552
850
|
if (command === "init") return initCommand(rest);
|
|
553
851
|
if (command === "codegen") return codegenCommand(rest);
|
|
554
|
-
if (command === "format")
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
|
|
852
|
+
if (command === "format") {
|
|
853
|
+
const result = await formatCommand(rest);
|
|
854
|
+
if (result.isOk()) {
|
|
855
|
+
const exitCode = result.value.data?.hasFormattingIssues ? 1 : 0;
|
|
856
|
+
return (0, neverthrow.ok)({
|
|
857
|
+
...result.value,
|
|
858
|
+
exitCode
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
return (0, neverthrow.err)(result.error);
|
|
862
|
+
}
|
|
863
|
+
if (command === "artifact") return artifactCommand(rest);
|
|
864
|
+
return (0, neverthrow.err)(cliErrors.unknownCommand(command));
|
|
865
|
+
};
|
|
866
|
+
const main = async () => {
|
|
867
|
+
const argv = process.argv.slice(2);
|
|
868
|
+
const format = getOutputFormat(argv);
|
|
869
|
+
const result = await dispatch(argv);
|
|
870
|
+
if (result.isOk()) {
|
|
871
|
+
process.stdout.write(`${result.value.message}\n`);
|
|
872
|
+
process.exitCode = result.value.exitCode ?? 0;
|
|
873
|
+
} else {
|
|
874
|
+
process.stderr.write(`${formatCliError(result.error, format)}\n`);
|
|
875
|
+
process.exitCode = 1;
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
main().catch((error) => {
|
|
879
|
+
const unexpectedError = cliErrors.unexpected(error instanceof Error ? error.message : String(error), error);
|
|
880
|
+
const format = getOutputFormat(process.argv.slice(2));
|
|
881
|
+
process.stderr.write(`${formatCliError(unexpectedError, format)}\n`);
|
|
566
882
|
process.exitCode = 1;
|
|
567
883
|
});
|
|
568
884
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["z","parsed: Record<string, unknown>","positional: string[]","schemas: Record<string, CodegenSchemaConfig>","formatSuccess","errorHints: Record<string, string>","result","resolvedSchemas: Record<string, CodegenSchemaConfig>","unexpectedError: CodegenError","parts: string[]","files: string[]","error: FormatError","targetPatterns: readonly string[]","excludePatterns: readonly string[]","result: FormatResult","result","unformatted: string[]","createdPaths: string[]","error: InitError","files: FileToGenerate[]"],"sources":["../src/schemas/args.ts","../src/utils/parse-args.ts","../src/commands/codegen.ts","../src/commands/format.ts","../src/templates/config.template.ts","../src/templates/gitignore.template.ts","../src/templates/inject.template.ts","../src/templates/schema.template.ts","../src/commands/init.ts","../src/utils/format.ts","../src/index.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const CodegenArgsSchema = z.object({\n config: z.string().optional(),\n \"emit-inject-template\": z.string().optional(),\n});\n\nexport const BuilderArgsSchema = z.object({\n mode: z.enum([\"runtime\", \"zero-runtime\"]),\n entry: z.string(),\n out: z.string(),\n format: z.enum([\"human\", \"json\"]).optional().default(\"human\"),\n});\n\nexport const FormatArgsSchema = z.object({\n _: z.array(z.string()).optional(),\n config: z.string().optional(),\n check: z.boolean().optional(),\n});\n\nexport const InitArgsSchema = z.object({\n force: z.boolean().optional(),\n});\n\nexport type CodegenArgs = z.infer<typeof CodegenArgsSchema>;\nexport type BuilderArgs = z.infer<typeof BuilderArgsSchema>;\nexport type FormatArgs = z.infer<typeof FormatArgsSchema>;\nexport type InitArgs = z.infer<typeof InitArgsSchema>;\n","import { err, ok, type Result } from \"neverthrow\";\nimport type { z } from \"zod\";\n\nexport const parseArgs = <T extends z.ZodType>(args: string[], schema: T): Result<z.infer<T>, string> => {\n const parsed: Record<string, unknown> = {};\n const positional: string[] = [];\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg) continue;\n\n if (arg.startsWith(\"--\")) {\n const key = arg.slice(2);\n const nextArg = args[i + 1];\n\n if (!nextArg || nextArg.startsWith(\"--\")) {\n parsed[key] = true;\n } else {\n parsed[key] = nextArg;\n i++;\n }\n } else {\n positional.push(arg);\n }\n }\n\n if (positional.length > 0) {\n parsed._ = positional;\n }\n\n const result = schema.safeParse(parsed);\n if (!result.success) {\n return err(result.error.issues.map((e) => e.message).join(\", \"));\n }\n\n return ok(result.data);\n};\n","import { resolve } from \"node:path\";\nimport type { CodegenError, CodegenSchemaConfig, CodegenSuccess } from \"@soda-gql/codegen\";\nimport { runCodegen, writeInjectTemplate } from \"@soda-gql/codegen\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport { CodegenArgsSchema } from \"../schemas/args\";\nimport { parseArgs } from \"../utils/parse-args\";\n\ntype ParsedCommand =\n | {\n kind: \"emitInjectTemplate\";\n outPath: string;\n }\n | {\n kind: \"generate\";\n schemas: Record<string, CodegenSchemaConfig>;\n outPath: string;\n importExtension: boolean;\n };\n\nconst parseCodegenArgs = (argv: readonly string[]): Result<ParsedCommand, CodegenError> => {\n const parsed = parseArgs([...argv], CodegenArgsSchema);\n\n if (!parsed.isOk()) {\n return err<ParsedCommand, CodegenError>({\n code: \"EMIT_FAILED\",\n message: parsed.error,\n outPath: \"\",\n });\n }\n\n const args = parsed.value;\n\n // Handle emit inject template\n if (args[\"emit-inject-template\"]) {\n return ok<ParsedCommand, CodegenError>({\n kind: \"emitInjectTemplate\",\n outPath: args[\"emit-inject-template\"],\n });\n }\n\n // Load config from @soda-gql/config\n const configResult = loadConfig(args.config);\n if (configResult.isErr()) {\n return err<ParsedCommand, CodegenError>({\n code: \"EMIT_FAILED\",\n message: `Failed to load config: ${configResult.error.message}`,\n outPath: \"\",\n });\n }\n\n const config = configResult.value;\n\n // Check if schemas config exists\n if (!config.schemas || Object.keys(config.schemas).length === 0) {\n return err<ParsedCommand, CodegenError>({\n code: \"EMIT_FAILED\",\n message: \"schemas configuration is required in soda-gql.config.ts\",\n outPath: \"\",\n });\n }\n\n // Build schemas config with resolved paths\n const schemas: Record<string, CodegenSchemaConfig> = {};\n\n for (const [name, schemaConfig] of Object.entries(config.schemas)) {\n schemas[name] = {\n schema: schemaConfig.schema,\n inject: schemaConfig.inject,\n defaultInputDepth: schemaConfig.defaultInputDepth,\n inputDepthOverrides: schemaConfig.inputDepthOverrides,\n };\n }\n\n // Derive output path from outdir (default to index.ts)\n const outPath = resolve(config.outdir, \"index.ts\");\n\n return ok<ParsedCommand, CodegenError>({\n kind: \"generate\",\n schemas,\n outPath,\n importExtension: config.styles.importExtension,\n });\n};\n\nconst formatSuccess = (success: CodegenSuccess): string => {\n const schemaNames = Object.keys(success.schemas).join(\", \");\n const totalObjects = Object.values(success.schemas).reduce((sum, s) => sum + s.objects, 0);\n return `Generated ${totalObjects} objects from schemas: ${schemaNames}\\n TypeScript: ${success.outPath}\\n CommonJS: ${success.cjsPath}`;\n};\n\nconst formatTemplateSuccess = (outPath: string): string => {\n return `Created inject template → ${outPath}`;\n};\n\nconst errorHints: Record<string, string> = {\n SCHEMA_NOT_FOUND: \"Verify the schema path in soda-gql.config.ts\",\n SCHEMA_INVALID: \"Check your GraphQL schema for syntax errors\",\n INJECT_MODULE_NOT_FOUND: \"Run: soda-gql codegen --emit-inject-template <path>\",\n INJECT_MODULE_REQUIRED: \"Add inject configuration to your schema in soda-gql.config.ts\",\n INJECT_TEMPLATE_EXISTS: \"Delete the existing file to regenerate, or use a different path\",\n EMIT_FAILED: \"Check write permissions and that the output directory exists\",\n};\n\nconst formatCodegenError = (error: CodegenError): string => {\n const message = \"message\" in error ? error.message : \"Unknown error\";\n const hint = errorHints[error.code];\n const hintLine = hint ? `\\n Hint: ${hint}` : \"\";\n return `${error.code}: ${message}${hintLine}`;\n};\n\nconst CODEGEN_HELP = `Usage: soda-gql codegen [options]\n\nGenerate graphql-system runtime module from GraphQL schema.\n\nOptions:\n --config <path> Path to soda-gql.config.ts\n --emit-inject-template <path> Create inject template file\n --help, -h Show this help message\n\nExamples:\n soda-gql codegen --config ./soda-gql.config.ts\n soda-gql codegen --emit-inject-template ./src/graphql/scalars.ts\n`;\n\nexport const codegenCommand = async (argv: readonly string[]): Promise<number> => {\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n process.stdout.write(CODEGEN_HELP);\n return 0;\n }\n\n try {\n const parsed = parseCodegenArgs(argv);\n\n if (parsed.isErr()) {\n process.stderr.write(`${formatCodegenError(parsed.error)}\\n`);\n return 1;\n }\n\n const command = parsed.value;\n\n if (command.kind === \"emitInjectTemplate\") {\n const outPath = resolve(command.outPath);\n const result = writeInjectTemplate(outPath);\n if (result.isErr()) {\n process.stderr.write(`${formatCodegenError(result.error)}\\n`);\n return 1;\n }\n process.stdout.write(`${formatTemplateSuccess(outPath)}\\n`);\n return 0;\n }\n\n // Resolve all paths in schemas config\n const resolvedSchemas: Record<string, CodegenSchemaConfig> = {};\n for (const [name, schemaConfig] of Object.entries(command.schemas)) {\n resolvedSchemas[name] = {\n schema: resolve(schemaConfig.schema),\n inject: {\n scalars: resolve(schemaConfig.inject.scalars),\n ...(schemaConfig.inject.adapter ? { adapter: resolve(schemaConfig.inject.adapter) } : {}),\n },\n defaultInputDepth: schemaConfig.defaultInputDepth,\n inputDepthOverrides: schemaConfig.inputDepthOverrides,\n };\n }\n\n const result = await runCodegen({\n schemas: resolvedSchemas,\n outPath: resolve(command.outPath),\n format: \"human\",\n importExtension: command.importExtension,\n });\n\n if (result.isErr()) {\n process.stderr.write(`${formatCodegenError(result.error)}\\n`);\n return 1;\n }\n\n process.stdout.write(`${formatSuccess(result.value)}\\n`);\n return 0;\n } catch (error) {\n // Catch unexpected errors and convert to structured format\n const unexpectedError: CodegenError = {\n code: \"EMIT_FAILED\",\n message: error instanceof Error ? error.message : String(error),\n outPath: \"\",\n };\n process.stderr.write(`${formatCodegenError(unexpectedError)}\\n`);\n return 1;\n }\n};\n","import { access, readFile, writeFile } from \"node:fs/promises\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport fg from \"fast-glob\";\nimport { FormatArgsSchema } from \"../schemas/args\";\nimport { parseArgs } from \"../utils/parse-args\";\n\ntype FormatterModule = typeof import(\"@soda-gql/formatter\");\n\nconst loadFormatter = async (): Promise<FormatterModule | null> => {\n try {\n return await import(\"@soda-gql/formatter\");\n } catch {\n return null;\n }\n};\n\ntype FormatError = {\n code: \"PARSE_ERROR\" | \"NO_PATTERNS\" | \"FORMAT_ERROR\" | \"FORMATTER_NOT_INSTALLED\";\n message: string;\n};\n\ntype FormatResult = {\n mode: \"format\" | \"check\";\n total: number;\n modified: number;\n unchanged: number;\n errors: number;\n unformatted: string[];\n};\n\nconst formatFormatError = (error: FormatError): string => {\n return `${error.code}: ${error.message}`;\n};\n\nconst formatResult = (result: FormatResult): string => {\n if (result.mode === \"check\") {\n if (result.unformatted.length > 0) {\n const files = result.unformatted.map((f) => ` ${f}`).join(\"\\n\");\n return `${result.unformatted.length} file(s) need formatting:\\n${files}`;\n }\n return `All ${result.total} file(s) are properly formatted`;\n }\n\n const parts: string[] = [];\n if (result.modified > 0) {\n parts.push(`${result.modified} formatted`);\n }\n if (result.unchanged > 0) {\n parts.push(`${result.unchanged} unchanged`);\n }\n if (result.errors > 0) {\n parts.push(`${result.errors} errors`);\n }\n return `${result.total} file(s) checked: ${parts.join(\", \")}`;\n};\n\nconst isGlobPattern = (pattern: string): boolean => {\n return /[*?[\\]{}]/.test(pattern);\n};\n\nconst expandGlobPatterns = async (patterns: readonly string[], excludePatterns: readonly string[] = []): Promise<string[]> => {\n const files: string[] = [];\n\n for (const pattern of patterns) {\n if (!isGlobPattern(pattern)) {\n // Direct file path - check if it exists\n try {\n await access(pattern);\n files.push(pattern);\n } catch {\n // File doesn't exist, skip it\n }\n continue;\n }\n\n // Glob pattern - use fast-glob with ignore\n const matches = await fg(pattern, {\n absolute: true,\n ignore: [...excludePatterns],\n });\n files.push(...matches);\n }\n\n return [...new Set(files)];\n};\n\nconst FORMAT_HELP = `Usage: soda-gql format [patterns...] [options]\n\nFormat soda-gql field selections by inserting empty comments.\n\nOptions:\n --config <path> Path to soda-gql.config.ts (auto-detected if omitted)\n --check Check if files need formatting (exit 1 if unformatted)\n --help, -h Show this help message\n\nExamples:\n soda-gql format # Use config include/exclude\n soda-gql format \"src/**/*.ts\" # Override with explicit patterns\n soda-gql format --check # Check mode with config\n`;\n\nexport const formatCommand = async (argv: readonly string[]): Promise<number> => {\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n process.stdout.write(FORMAT_HELP);\n return 0;\n }\n\n const parsed = parseArgs([...argv], FormatArgsSchema);\n\n if (!parsed.isOk()) {\n const error: FormatError = {\n code: \"PARSE_ERROR\",\n message: parsed.error,\n };\n process.stderr.write(`${formatFormatError(error)}\\n`);\n return 1;\n }\n\n const args = parsed.value;\n const isCheckMode = args.check === true;\n const explicitPatterns = args._ ?? [];\n\n // Determine patterns: use explicit patterns or load from config\n let targetPatterns: readonly string[];\n let excludePatterns: readonly string[] = [];\n\n if (explicitPatterns.length > 0) {\n targetPatterns = explicitPatterns;\n } else {\n // Try to load patterns from config\n const configResult = loadConfig(args.config);\n if (configResult.isErr()) {\n const error: FormatError = {\n code: \"NO_PATTERNS\",\n message: \"No patterns provided and config not found. Usage: soda-gql format [patterns...] [--check]\",\n };\n process.stderr.write(`${formatFormatError(error)}\\n`);\n return 1;\n }\n targetPatterns = configResult.value.include;\n excludePatterns = configResult.value.exclude;\n }\n\n // Load formatter lazily - it's an optional dependency\n const formatter = await loadFormatter();\n if (!formatter) {\n const error: FormatError = {\n code: \"FORMATTER_NOT_INSTALLED\",\n message: \"@soda-gql/formatter is not installed. Run: npm install @soda-gql/formatter\",\n };\n process.stderr.write(`${formatFormatError(error)}\\n`);\n return 1;\n }\n\n const files = await expandGlobPatterns(targetPatterns, excludePatterns);\n\n if (files.length === 0) {\n const result: FormatResult = {\n mode: isCheckMode ? \"check\" : \"format\",\n total: 0,\n modified: 0,\n unchanged: 0,\n errors: 0,\n unformatted: [],\n };\n process.stdout.write(`${formatResult(result)}\\n`);\n return 0;\n }\n\n let modified = 0;\n let unchanged = 0;\n let errors = 0;\n const unformatted: string[] = [];\n\n for (const filePath of files) {\n const sourceCode = await readFile(filePath, \"utf-8\");\n\n if (isCheckMode) {\n const result = formatter.needsFormat({ sourceCode, filePath });\n if (result.isErr()) {\n errors++;\n continue;\n }\n if (result.value) {\n unformatted.push(filePath);\n modified++;\n } else {\n unchanged++;\n }\n } else {\n const result = formatter.format({ sourceCode, filePath });\n if (result.isErr()) {\n errors++;\n continue;\n }\n if (result.value.modified) {\n await writeFile(filePath, result.value.sourceCode, \"utf-8\");\n modified++;\n } else {\n unchanged++;\n }\n }\n }\n\n const result: FormatResult = {\n mode: isCheckMode ? \"check\" : \"format\",\n total: files.length,\n modified,\n unchanged,\n errors,\n unformatted,\n };\n\n process.stdout.write(`${formatResult(result)}\\n`);\n\n if (isCheckMode && unformatted.length > 0) {\n return 1;\n }\n\n return errors > 0 ? 1 : 0;\n};\n","export const getConfigTemplate = (): string => `\\\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig({\n outdir: \"./graphql-system\",\n include: [\"./src/**/*.ts\"],\n schemas: {\n default: {\n schema: \"./schema.graphql\",\n inject: \"./graphql-system/default.inject.ts\",\n },\n },\n});\n`;\n","export const getGitignoreTemplate = (): string => `\\\n/index.ts\n/index.cjs\n`;\n","export const getInjectTemplate = (): string => `\\\nimport { defineAdapter, defineScalar } from \"@soda-gql/core/adapter\";\n\nexport const scalar = {\n ...defineScalar<\"ID\", string, string>(\"ID\"),\n ...defineScalar<\"String\", string, string>(\"String\"),\n ...defineScalar<\"Int\", number, number>(\"Int\"),\n ...defineScalar<\"Float\", number, number>(\"Float\"),\n ...defineScalar<\"Boolean\", boolean, boolean>(\"Boolean\"),\n} as const;\n\nexport const adapter = defineAdapter({\n helpers: {},\n metadata: {\n aggregateFragmentMetadata: (fragments) => fragments.map((m) => m.metadata),\n },\n});\n`;\n","export const getSchemaTemplate = (): string => `\\\ntype Query {\n hello: String!\n}\n`;\n","import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok, type Result } from \"neverthrow\";\n\nimport { InitArgsSchema } from \"../schemas/args\";\nimport { getConfigTemplate } from \"../templates/config.template\";\nimport { getGitignoreTemplate } from \"../templates/gitignore.template\";\nimport { getInjectTemplate } from \"../templates/inject.template\";\nimport { getSchemaTemplate } from \"../templates/schema.template\";\nimport { parseArgs } from \"../utils/parse-args\";\n\ntype InitErrorCode = \"FILE_EXISTS\" | \"WRITE_FAILED\" | \"PARSE_ERROR\";\n\ntype InitError = {\n readonly code: InitErrorCode;\n readonly message: string;\n readonly filePath?: string;\n};\n\ntype FileToGenerate = {\n readonly path: string;\n readonly content: string;\n readonly description: string;\n};\n\ntype InitSuccess = {\n readonly filesCreated: readonly string[];\n};\n\nconst INIT_HELP = `Usage: soda-gql init [options]\n\nInitialize a new soda-gql project with starter configuration.\n\nOptions:\n --force Overwrite existing files\n --help, -h Show this help message\n\nGenerated files:\n soda-gql.config.ts Configuration file\n schema.graphql Sample GraphQL schema\n graphql-system/default.inject.ts Scalars, helpers, and metadata adapter\n graphql-system/.gitignore Ignore generated files\n`;\n\nconst checkFilesExist = (files: readonly FileToGenerate[], force: boolean): Result<void, InitError> => {\n if (force) {\n return ok(undefined);\n }\n\n for (const file of files) {\n if (existsSync(file.path)) {\n return err({\n code: \"FILE_EXISTS\",\n message: `File already exists: ${file.path}. Use --force to overwrite.`,\n filePath: file.path,\n });\n }\n }\n\n return ok(undefined);\n};\n\nconst writeFiles = (files: readonly FileToGenerate[]): Result<InitSuccess, InitError> => {\n const createdPaths: string[] = [];\n\n for (const file of files) {\n try {\n const dir = dirname(file.path);\n mkdirSync(dir, { recursive: true });\n writeFileSync(file.path, file.content);\n createdPaths.push(file.path);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err({\n code: \"WRITE_FAILED\",\n message: `Failed to write ${file.description}: ${message}`,\n filePath: file.path,\n });\n }\n }\n\n return ok({ filesCreated: createdPaths });\n};\n\nconst formatSuccess = (result: InitSuccess): string => {\n const lines = [\"soda-gql project initialized successfully!\", \"\", \"Created files:\"];\n for (const file of result.filesCreated) {\n lines.push(` ${file}`);\n }\n lines.push(\"\", \"Next steps:\");\n lines.push(\" 1. Edit schema.graphql with your GraphQL types\");\n lines.push(\" 2. Run: soda-gql codegen\");\n lines.push(\" 3. Import gql from ./graphql-system\");\n return lines.join(\"\\n\");\n};\n\nconst formatInitError = (error: InitError): string => {\n return `${error.code}: ${error.message}`;\n};\n\nexport const initCommand = async (argv: readonly string[]): Promise<number> => {\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n process.stdout.write(INIT_HELP);\n return 0;\n }\n\n const parsed = parseArgs([...argv], InitArgsSchema);\n\n if (!parsed.isOk()) {\n const error: InitError = {\n code: \"PARSE_ERROR\",\n message: parsed.error,\n };\n process.stderr.write(`${formatInitError(error)}\\n`);\n return 1;\n }\n\n const args = parsed.value;\n const force = args.force === true;\n const cwd = process.cwd();\n\n const files: FileToGenerate[] = [\n {\n path: resolve(cwd, \"soda-gql.config.ts\"),\n content: getConfigTemplate(),\n description: \"configuration file\",\n },\n {\n path: resolve(cwd, \"schema.graphql\"),\n content: getSchemaTemplate(),\n description: \"GraphQL schema\",\n },\n {\n path: resolve(cwd, \"graphql-system/default.inject.ts\"),\n content: getInjectTemplate(),\n description: \"inject module\",\n },\n {\n path: resolve(cwd, \"graphql-system/.gitignore\"),\n content: getGitignoreTemplate(),\n description: \"gitignore file\",\n },\n ];\n\n const existsCheck = checkFilesExist(files, force);\n if (existsCheck.isErr()) {\n process.stderr.write(`${formatInitError(existsCheck.error)}\\n`);\n return 1;\n }\n\n const writeResult = writeFiles(files);\n if (writeResult.isErr()) {\n process.stderr.write(`${formatInitError(writeResult.error)}\\n`);\n return 1;\n }\n\n process.stdout.write(`${formatSuccess(writeResult.value)}\\n`);\n return 0;\n};\n","export const formatters = {\n json: (data: unknown) => JSON.stringify(data, null, 2),\n human: (data: unknown) => {\n if (typeof data === \"string\") return data;\n if (data instanceof Error) return data.message;\n return JSON.stringify(data, null, 2);\n },\n} as const;\n\nexport type OutputFormat = keyof typeof formatters;\n\nexport const formatOutput = (data: unknown, format: OutputFormat = \"human\"): string => {\n return formatters[format](data);\n};\n\nexport const formatError = (error: unknown, format: OutputFormat = \"human\"): string => {\n if (format === \"json\") {\n return JSON.stringify(\n {\n error: error,\n },\n null,\n 2,\n );\n }\n return error instanceof Error ? error.message : String(error);\n};\n","import { codegenCommand } from \"./commands/codegen\";\nimport { formatCommand } from \"./commands/format\";\nimport { initCommand } from \"./commands/init\";\nimport { formatError } from \"./utils/format\";\n\nconst dispatch = async (argv: readonly string[]): Promise<number> => {\n const [command, ...rest] = argv;\n\n if (!command || command === \"--help\" || command === \"-h\") {\n process.stdout.write(`Usage: soda-gql <command> [options]\\n`);\n process.stdout.write(`\\nCommands:\\n`);\n process.stdout.write(` init Initialize a new soda-gql project\\n`);\n process.stdout.write(` codegen Generate graphql-system runtime module\\n`);\n process.stdout.write(` format Format soda-gql field selections\\n`);\n return 0;\n }\n\n if (command === \"init\") {\n return initCommand(rest);\n }\n\n if (command === \"codegen\") {\n return codegenCommand(rest);\n }\n\n if (command === \"format\") {\n return formatCommand(rest);\n }\n\n process.stderr.write(`Unknown command: ${command}\\n`);\n return 1;\n};\n\n// Run CLI when executed directly\ndispatch(process.argv.slice(2))\n .then((exitCode) => {\n process.exitCode = exitCode;\n })\n .catch((error) => {\n const message = error instanceof Error ? error.message : String(error);\n const unexpectedError = {\n code: \"UNEXPECTED_ERROR\",\n message,\n };\n process.stderr.write(`${formatError(unexpectedError, \"json\")}\\n`);\n process.exitCode = 1;\n });\n\nexport { dispatch };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAa,oBAAoBA,MAAE,OAAO;CACxC,QAAQA,MAAE,QAAQ,CAAC,UAAU;CAC7B,wBAAwBA,MAAE,QAAQ,CAAC,UAAU;CAC9C,CAAC;AAEF,MAAa,oBAAoBA,MAAE,OAAO;CACxC,MAAMA,MAAE,KAAK,CAAC,WAAW,eAAe,CAAC;CACzC,OAAOA,MAAE,QAAQ;CACjB,KAAKA,MAAE,QAAQ;CACf,QAAQA,MAAE,KAAK,CAAC,SAAS,OAAO,CAAC,CAAC,UAAU,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;AACrD,QAAO;;AAIT,SAAS,QAAQ,KAAK,MAAM,EAAE,CAAC,CAC5B,MAAM,aAAa;AAClB,SAAQ,WAAW;EACnB,CACD,OAAO,UAAU;CAEhB,MAAM,kBAAkB;EACtB,MAAM;EACN,SAHc,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;EAIrE;AACD,SAAQ,OAAO,MAAM,GAAG,YAAY,iBAAiB,OAAO,CAAC,IAAI;AACjE,SAAQ,WAAW;EACnB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["args: BuildArgs","formatSuccess","lines: string[]","meta: BuilderArtifactMeta | undefined","artifactWithMeta: BuilderArtifact","data: BuildData","data","args: ValidateArgs","formatSuccess","lines: string[]","z","parsed: Record<string, unknown>","positional: string[]","schemas: Record<string, CodegenSchemaConfig>","formatSuccess","result","resolvedSchemas: Record<string, CodegenSchemaConfig>","parts: string[]","files: string[]","targetPatterns: readonly string[]","excludePatterns: readonly string[]","data: FormatData","data","unformatted: string[]","createdPaths: string[]","files: FileToGenerate[]","cliErrorHints: Partial<Record<CliErrorCode, string>>","codegenErrorHints: Record<string, string>","configErrorHints: Record<string, string>","artifactErrorHints: Record<string, string>","lines: string[]"],"sources":["../src/errors.ts","../src/commands/artifact/build.ts","../src/commands/artifact/validate.ts","../src/commands/artifact/index.ts","../src/schemas/args.ts","../src/utils/parse-args.ts","../src/commands/codegen.ts","../src/commands/format.ts","../src/templates/config.template.ts","../src/templates/gitignore.template.ts","../src/templates/inject.template.ts","../src/templates/schema.template.ts","../src/commands/init.ts","../src/utils/format.ts","../src/index.ts"],"sourcesContent":["/**\n * Unified CLI error types and constructors.\n * @module\n */\n\nimport type { ArtifactLoadError, BuilderError } from \"@soda-gql/builder\";\nimport type { CodegenError } from \"@soda-gql/codegen\";\nimport type { ConfigError } from \"@soda-gql/config\";\nimport { err, type Result } from \"neverthrow\";\n\n/**\n * CLI-specific error codes.\n */\nexport type CliErrorCode =\n // Argument parsing errors\n | \"CLI_ARGS_INVALID\"\n | \"CLI_UNKNOWN_COMMAND\"\n | \"CLI_UNKNOWN_SUBCOMMAND\"\n // File operation errors\n | \"CLI_FILE_EXISTS\"\n | \"CLI_FILE_NOT_FOUND\"\n | \"CLI_WRITE_FAILED\"\n | \"CLI_READ_FAILED\"\n // Format command specific\n | \"CLI_NO_PATTERNS\"\n | \"CLI_FORMATTER_NOT_INSTALLED\"\n | \"CLI_PARSE_ERROR\"\n | \"CLI_FORMAT_ERROR\"\n // Unexpected errors\n | \"CLI_UNEXPECTED\";\n\n/**\n * Unified CLI error discriminated union.\n * Wraps external errors (codegen, builder, config) and defines CLI-specific errors.\n */\nexport type CliError =\n // Wrapped external errors (preserve original structure)\n | { readonly category: \"codegen\"; readonly error: CodegenError }\n | { readonly category: \"builder\"; readonly error: BuilderError }\n | { readonly category: \"artifact\"; readonly error: ArtifactLoadError }\n | { readonly category: \"config\"; readonly error: ConfigError }\n // CLI-specific errors\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_ARGS_INVALID\";\n readonly message: string;\n readonly command: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_UNKNOWN_COMMAND\";\n readonly message: string;\n readonly command: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_UNKNOWN_SUBCOMMAND\";\n readonly message: string;\n readonly parent: string;\n readonly subcommand: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_FILE_EXISTS\";\n readonly message: string;\n readonly filePath: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_FILE_NOT_FOUND\";\n readonly message: string;\n readonly filePath: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_WRITE_FAILED\";\n readonly message: string;\n readonly filePath: string;\n readonly cause?: unknown;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_READ_FAILED\";\n readonly message: string;\n readonly filePath: string;\n readonly cause?: unknown;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_NO_PATTERNS\";\n readonly message: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_FORMATTER_NOT_INSTALLED\";\n readonly message: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_PARSE_ERROR\";\n readonly message: string;\n readonly filePath?: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_FORMAT_ERROR\";\n readonly message: string;\n readonly filePath?: string;\n }\n | {\n readonly category: \"cli\";\n readonly code: \"CLI_UNEXPECTED\";\n readonly message: string;\n readonly cause?: unknown;\n };\n\n/**\n * Result type for CLI operations.\n */\nexport type CliResult<T> = Result<T, CliError>;\n\n// Extract CLI-specific error types for type-safe constructors\ntype CliArgsInvalidError = Extract<CliError, { code: \"CLI_ARGS_INVALID\" }>;\ntype CliUnknownCommandError = Extract<CliError, { code: \"CLI_UNKNOWN_COMMAND\" }>;\ntype CliUnknownSubcommandError = Extract<CliError, { code: \"CLI_UNKNOWN_SUBCOMMAND\" }>;\ntype CliFileExistsError = Extract<CliError, { code: \"CLI_FILE_EXISTS\" }>;\ntype CliFileNotFoundError = Extract<CliError, { code: \"CLI_FILE_NOT_FOUND\" }>;\ntype CliWriteFailedError = Extract<CliError, { code: \"CLI_WRITE_FAILED\" }>;\ntype CliReadFailedError = Extract<CliError, { code: \"CLI_READ_FAILED\" }>;\ntype CliNoPatternsError = Extract<CliError, { code: \"CLI_NO_PATTERNS\" }>;\ntype CliFormatterNotInstalledError = Extract<CliError, { code: \"CLI_FORMATTER_NOT_INSTALLED\" }>;\ntype CliParseErrorError = Extract<CliError, { code: \"CLI_PARSE_ERROR\" }>;\ntype CliFormatErrorError = Extract<CliError, { code: \"CLI_FORMAT_ERROR\" }>;\ntype CliUnexpectedError = Extract<CliError, { code: \"CLI_UNEXPECTED\" }>;\ntype CliCodegenError = Extract<CliError, { category: \"codegen\" }>;\ntype CliBuilderError = Extract<CliError, { category: \"builder\" }>;\ntype CliArtifactError = Extract<CliError, { category: \"artifact\" }>;\ntype CliConfigError = Extract<CliError, { category: \"config\" }>;\n\n/**\n * Error constructor helpers for concise error creation.\n * Each function returns a specific error type for better type inference.\n */\nexport const cliErrors = {\n argsInvalid: (command: string, message: string): CliArgsInvalidError => ({\n category: \"cli\",\n code: \"CLI_ARGS_INVALID\",\n message,\n command,\n }),\n\n unknownCommand: (command: string): CliUnknownCommandError => ({\n category: \"cli\",\n code: \"CLI_UNKNOWN_COMMAND\",\n message: `Unknown command: ${command}`,\n command,\n }),\n\n unknownSubcommand: (parent: string, subcommand: string): CliUnknownSubcommandError => ({\n category: \"cli\",\n code: \"CLI_UNKNOWN_SUBCOMMAND\",\n message: `Unknown subcommand: ${subcommand}`,\n parent,\n subcommand,\n }),\n\n fileExists: (filePath: string, message?: string): CliFileExistsError => ({\n category: \"cli\",\n code: \"CLI_FILE_EXISTS\",\n message: message ?? `File already exists: ${filePath}. Use --force to overwrite.`,\n filePath,\n }),\n\n fileNotFound: (filePath: string, message?: string): CliFileNotFoundError => ({\n category: \"cli\",\n code: \"CLI_FILE_NOT_FOUND\",\n message: message ?? `File not found: ${filePath}`,\n filePath,\n }),\n\n writeFailed: (filePath: string, message?: string, cause?: unknown): CliWriteFailedError => ({\n category: \"cli\",\n code: \"CLI_WRITE_FAILED\",\n message: message ?? `Failed to write file: ${filePath}`,\n filePath,\n cause,\n }),\n\n readFailed: (filePath: string, message?: string, cause?: unknown): CliReadFailedError => ({\n category: \"cli\",\n code: \"CLI_READ_FAILED\",\n message: message ?? `Failed to read file: ${filePath}`,\n filePath,\n cause,\n }),\n\n noPatterns: (message?: string): CliNoPatternsError => ({\n category: \"cli\",\n code: \"CLI_NO_PATTERNS\",\n message: message ?? \"No patterns provided and config not found. Usage: soda-gql format [patterns...] [--check]\",\n }),\n\n formatterNotInstalled: (message?: string): CliFormatterNotInstalledError => ({\n category: \"cli\",\n code: \"CLI_FORMATTER_NOT_INSTALLED\",\n message: message ?? \"@soda-gql/formatter is not installed. Run: bun add @soda-gql/formatter\",\n }),\n\n parseError: (message: string, filePath?: string): CliParseErrorError => ({\n category: \"cli\",\n code: \"CLI_PARSE_ERROR\",\n message,\n filePath,\n }),\n\n formatError: (message: string, filePath?: string): CliFormatErrorError => ({\n category: \"cli\",\n code: \"CLI_FORMAT_ERROR\",\n message,\n filePath,\n }),\n\n unexpected: (message: string, cause?: unknown): CliUnexpectedError => ({\n category: \"cli\",\n code: \"CLI_UNEXPECTED\",\n message,\n cause,\n }),\n\n // Wrappers for external errors\n fromCodegen: (error: CodegenError): CliCodegenError => ({\n category: \"codegen\",\n error,\n }),\n\n fromBuilder: (error: BuilderError): CliBuilderError => ({\n category: \"builder\",\n error,\n }),\n\n fromArtifact: (error: ArtifactLoadError): CliArtifactError => ({\n category: \"artifact\",\n error,\n }),\n\n fromConfig: (error: ConfigError): CliConfigError => ({\n category: \"config\",\n error,\n }),\n} as const;\n\n/**\n * Convenience helper to create an err Result from CliError.\n */\nexport const cliErr = <T = never>(error: CliError): CliResult<T> => err(error);\n\n/**\n * Type guard to check if error is a CLI-specific error.\n */\nexport const isCliError = (error: CliError): error is CliError & { category: \"cli\" } => {\n return error.category === \"cli\";\n};\n\n/**\n * Extract error code from any CliError variant.\n */\nexport const getErrorCode = (error: CliError): string => {\n if (error.category === \"cli\") {\n return error.code;\n }\n // codegen, builder, artifact, config all have error.code\n return error.error.code;\n};\n\n/**\n * Extract error message from any CliError variant.\n */\nexport const getErrorMessage = (error: CliError): string => {\n if (error.category === \"cli\") {\n return error.message;\n }\n return error.error.message;\n};\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\nimport type { BuilderArtifact, BuilderArtifactMeta } from \"@soda-gql/builder\";\nimport { createBuilderService } from \"@soda-gql/builder\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport { err, ok } from \"neverthrow\";\nimport { cliErrors } from \"../../errors\";\nimport type { CommandResult, CommandSuccess } from \"../../types\";\n\nconst BUILD_HELP = `Usage: soda-gql artifact build [options]\n\nBuild and validate soda-gql artifacts.\n\nOptions:\n --config <path> Path to soda-gql.config.ts\n --output, -o Output file path (default: ./soda-gql-artifact.json)\n --version, -v Custom version string for the artifact (default: package version)\n --dry-run Validate only, don't write output\n --help, -h Show this help message\n\nExamples:\n soda-gql artifact build\n soda-gql artifact build --output ./dist/artifact.json\n soda-gql artifact build --version \"1.0.0\"\n soda-gql artifact build --dry-run\n soda-gql artifact build --config ./soda-gql.config.ts\n`;\n\ntype BuildArgs = {\n configPath?: string;\n outputPath: string;\n version?: string;\n dryRun: boolean;\n help: boolean;\n};\n\nconst DEFAULT_OUTPUT_PATH = \"./soda-gql-artifact.json\";\n\n/**\n * Parse build command arguments.\n */\nconst parseBuildArgs = (argv: readonly string[]): BuildArgs => {\n const args: BuildArgs = {\n configPath: undefined,\n outputPath: DEFAULT_OUTPUT_PATH,\n version: undefined,\n dryRun: false,\n help: false,\n };\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--config\" || arg === \"-c\") {\n args.configPath = argv[++i];\n } else if (arg === \"--output\" || arg === \"-o\") {\n args.outputPath = argv[++i] ?? DEFAULT_OUTPUT_PATH;\n } else if (arg === \"--version\" || arg === \"-v\") {\n args.version = argv[++i];\n } else if (arg === \"--dry-run\") {\n args.dryRun = true;\n } else if (arg === \"--help\" || arg === \"-h\") {\n args.help = true;\n }\n }\n\n return args;\n};\n\ntype BuildData = {\n artifact: BuilderArtifact;\n outputPath?: string;\n dryRun: boolean;\n};\n\nconst formatSuccess = (data: BuildData): string => {\n const { artifact, outputPath, dryRun } = data;\n const fragmentCount = Object.values(artifact.elements).filter((e) => e.type === \"fragment\").length;\n const operationCount = Object.values(artifact.elements).filter((e) => e.type === \"operation\").length;\n\n const lines: string[] = [];\n if (dryRun) {\n lines.push(`Validation passed: ${fragmentCount} fragments, ${operationCount} operations`);\n } else {\n lines.push(`Build complete: ${fragmentCount} fragments, ${operationCount} operations`);\n }\n\n if (artifact.meta?.version) {\n lines.push(` Version: ${artifact.meta.version}`);\n }\n\n if (outputPath && !dryRun) {\n lines.push(`Artifact written to: ${outputPath}`);\n }\n\n return lines.join(\"\\n\");\n};\n\ntype BuildCommandResult = CommandResult<CommandSuccess & { data?: BuildData }>;\n\n/**\n * Build command - builds and validates soda-gql artifacts.\n */\nexport const buildCommand = async (argv: readonly string[]): Promise<BuildCommandResult> => {\n const args = parseBuildArgs(argv);\n\n if (args.help) {\n return ok({ message: BUILD_HELP });\n }\n\n // Load config\n const configResult = loadConfig(args.configPath);\n if (configResult.isErr()) {\n return err(cliErrors.fromConfig(configResult.error));\n }\n\n const config = configResult.value;\n\n // Create builder service and build\n const service = createBuilderService({ config });\n const buildResult = await service.buildAsync();\n\n if (buildResult.isErr()) {\n return err(cliErrors.fromBuilder(buildResult.error));\n }\n\n const artifact = buildResult.value;\n\n // Create artifact with metadata (only if version is specified)\n const meta: BuilderArtifactMeta | undefined = args.version\n ? {\n version: args.version,\n createdAt: new Date().toISOString(),\n }\n : undefined;\n const artifactWithMeta: BuilderArtifact = {\n ...(meta ? { meta } : {}),\n ...artifact,\n };\n\n if (args.dryRun) {\n const data: BuildData = { artifact: artifactWithMeta, dryRun: true };\n return ok({ message: formatSuccess(data), data });\n }\n\n // Write artifact to output file\n const outputPath = resolve(process.cwd(), args.outputPath);\n const outputDir = dirname(outputPath);\n try {\n await mkdir(outputDir, { recursive: true });\n await writeFile(outputPath, JSON.stringify(artifactWithMeta, null, 2));\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err(cliErrors.writeFailed(outputPath, `Failed to write artifact: ${message}`, error));\n }\n\n const data: BuildData = { artifact: artifactWithMeta, outputPath, dryRun: false };\n return ok({ message: formatSuccess(data), data });\n};\n","import { resolve } from \"node:path\";\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { loadArtifact } from \"@soda-gql/builder\";\nimport { err, ok } from \"neverthrow\";\nimport { cliErrors } from \"../../errors\";\nimport type { CommandResult, CommandSuccess } from \"../../types\";\n\nconst VALIDATE_HELP = `Usage: soda-gql artifact validate [options] <path>\n\nValidate a pre-built soda-gql artifact file.\n\nArguments:\n <path> Path to artifact JSON file\n\nOptions:\n --help, -h Show this help message\n\nExamples:\n soda-gql artifact validate ./soda-gql-artifact.json\n soda-gql artifact validate ./dist/artifact.json\n`;\n\ntype ValidateArgs = {\n artifactPath?: string;\n help: boolean;\n};\n\n/**\n * Parse validate command arguments.\n */\nconst parseValidateArgs = (argv: readonly string[]): ValidateArgs => {\n const args: ValidateArgs = {\n artifactPath: undefined,\n help: false,\n };\n\n for (const arg of argv) {\n if (arg === \"--help\" || arg === \"-h\") {\n args.help = true;\n } else if (!arg.startsWith(\"-\")) {\n args.artifactPath = arg;\n }\n }\n\n return args;\n};\n\nconst formatSuccess = (artifact: BuilderArtifact): string => {\n const fragmentCount = Object.values(artifact.elements).filter((e) => e.type === \"fragment\").length;\n const operationCount = Object.values(artifact.elements).filter((e) => e.type === \"operation\").length;\n const lines: string[] = [`Artifact valid: ${fragmentCount} fragments, ${operationCount} operations`];\n\n if (artifact.meta) {\n lines.push(` Version: ${artifact.meta.version}`);\n lines.push(` Created: ${artifact.meta.createdAt}`);\n } else {\n lines.push(` (No metadata - legacy artifact format)`);\n }\n\n return lines.join(\"\\n\");\n};\n\ntype ValidateCommandResult = CommandResult<CommandSuccess & { data?: BuilderArtifact }>;\n\n/**\n * Validate command - validates a pre-built artifact file.\n */\nexport const validateCommand = async (argv: readonly string[]): Promise<ValidateCommandResult> => {\n const args = parseValidateArgs(argv);\n\n if (args.help) {\n return ok({ message: VALIDATE_HELP });\n }\n\n if (!args.artifactPath) {\n return err(cliErrors.argsInvalid(\"artifact validate\", \"Missing artifact path argument\"));\n }\n\n const artifactPath = resolve(process.cwd(), args.artifactPath);\n const result = await loadArtifact(artifactPath);\n\n if (result.isErr()) {\n return err(cliErrors.fromArtifact(result.error));\n }\n\n return ok({ message: formatSuccess(result.value), data: result.value });\n};\n","import { err, ok } from \"neverthrow\";\nimport { cliErrors } from \"../../errors\";\nimport type { CommandResult, CommandSuccess } from \"../../types\";\nimport { buildCommand } from \"./build\";\nimport { validateCommand } from \"./validate\";\n\nconst ARTIFACT_HELP = `Usage: soda-gql artifact <subcommand> [options]\n\nManage soda-gql artifacts.\n\nSubcommands:\n build Build artifacts (validate definitions)\n validate Validate a pre-built artifact file\n\nRun 'soda-gql artifact <subcommand> --help' for more information.\n`;\n\ntype ArtifactCommandResult = CommandResult<CommandSuccess>;\n\n/**\n * Dispatcher for artifact subcommands.\n */\nexport const artifactCommand = async (argv: readonly string[]): Promise<ArtifactCommandResult> => {\n const [subcommand, ...rest] = argv;\n\n if (!subcommand || subcommand === \"--help\" || subcommand === \"-h\") {\n return ok({ message: ARTIFACT_HELP });\n }\n\n if (subcommand === \"build\") {\n return buildCommand(rest);\n }\n\n if (subcommand === \"validate\") {\n return validateCommand(rest);\n }\n\n return err(cliErrors.unknownSubcommand(\"artifact\", subcommand));\n};\n","import { z } from \"zod\";\n\nexport const CodegenArgsSchema = z.object({\n config: z.string().optional(),\n \"emit-inject-template\": z.string().optional(),\n});\n\nexport const BuilderArgsSchema = z.object({\n mode: z.enum([\"runtime\", \"zero-runtime\"]),\n entry: z.string(),\n out: z.string(),\n format: z.enum([\"human\", \"json\"]).optional().default(\"human\"),\n});\n\nexport const FormatArgsSchema = z.object({\n _: z.array(z.string()).optional(),\n config: z.string().optional(),\n check: z.boolean().optional(),\n});\n\nexport const InitArgsSchema = z.object({\n force: z.boolean().optional(),\n});\n\nexport type CodegenArgs = z.infer<typeof CodegenArgsSchema>;\nexport type BuilderArgs = z.infer<typeof BuilderArgsSchema>;\nexport type FormatArgs = z.infer<typeof FormatArgsSchema>;\nexport type InitArgs = z.infer<typeof InitArgsSchema>;\n","import { err, ok, type Result } from \"neverthrow\";\nimport type { z } from \"zod\";\n\nexport const parseArgs = <T extends z.ZodType>(args: string[], schema: T): Result<z.infer<T>, string> => {\n const parsed: Record<string, unknown> = {};\n const positional: string[] = [];\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg) continue;\n\n if (arg.startsWith(\"--\")) {\n const key = arg.slice(2);\n const nextArg = args[i + 1];\n\n if (!nextArg || nextArg.startsWith(\"--\")) {\n parsed[key] = true;\n } else {\n parsed[key] = nextArg;\n i++;\n }\n } else {\n positional.push(arg);\n }\n }\n\n if (positional.length > 0) {\n parsed._ = positional;\n }\n\n const result = schema.safeParse(parsed);\n if (!result.success) {\n return err(result.error.issues.map((e) => e.message).join(\", \"));\n }\n\n return ok(result.data);\n};\n","import { resolve } from \"node:path\";\nimport type { CodegenSchemaConfig, CodegenSuccess } from \"@soda-gql/codegen\";\nimport { runCodegen, writeInjectTemplate } from \"@soda-gql/codegen\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport { err, ok } from \"neverthrow\";\nimport { type CliResult, cliErrors } from \"../errors\";\nimport { CodegenArgsSchema } from \"../schemas/args\";\nimport type { CommandResult, CommandSuccess } from \"../types\";\nimport { parseArgs } from \"../utils/parse-args\";\n\ntype ParsedCommand =\n | {\n kind: \"emitInjectTemplate\";\n outPath: string;\n }\n | {\n kind: \"generate\";\n schemas: Record<string, CodegenSchemaConfig>;\n outPath: string;\n importExtension: boolean;\n };\n\nconst parseCodegenArgs = (argv: readonly string[]): CliResult<ParsedCommand> => {\n const parsed = parseArgs([...argv], CodegenArgsSchema);\n\n if (!parsed.isOk()) {\n return err(cliErrors.argsInvalid(\"codegen\", parsed.error));\n }\n\n const args = parsed.value;\n\n // Handle emit inject template\n if (args[\"emit-inject-template\"]) {\n return ok({\n kind: \"emitInjectTemplate\",\n outPath: args[\"emit-inject-template\"],\n });\n }\n\n // Load config from @soda-gql/config\n const configResult = loadConfig(args.config);\n if (configResult.isErr()) {\n return err(cliErrors.fromConfig(configResult.error));\n }\n\n const config = configResult.value;\n\n // Check if schemas config exists\n if (!config.schemas || Object.keys(config.schemas).length === 0) {\n return err(cliErrors.argsInvalid(\"codegen\", \"schemas configuration is required in soda-gql.config.ts\"));\n }\n\n // Build schemas config with resolved paths\n const schemas: Record<string, CodegenSchemaConfig> = {};\n\n for (const [name, schemaConfig] of Object.entries(config.schemas)) {\n schemas[name] = {\n schema: schemaConfig.schema,\n inject: schemaConfig.inject,\n defaultInputDepth: schemaConfig.defaultInputDepth,\n inputDepthOverrides: schemaConfig.inputDepthOverrides,\n };\n }\n\n // Derive output path from outdir (default to index.ts)\n const outPath = resolve(config.outdir, \"index.ts\");\n\n return ok({\n kind: \"generate\",\n schemas,\n outPath,\n importExtension: config.styles.importExtension,\n });\n};\n\nconst formatSuccess = (success: CodegenSuccess): string => {\n const schemaNames = Object.keys(success.schemas).join(\", \");\n const totalObjects = Object.values(success.schemas).reduce((sum, s) => sum + s.objects, 0);\n return `Generated ${totalObjects} objects from schemas: ${schemaNames}\\n TypeScript: ${success.outPath}\\n CommonJS: ${success.cjsPath}`;\n};\n\nconst formatTemplateSuccess = (outPath: string): string => {\n return `Created inject template → ${outPath}`;\n};\n\nconst CODEGEN_HELP = `Usage: soda-gql codegen [options]\n\nGenerate graphql-system runtime module from GraphQL schema.\n\nOptions:\n --config <path> Path to soda-gql.config.ts\n --emit-inject-template <path> Create inject template file\n --help, -h Show this help message\n\nExamples:\n soda-gql codegen --config ./soda-gql.config.ts\n soda-gql codegen --emit-inject-template ./src/graphql/scalars.ts\n`;\n\ntype CodegenCommandResult = CommandResult<CommandSuccess & { data?: CodegenSuccess }>;\n\nexport const codegenCommand = async (argv: readonly string[]): Promise<CodegenCommandResult> => {\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n return ok({ message: CODEGEN_HELP });\n }\n\n const parsed = parseCodegenArgs(argv);\n\n if (parsed.isErr()) {\n return err(parsed.error);\n }\n\n const command = parsed.value;\n\n if (command.kind === \"emitInjectTemplate\") {\n const outPath = resolve(command.outPath);\n const result = writeInjectTemplate(outPath);\n if (result.isErr()) {\n return err(cliErrors.fromCodegen(result.error));\n }\n return ok({ message: formatTemplateSuccess(outPath) });\n }\n\n // Resolve all paths in schemas config\n const resolvedSchemas: Record<string, CodegenSchemaConfig> = {};\n for (const [name, schemaConfig] of Object.entries(command.schemas)) {\n resolvedSchemas[name] = {\n schema: resolve(schemaConfig.schema),\n inject: {\n scalars: resolve(schemaConfig.inject.scalars),\n ...(schemaConfig.inject.adapter ? { adapter: resolve(schemaConfig.inject.adapter) } : {}),\n },\n defaultInputDepth: schemaConfig.defaultInputDepth,\n inputDepthOverrides: schemaConfig.inputDepthOverrides,\n };\n }\n\n const result = await runCodegen({\n schemas: resolvedSchemas,\n outPath: resolve(command.outPath),\n format: \"human\",\n importExtension: command.importExtension,\n });\n\n if (result.isErr()) {\n return err(cliErrors.fromCodegen(result.error));\n }\n\n return ok({ message: formatSuccess(result.value), data: result.value });\n};\n","import { access, readFile, writeFile } from \"node:fs/promises\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport fg from \"fast-glob\";\nimport { err, ok } from \"neverthrow\";\nimport { cliErrors } from \"../errors\";\nimport { FormatArgsSchema } from \"../schemas/args\";\nimport type { CommandResult, CommandSuccess } from \"../types\";\nimport { parseArgs } from \"../utils/parse-args\";\n\ntype FormatterModule = typeof import(\"@soda-gql/formatter\");\n\nconst loadFormatter = async (): Promise<FormatterModule | null> => {\n try {\n return await import(\"@soda-gql/formatter\");\n } catch {\n return null;\n }\n};\n\ntype FormatData = {\n mode: \"format\" | \"check\";\n total: number;\n modified: number;\n unchanged: number;\n errors: number;\n unformatted: string[];\n hasFormattingIssues: boolean;\n};\n\nconst formatResultMessage = (data: FormatData): string => {\n if (data.mode === \"check\") {\n if (data.unformatted.length > 0) {\n const files = data.unformatted.map((f) => ` ${f}`).join(\"\\n\");\n return `${data.unformatted.length} file(s) need formatting:\\n${files}`;\n }\n return `All ${data.total} file(s) are properly formatted`;\n }\n\n const parts: string[] = [];\n if (data.modified > 0) {\n parts.push(`${data.modified} formatted`);\n }\n if (data.unchanged > 0) {\n parts.push(`${data.unchanged} unchanged`);\n }\n if (data.errors > 0) {\n parts.push(`${data.errors} errors`);\n }\n return `${data.total} file(s) checked: ${parts.join(\", \")}`;\n};\n\nconst isGlobPattern = (pattern: string): boolean => {\n return /[*?[\\]{}]/.test(pattern);\n};\n\nconst expandGlobPatterns = async (patterns: readonly string[], excludePatterns: readonly string[] = []): Promise<string[]> => {\n const files: string[] = [];\n\n for (const pattern of patterns) {\n if (!isGlobPattern(pattern)) {\n // Direct file path - check if it exists\n try {\n await access(pattern);\n files.push(pattern);\n } catch {\n // File doesn't exist, skip it\n }\n continue;\n }\n\n // Glob pattern - use fast-glob with ignore\n const matches = await fg(pattern, {\n absolute: true,\n ignore: [...excludePatterns],\n });\n files.push(...matches);\n }\n\n return [...new Set(files)];\n};\n\nconst FORMAT_HELP = `Usage: soda-gql format [patterns...] [options]\n\nFormat soda-gql field selections by inserting empty comments.\n\nOptions:\n --config <path> Path to soda-gql.config.ts (auto-detected if omitted)\n --check Check if files need formatting (exit 1 if unformatted)\n --help, -h Show this help message\n\nExamples:\n soda-gql format # Use config include/exclude\n soda-gql format \"src/**/*.ts\" # Override with explicit patterns\n soda-gql format --check # Check mode with config\n`;\n\ntype FormatCommandResult = CommandResult<CommandSuccess & { data?: FormatData }>;\n\nexport const formatCommand = async (argv: readonly string[]): Promise<FormatCommandResult> => {\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n return ok({ message: FORMAT_HELP });\n }\n\n const parsed = parseArgs([...argv], FormatArgsSchema);\n\n if (!parsed.isOk()) {\n return err(cliErrors.argsInvalid(\"format\", parsed.error));\n }\n\n const args = parsed.value;\n const isCheckMode = args.check === true;\n const explicitPatterns = args._ ?? [];\n\n // Determine patterns: use explicit patterns or load from config\n let targetPatterns: readonly string[];\n let excludePatterns: readonly string[] = [];\n\n if (explicitPatterns.length > 0) {\n targetPatterns = explicitPatterns;\n } else {\n // Try to load patterns from config\n const configResult = loadConfig(args.config);\n if (configResult.isErr()) {\n return err(cliErrors.noPatterns());\n }\n targetPatterns = configResult.value.include;\n excludePatterns = configResult.value.exclude;\n }\n\n // Load formatter lazily - it's an optional dependency\n const formatter = await loadFormatter();\n if (!formatter) {\n return err(cliErrors.formatterNotInstalled());\n }\n\n const files = await expandGlobPatterns(targetPatterns, excludePatterns);\n\n if (files.length === 0) {\n const data: FormatData = {\n mode: isCheckMode ? \"check\" : \"format\",\n total: 0,\n modified: 0,\n unchanged: 0,\n errors: 0,\n unformatted: [],\n hasFormattingIssues: false,\n };\n return ok({ message: formatResultMessage(data), data });\n }\n\n let modified = 0;\n let unchanged = 0;\n let errors = 0;\n const unformatted: string[] = [];\n\n for (const filePath of files) {\n const sourceCode = await readFile(filePath, \"utf-8\");\n\n if (isCheckMode) {\n const result = formatter.needsFormat({ sourceCode, filePath });\n if (result.isErr()) {\n errors++;\n continue;\n }\n if (result.value) {\n unformatted.push(filePath);\n modified++;\n } else {\n unchanged++;\n }\n } else {\n const result = formatter.format({ sourceCode, filePath });\n if (result.isErr()) {\n errors++;\n continue;\n }\n if (result.value.modified) {\n await writeFile(filePath, result.value.sourceCode, \"utf-8\");\n modified++;\n } else {\n unchanged++;\n }\n }\n }\n\n const data: FormatData = {\n mode: isCheckMode ? \"check\" : \"format\",\n total: files.length,\n modified,\n unchanged,\n errors,\n unformatted,\n hasFormattingIssues: (isCheckMode && unformatted.length > 0) || errors > 0,\n };\n\n return ok({ message: formatResultMessage(data), data });\n};\n","export const getConfigTemplate = (): string => `\\\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig({\n outdir: \"./graphql-system\",\n include: [\"./src/**/*.ts\"],\n schemas: {\n default: {\n schema: \"./schema.graphql\",\n inject: \"./graphql-system/default.inject.ts\",\n },\n },\n});\n`;\n","export const getGitignoreTemplate = (): string => `\\\n/index.ts\n/index.cjs\n`;\n","export const getInjectTemplate = (): string => `\\\nimport { defineAdapter, defineScalar } from \"@soda-gql/core/adapter\";\n\nexport const scalar = {\n ...defineScalar<\"ID\", string, string>(\"ID\"),\n ...defineScalar<\"String\", string, string>(\"String\"),\n ...defineScalar<\"Int\", number, number>(\"Int\"),\n ...defineScalar<\"Float\", number, number>(\"Float\"),\n ...defineScalar<\"Boolean\", boolean, boolean>(\"Boolean\"),\n} as const;\n\nexport const adapter = defineAdapter({\n helpers: {},\n metadata: {\n aggregateFragmentMetadata: (fragments) => fragments.map((m) => m.metadata),\n },\n});\n`;\n","export const getSchemaTemplate = (): string => `\\\ntype Query {\n hello: String!\n}\n`;\n","import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok, type Result } from \"neverthrow\";\n\nimport { type CliError, cliErrors } from \"../errors\";\nimport { InitArgsSchema } from \"../schemas/args\";\nimport { getConfigTemplate } from \"../templates/config.template\";\nimport { getGitignoreTemplate } from \"../templates/gitignore.template\";\nimport { getInjectTemplate } from \"../templates/inject.template\";\nimport { getSchemaTemplate } from \"../templates/schema.template\";\nimport type { CommandResult, CommandSuccess } from \"../types\";\nimport { parseArgs } from \"../utils/parse-args\";\n\ntype FileToGenerate = {\n readonly path: string;\n readonly content: string;\n readonly description: string;\n};\n\ntype InitSuccess = {\n readonly filesCreated: readonly string[];\n};\n\nconst INIT_HELP = `Usage: soda-gql init [options]\n\nInitialize a new soda-gql project with starter configuration.\n\nOptions:\n --force Overwrite existing files\n --help, -h Show this help message\n\nGenerated files:\n soda-gql.config.ts Configuration file\n schema.graphql Sample GraphQL schema\n graphql-system/default.inject.ts Scalars, helpers, and metadata adapter\n graphql-system/.gitignore Ignore generated files\n`;\n\nconst checkFilesExist = (files: readonly FileToGenerate[], force: boolean): Result<void, CliError> => {\n if (force) {\n return ok(undefined);\n }\n\n for (const file of files) {\n if (existsSync(file.path)) {\n return err(cliErrors.fileExists(file.path));\n }\n }\n\n return ok(undefined);\n};\n\nconst writeFiles = (files: readonly FileToGenerate[]): Result<InitSuccess, CliError> => {\n const createdPaths: string[] = [];\n\n for (const file of files) {\n try {\n const dir = dirname(file.path);\n mkdirSync(dir, { recursive: true });\n writeFileSync(file.path, file.content);\n createdPaths.push(file.path);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err(cliErrors.writeFailed(file.path, `Failed to write ${file.description}: ${message}`, error));\n }\n }\n\n return ok({ filesCreated: createdPaths });\n};\n\nconst formatSuccess = (result: InitSuccess): string => {\n const lines = [\"soda-gql project initialized successfully!\", \"\", \"Created files:\"];\n for (const file of result.filesCreated) {\n lines.push(` ${file}`);\n }\n lines.push(\"\", \"Next steps:\");\n lines.push(\" 1. Edit schema.graphql with your GraphQL types\");\n lines.push(\" 2. Run: soda-gql codegen\");\n lines.push(\" 3. Import gql from ./graphql-system\");\n return lines.join(\"\\n\");\n};\n\ntype InitCommandResult = CommandResult<CommandSuccess & { data?: InitSuccess }>;\n\nexport const initCommand = async (argv: readonly string[]): Promise<InitCommandResult> => {\n if (argv.includes(\"--help\") || argv.includes(\"-h\")) {\n return ok({ message: INIT_HELP });\n }\n\n const parsed = parseArgs([...argv], InitArgsSchema);\n\n if (!parsed.isOk()) {\n return err(cliErrors.argsInvalid(\"init\", parsed.error));\n }\n\n const args = parsed.value;\n const force = args.force === true;\n const cwd = process.cwd();\n\n const files: FileToGenerate[] = [\n {\n path: resolve(cwd, \"soda-gql.config.ts\"),\n content: getConfigTemplate(),\n description: \"configuration file\",\n },\n {\n path: resolve(cwd, \"schema.graphql\"),\n content: getSchemaTemplate(),\n description: \"GraphQL schema\",\n },\n {\n path: resolve(cwd, \"graphql-system/default.inject.ts\"),\n content: getInjectTemplate(),\n description: \"inject module\",\n },\n {\n path: resolve(cwd, \"graphql-system/.gitignore\"),\n content: getGitignoreTemplate(),\n description: \"gitignore file\",\n },\n ];\n\n const existsCheck = checkFilesExist(files, force);\n if (existsCheck.isErr()) {\n return err(existsCheck.error);\n }\n\n const writeResult = writeFiles(files);\n if (writeResult.isErr()) {\n return err(writeResult.error);\n }\n\n return ok({ message: formatSuccess(writeResult.value), data: writeResult.value });\n};\n","import { formatBuilderErrorForCLI } from \"@soda-gql/builder\";\nimport type { CliError, CliErrorCode } from \"../errors\";\nimport type { OutputFormat } from \"../types\";\n\nexport type { OutputFormat } from \"../types\";\n\n/**\n * CLI-specific error hints to help users fix issues.\n */\nconst cliErrorHints: Partial<Record<CliErrorCode, string>> = {\n CLI_ARGS_INVALID: \"Check command usage with --help\",\n CLI_UNKNOWN_COMMAND: \"Run 'soda-gql --help' for available commands\",\n CLI_UNKNOWN_SUBCOMMAND: \"Run the parent command with --help for available subcommands\",\n CLI_FILE_EXISTS: \"Use --force flag to overwrite existing files\",\n CLI_FILE_NOT_FOUND: \"Verify the file path exists\",\n CLI_WRITE_FAILED: \"Check write permissions and disk space\",\n CLI_READ_FAILED: \"Check file permissions and verify the file is not locked\",\n CLI_NO_PATTERNS: \"Provide file patterns or create soda-gql.config.ts\",\n CLI_FORMATTER_NOT_INSTALLED: \"Install with: bun add @soda-gql/formatter\",\n CLI_PARSE_ERROR: \"Check the file for syntax errors\",\n CLI_FORMAT_ERROR: \"Verify the file contains valid soda-gql code\",\n CLI_UNEXPECTED: \"This is an unexpected error. Please report at https://github.com/soda-gql/soda-gql/issues\",\n};\n\n/**\n * Codegen-specific error hints.\n */\nconst codegenErrorHints: Record<string, string> = {\n SCHEMA_NOT_FOUND: \"Verify the schema path in soda-gql.config.ts\",\n SCHEMA_INVALID: \"Check your GraphQL schema for syntax errors\",\n INJECT_MODULE_NOT_FOUND: \"Run: soda-gql codegen --emit-inject-template <path>\",\n INJECT_MODULE_REQUIRED: \"Add inject configuration to your schema in soda-gql.config.ts\",\n INJECT_TEMPLATE_EXISTS: \"Delete the existing file to regenerate, or use a different path\",\n EMIT_FAILED: \"Check write permissions and that the output directory exists\",\n INJECT_TEMPLATE_FAILED: \"Check write permissions for the output path\",\n};\n\n/**\n * Config-specific error hints.\n */\nconst configErrorHints: Record<string, string> = {\n CONFIG_NOT_FOUND: \"Create a soda-gql.config.ts file in your project root\",\n CONFIG_LOAD_FAILED: \"Check your configuration file for syntax errors\",\n CONFIG_VALIDATION_FAILED: \"Verify your configuration matches the expected schema\",\n CONFIG_INVALID_PATH: \"Verify the path in your configuration exists\",\n};\n\n/**\n * Artifact-specific error hints.\n */\nconst artifactErrorHints: Record<string, string> = {\n ARTIFACT_NOT_FOUND: \"Verify the artifact file path exists\",\n ARTIFACT_PARSE_ERROR: \"Check that the artifact file is valid JSON\",\n ARTIFACT_VALIDATION_ERROR: \"Verify the artifact was built with a compatible version of soda-gql\",\n};\n\n/**\n * Get hint for any error type.\n */\nconst getErrorHint = (error: CliError): string | undefined => {\n if (error.category === \"cli\") {\n return cliErrorHints[error.code];\n }\n if (error.category === \"codegen\") {\n return codegenErrorHints[error.error.code];\n }\n if (error.category === \"config\") {\n return configErrorHints[error.error.code];\n }\n if (error.category === \"artifact\") {\n return artifactErrorHints[error.error.code];\n }\n // Builder errors use their own hints via formatBuilderErrorForCLI\n return undefined;\n};\n\n/**\n * Format CliError to human-readable string with hints.\n */\nexport const formatCliErrorHuman = (error: CliError): string => {\n // Delegate to builder's formatter for builder errors\n if (error.category === \"builder\") {\n return formatBuilderErrorForCLI(error.error);\n }\n\n const lines: string[] = [];\n\n if (error.category === \"codegen\") {\n const codegenError = error.error;\n lines.push(`Error [${codegenError.code}]: ${codegenError.message}`);\n\n // Add context based on error type\n if (\"schemaPath\" in codegenError) {\n lines.push(` Schema: ${codegenError.schemaPath}`);\n }\n if (\"outPath\" in codegenError && codegenError.outPath) {\n lines.push(` Output: ${codegenError.outPath}`);\n }\n if (\"injectPath\" in codegenError) {\n lines.push(` Inject: ${codegenError.injectPath}`);\n }\n } else if (error.category === \"config\") {\n const configError = error.error;\n lines.push(`Error [${configError.code}]: ${configError.message}`);\n if (configError.filePath) {\n lines.push(` Config: ${configError.filePath}`);\n }\n } else if (error.category === \"artifact\") {\n const artifactError = error.error;\n lines.push(`Error [${artifactError.code}]: ${artifactError.message}`);\n if (artifactError.filePath) {\n lines.push(` Artifact: ${artifactError.filePath}`);\n }\n } else {\n // CLI errors\n lines.push(`Error [${error.code}]: ${error.message}`);\n\n if (\"filePath\" in error && error.filePath) {\n lines.push(` File: ${error.filePath}`);\n }\n if (\"command\" in error && error.code !== \"CLI_UNKNOWN_COMMAND\") {\n lines.push(` Command: ${error.command}`);\n }\n if (\"parent\" in error) {\n lines.push(` Parent: ${error.parent}`);\n }\n }\n\n const hint = getErrorHint(error);\n if (hint) {\n lines.push(\"\");\n lines.push(` Hint: ${hint}`);\n }\n\n return lines.join(\"\\n\");\n};\n\n/**\n * Format CliError to JSON string.\n */\nexport const formatCliErrorJson = (error: CliError): string => {\n if (error.category === \"cli\") {\n const { category: _category, ...rest } = error;\n return JSON.stringify({ error: rest }, null, 2);\n }\n return JSON.stringify({ error: error.error }, null, 2);\n};\n\n/**\n * Format CliError with output format preference.\n */\nexport const formatCliError = (error: CliError, format: OutputFormat = \"human\"): string => {\n return format === \"json\" ? formatCliErrorJson(error) : formatCliErrorHuman(error);\n};\n\n// ---- Legacy formatters (kept for backward compatibility) ----\n\nexport const formatters = {\n json: (data: unknown) => JSON.stringify(data, null, 2),\n human: (data: unknown) => {\n if (typeof data === \"string\") return data;\n if (data instanceof Error) return data.message;\n return JSON.stringify(data, null, 2);\n },\n} as const;\n\nexport const formatOutput = (data: unknown, format: OutputFormat = \"human\"): string => {\n return formatters[format](data);\n};\n\n/**\n * @deprecated Use formatCliError instead for CliError types.\n */\nexport const formatError = (error: unknown, format: OutputFormat = \"human\"): string => {\n if (format === \"json\") {\n return JSON.stringify(\n {\n error: error,\n },\n null,\n 2,\n );\n }\n return error instanceof Error ? error.message : String(error);\n};\n","import { err, ok } from \"neverthrow\";\nimport { artifactCommand } from \"./commands/artifact\";\nimport { codegenCommand } from \"./commands/codegen\";\nimport { formatCommand } from \"./commands/format\";\nimport { initCommand } from \"./commands/init\";\nimport { cliErrors } from \"./errors\";\nimport type { CommandResult, CommandSuccess, OutputFormat } from \"./types\";\nimport { formatCliError } from \"./utils/format\";\n\nconst MAIN_HELP = `Usage: soda-gql <command> [options]\n\nCommands:\n init Initialize a new soda-gql project\n codegen Generate graphql-system runtime module\n format Format soda-gql field selections\n artifact Manage soda-gql artifacts\n\nRun 'soda-gql <command> --help' for more information on a specific command.\n`;\n\n/**\n * Parse output format from argv.\n * Returns \"json\" if --format=json or --json flag is present, otherwise \"human\".\n */\nconst getOutputFormat = (argv: readonly string[]): OutputFormat => {\n for (const arg of argv) {\n if (arg === \"--format=json\" || arg === \"--json\") {\n return \"json\";\n }\n if (arg === \"--format=human\") {\n return \"human\";\n }\n }\n return \"human\";\n};\n\ntype DispatchResult = CommandResult<CommandSuccess & { exitCode?: number }>;\n\nconst dispatch = async (argv: readonly string[]): Promise<DispatchResult> => {\n const [command, ...rest] = argv;\n\n if (!command || command === \"--help\" || command === \"-h\") {\n return ok({ message: MAIN_HELP });\n }\n\n if (command === \"init\") {\n return initCommand(rest);\n }\n\n if (command === \"codegen\") {\n return codegenCommand(rest);\n }\n\n if (command === \"format\") {\n const result = await formatCommand(rest);\n if (result.isOk()) {\n // Format command uses exit 1 for unformatted files in check mode or errors\n const exitCode = result.value.data?.hasFormattingIssues ? 1 : 0;\n return ok({ ...result.value, exitCode });\n }\n return err(result.error);\n }\n\n if (command === \"artifact\") {\n return artifactCommand(rest);\n }\n\n return err(cliErrors.unknownCommand(command));\n};\n\n// Run CLI when executed directly\nconst main = async () => {\n const argv = process.argv.slice(2);\n const format = getOutputFormat(argv);\n\n const result = await dispatch(argv);\n\n if (result.isOk()) {\n process.stdout.write(`${result.value.message}\\n`);\n process.exitCode = result.value.exitCode ?? 0;\n } else {\n process.stderr.write(`${formatCliError(result.error, format)}\\n`);\n process.exitCode = 1;\n }\n};\n\nmain().catch((error) => {\n const unexpectedError = cliErrors.unexpected(error instanceof Error ? error.message : String(error), error);\n const format = getOutputFormat(process.argv.slice(2));\n process.stderr.write(`${formatCliError(unexpectedError, format)}\\n`);\n process.exitCode = 1;\n});\n\nexport { dispatch };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+IA,MAAa,YAAY;CACvB,cAAc,SAAiB,aAA0C;EACv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Q,WAAW,OAAO,MAAM,YAAY;QACvC;AACL,UAAQ,OAAO,MAAM,GAAG,eAAe,OAAO,OAAO,OAAO,CAAC,IAAI;AACjE,UAAQ,WAAW;;;AAIvB,MAAM,CAAC,OAAO,UAAU;CACtB,MAAM,kBAAkB,UAAU,WAAW,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EAAE,MAAM;CAC3G,MAAM,SAAS,gBAAgB,QAAQ,KAAK,MAAM,EAAE,CAAC;AACrD,SAAQ,OAAO,MAAM,GAAG,eAAe,iBAAiB,OAAO,CAAC,IAAI;AACpE,SAAQ,WAAW;EACnB"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,106 @@
|
|
|
1
|
+
import { Result } from "neverthrow";
|
|
2
|
+
import { ArtifactLoadError, BuilderError } from "@soda-gql/builder";
|
|
3
|
+
import { CodegenError } from "@soda-gql/codegen";
|
|
4
|
+
import { ConfigError } from "@soda-gql/config";
|
|
5
|
+
|
|
6
|
+
//#region packages/cli/src/errors.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Unified CLI error discriminated union.
|
|
10
|
+
* Wraps external errors (codegen, builder, config) and defines CLI-specific errors.
|
|
11
|
+
*/
|
|
12
|
+
type CliError = {
|
|
13
|
+
readonly category: "codegen";
|
|
14
|
+
readonly error: CodegenError;
|
|
15
|
+
} | {
|
|
16
|
+
readonly category: "builder";
|
|
17
|
+
readonly error: BuilderError;
|
|
18
|
+
} | {
|
|
19
|
+
readonly category: "artifact";
|
|
20
|
+
readonly error: ArtifactLoadError;
|
|
21
|
+
} | {
|
|
22
|
+
readonly category: "config";
|
|
23
|
+
readonly error: ConfigError;
|
|
24
|
+
} | {
|
|
25
|
+
readonly category: "cli";
|
|
26
|
+
readonly code: "CLI_ARGS_INVALID";
|
|
27
|
+
readonly message: string;
|
|
28
|
+
readonly command: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly category: "cli";
|
|
31
|
+
readonly code: "CLI_UNKNOWN_COMMAND";
|
|
32
|
+
readonly message: string;
|
|
33
|
+
readonly command: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly category: "cli";
|
|
36
|
+
readonly code: "CLI_UNKNOWN_SUBCOMMAND";
|
|
37
|
+
readonly message: string;
|
|
38
|
+
readonly parent: string;
|
|
39
|
+
readonly subcommand: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly category: "cli";
|
|
42
|
+
readonly code: "CLI_FILE_EXISTS";
|
|
43
|
+
readonly message: string;
|
|
44
|
+
readonly filePath: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly category: "cli";
|
|
47
|
+
readonly code: "CLI_FILE_NOT_FOUND";
|
|
48
|
+
readonly message: string;
|
|
49
|
+
readonly filePath: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly category: "cli";
|
|
52
|
+
readonly code: "CLI_WRITE_FAILED";
|
|
53
|
+
readonly message: string;
|
|
54
|
+
readonly filePath: string;
|
|
55
|
+
readonly cause?: unknown;
|
|
56
|
+
} | {
|
|
57
|
+
readonly category: "cli";
|
|
58
|
+
readonly code: "CLI_READ_FAILED";
|
|
59
|
+
readonly message: string;
|
|
60
|
+
readonly filePath: string;
|
|
61
|
+
readonly cause?: unknown;
|
|
62
|
+
} | {
|
|
63
|
+
readonly category: "cli";
|
|
64
|
+
readonly code: "CLI_NO_PATTERNS";
|
|
65
|
+
readonly message: string;
|
|
66
|
+
} | {
|
|
67
|
+
readonly category: "cli";
|
|
68
|
+
readonly code: "CLI_FORMATTER_NOT_INSTALLED";
|
|
69
|
+
readonly message: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly category: "cli";
|
|
72
|
+
readonly code: "CLI_PARSE_ERROR";
|
|
73
|
+
readonly message: string;
|
|
74
|
+
readonly filePath?: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly category: "cli";
|
|
77
|
+
readonly code: "CLI_FORMAT_ERROR";
|
|
78
|
+
readonly message: string;
|
|
79
|
+
readonly filePath?: string;
|
|
80
|
+
} | {
|
|
81
|
+
readonly category: "cli";
|
|
82
|
+
readonly code: "CLI_UNEXPECTED";
|
|
83
|
+
readonly message: string;
|
|
84
|
+
readonly cause?: unknown;
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region packages/cli/src/types.d.ts
|
|
88
|
+
/**
|
|
89
|
+
* Result type for all CLI commands.
|
|
90
|
+
*/
|
|
91
|
+
type CommandResult<T = CommandSuccess> = Result<T, CliError>;
|
|
92
|
+
/**
|
|
93
|
+
* Standard success response for commands.
|
|
94
|
+
*/
|
|
95
|
+
type CommandSuccess = {
|
|
96
|
+
readonly message: string;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
1
99
|
//#region packages/cli/src/index.d.ts
|
|
2
|
-
|
|
100
|
+
type DispatchResult = CommandResult<CommandSuccess & {
|
|
101
|
+
exitCode?: number;
|
|
102
|
+
}>;
|
|
103
|
+
declare const dispatch: (argv: readonly string[]) => Promise<DispatchResult>;
|
|
3
104
|
//#endregion
|
|
4
105
|
export { dispatch };
|
|
5
106
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;ACWA,CAAA,CAAA;AAA8B,IAAA,CDwBlB,QAAA,CAAA,CAAA,CCxBkB;EAAyB,QAAA,CAAA,QAAA,CAAA,CAAA,CAAA,OAAA,CAAA;EAAG,QAAA,CAAA,KAAA,CAAA,CD0BN,YC1BM;CAAV,CAAA,CAAA,CAAA;EAAM,QAAA,CAAA,QAAA,CAAA,CAAA,CAAA,OAAA,CAAA;EAK1C,QAAA,CAAA,KAAA,CAAA,CDsBwC,YCtB1B;;;kBDuB2B;AEjCsB,CAAA,CAAA,CAAA,CA8BtE;EAEC,QAAA,CAAA,QA8BL,CAAA,CAAA,CAAA,MAAA,CA9ByD;kBFEP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALnD,CAAA,CAAA;;;AAIqD,IAAA,CC5BzC,aD4ByC,CAAA,CAAA,CAAA,CAAA,CC5BvB,cD4BuB,CAAA,CAAA,CAAA,CC5BL,MD4BK,CC5BE,CD4BF,CAAA,CC5BK,QD4BL,CAAA;;;;KCvBzC,cAAA,CAAA,CAAA;;AALZ,CAAA;;;KCyBK,cAAA,CAAA,CAAA,CAAiB,cAAc;;;cAE9B,uCAA4C,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Command-line interface for soda-gql",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"./package.json": "./package.json"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@soda-gql/codegen": "~0.
|
|
52
|
-
"@soda-gql/builder": "~0.
|
|
51
|
+
"@soda-gql/codegen": "~0.8.0",
|
|
52
|
+
"@soda-gql/builder": "~0.8.0",
|
|
53
53
|
"fast-glob": "^3.3.3",
|
|
54
54
|
"neverthrow": "^8.1.1",
|
|
55
55
|
"zod": "^4.1.11"
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
"devDependencies": {},
|
|
58
58
|
"peerDependencies": {},
|
|
59
59
|
"optionalDependencies": {
|
|
60
|
-
"@soda-gql/formatter": "~0.
|
|
60
|
+
"@soda-gql/formatter": "~0.8.0"
|
|
61
61
|
}
|
|
62
62
|
}
|