chowbea-axios 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +162 -0
- package/bin/dev.js +13 -0
- package/bin/run.js +10 -0
- package/dist/commands/diff.d.ts +31 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +215 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/fetch.d.ts +28 -0
- package/dist/commands/fetch.d.ts.map +1 -0
- package/dist/commands/fetch.js +223 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/generate.d.ts +26 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +187 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +92 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +738 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/status.d.ts +38 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +233 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/validate.d.ts +27 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +209 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/commands/watch.d.ts +34 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +202 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +151 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +336 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +77 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +144 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/fetcher.d.ts +115 -0
- package/dist/lib/fetcher.d.ts.map +1 -0
- package/dist/lib/fetcher.js +237 -0
- package/dist/lib/fetcher.js.map +1 -0
- package/dist/lib/generator.d.ts +96 -0
- package/dist/lib/generator.d.ts.map +1 -0
- package/dist/lib/generator.js +1575 -0
- package/dist/lib/generator.js.map +1 -0
- package/dist/lib/logger.d.ts +63 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +183 -0
- package/dist/lib/logger.js.map +1 -0
- package/oclif.manifest.json +556 -0
- package/package.json +68 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch command - fetches OpenAPI spec from remote endpoint and generates types.
|
|
3
|
+
* Includes retry logic and caching to skip regeneration when spec hasn't changed.
|
|
4
|
+
*/
|
|
5
|
+
import { Command, Flags } from "@oclif/core";
|
|
6
|
+
import { ensureOutputFolders, getOutputPaths, loadConfig, resolveSpecSource, } from "../lib/config.js";
|
|
7
|
+
import { formatError } from "../lib/errors.js";
|
|
8
|
+
import { fetchOpenApiSpec, loadLocalSpecFile, saveSpec, } from "../lib/fetcher.js";
|
|
9
|
+
import { generate, generateClientFiles } from "../lib/generator.js";
|
|
10
|
+
import { createLogger, formatDuration, getLogLevel, logSeparator, } from "../lib/logger.js";
|
|
11
|
+
/**
|
|
12
|
+
* Fetch OpenAPI spec from remote endpoint and generate types.
|
|
13
|
+
*/
|
|
14
|
+
export default class Fetch extends Command {
|
|
15
|
+
static description = `Fetch OpenAPI spec and generate TypeScript types + operations.
|
|
16
|
+
|
|
17
|
+
Downloads the spec from your configured endpoint (or local file),
|
|
18
|
+
caches it, and generates api.types.ts and api.operations.ts.
|
|
19
|
+
|
|
20
|
+
Skips regeneration if spec hasn't changed (use --force to override).
|
|
21
|
+
Falls back to cached spec on network failure.`;
|
|
22
|
+
static examples = [
|
|
23
|
+
{
|
|
24
|
+
command: "<%= config.bin %> fetch",
|
|
25
|
+
description: "Fetch from configured endpoint, generate if changed",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
command: "<%= config.bin %> fetch --force",
|
|
29
|
+
description: "Force regeneration even if spec unchanged",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
command: "<%= config.bin %> fetch --spec-file ./openapi.json",
|
|
33
|
+
description: "Use local spec file instead of remote",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
command: "<%= config.bin %> fetch --dry-run",
|
|
37
|
+
description: "Preview what would be generated",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
command: "<%= config.bin %> fetch --types-only",
|
|
41
|
+
description: "Generate only TypeScript types",
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
static flags = {
|
|
45
|
+
config: Flags.string({
|
|
46
|
+
char: "c",
|
|
47
|
+
description: "Path to api.config.toml",
|
|
48
|
+
}),
|
|
49
|
+
endpoint: Flags.string({
|
|
50
|
+
char: "e",
|
|
51
|
+
description: "Override API endpoint URL",
|
|
52
|
+
}),
|
|
53
|
+
"spec-file": Flags.string({
|
|
54
|
+
char: "s",
|
|
55
|
+
description: "Use local spec file instead of fetching from remote",
|
|
56
|
+
}),
|
|
57
|
+
force: Flags.boolean({
|
|
58
|
+
char: "f",
|
|
59
|
+
description: "Force regeneration even if spec hasn't changed",
|
|
60
|
+
default: false,
|
|
61
|
+
}),
|
|
62
|
+
"dry-run": Flags.boolean({
|
|
63
|
+
char: "n",
|
|
64
|
+
description: "Show what would be generated without writing files",
|
|
65
|
+
default: false,
|
|
66
|
+
}),
|
|
67
|
+
"types-only": Flags.boolean({
|
|
68
|
+
description: "Generate only TypeScript types (skip operations)",
|
|
69
|
+
default: false,
|
|
70
|
+
}),
|
|
71
|
+
"operations-only": Flags.boolean({
|
|
72
|
+
description: "Generate only operations (skip types)",
|
|
73
|
+
default: false,
|
|
74
|
+
}),
|
|
75
|
+
quiet: Flags.boolean({
|
|
76
|
+
char: "q",
|
|
77
|
+
description: "Suppress non-error output",
|
|
78
|
+
default: false,
|
|
79
|
+
}),
|
|
80
|
+
verbose: Flags.boolean({
|
|
81
|
+
char: "v",
|
|
82
|
+
description: "Show detailed output",
|
|
83
|
+
default: false,
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
async run() {
|
|
87
|
+
const { flags } = await this.parse(Fetch);
|
|
88
|
+
// Create logger with appropriate level
|
|
89
|
+
const logger = createLogger({
|
|
90
|
+
level: getLogLevel(flags),
|
|
91
|
+
});
|
|
92
|
+
logSeparator(logger, "chowbea-axios fetch");
|
|
93
|
+
try {
|
|
94
|
+
// Load configuration (auto-creates if missing)
|
|
95
|
+
logger.info("Loading configuration...");
|
|
96
|
+
const { config, projectRoot, configPath, wasCreated } = await loadConfig(flags.config);
|
|
97
|
+
if (wasCreated) {
|
|
98
|
+
logger.warn({ configPath }, "Created default api.config.toml - please review and update settings");
|
|
99
|
+
}
|
|
100
|
+
// Get output paths
|
|
101
|
+
const outputPaths = getOutputPaths(config, projectRoot);
|
|
102
|
+
logger.debug({ outputPaths }, "Resolved output paths");
|
|
103
|
+
// Ensure output folders exist (_internal, _generated)
|
|
104
|
+
await ensureOutputFolders(outputPaths);
|
|
105
|
+
logger.debug({ folder: outputPaths.folder }, "Output folders ready");
|
|
106
|
+
// Resolve spec source (flag > config spec_file > config api_endpoint)
|
|
107
|
+
// Note: --endpoint flag overrides spec_file for remote fetching
|
|
108
|
+
const specFile = flags["spec-file"];
|
|
109
|
+
const specSource = flags.endpoint
|
|
110
|
+
? { type: "remote", endpoint: flags.endpoint }
|
|
111
|
+
: resolveSpecSource(config, projectRoot, specFile);
|
|
112
|
+
let fetchResult;
|
|
113
|
+
let sourceIdentifier;
|
|
114
|
+
if (specSource.type === "local") {
|
|
115
|
+
// Load from local file
|
|
116
|
+
sourceIdentifier = specSource.path;
|
|
117
|
+
fetchResult = await loadLocalSpecFile({
|
|
118
|
+
localPath: specSource.path,
|
|
119
|
+
specPath: outputPaths.spec,
|
|
120
|
+
cachePath: outputPaths.cache,
|
|
121
|
+
logger,
|
|
122
|
+
force: flags.force,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// Fetch from remote endpoint
|
|
127
|
+
sourceIdentifier = specSource.endpoint;
|
|
128
|
+
logger.info({ endpoint: specSource.endpoint }, "Fetching OpenAPI spec...");
|
|
129
|
+
fetchResult = await fetchOpenApiSpec({
|
|
130
|
+
endpoint: specSource.endpoint,
|
|
131
|
+
specPath: outputPaths.spec,
|
|
132
|
+
cachePath: outputPaths.cache,
|
|
133
|
+
logger,
|
|
134
|
+
force: flags.force,
|
|
135
|
+
headers: config.fetch?.headers,
|
|
136
|
+
});
|
|
137
|
+
// Handle network fallback
|
|
138
|
+
if (fetchResult.fromCache) {
|
|
139
|
+
logger.warn("Using cached spec due to network issues");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!(fetchResult.hasChanged || flags.force)) {
|
|
143
|
+
logger.info("Spec unchanged, skipping generation");
|
|
144
|
+
logger.info("Use --force to regenerate anyway");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Save the new spec
|
|
148
|
+
await saveSpec({
|
|
149
|
+
buffer: fetchResult.buffer,
|
|
150
|
+
hash: fetchResult.hash,
|
|
151
|
+
endpoint: sourceIdentifier,
|
|
152
|
+
specPath: outputPaths.spec,
|
|
153
|
+
cachePath: outputPaths.cache,
|
|
154
|
+
});
|
|
155
|
+
logger.info({
|
|
156
|
+
bytes: fetchResult.buffer.length,
|
|
157
|
+
hash: fetchResult.hash.slice(0, 8),
|
|
158
|
+
}, "Spec saved");
|
|
159
|
+
// Generate client files if they don't exist
|
|
160
|
+
const clientFiles = await generateClientFiles({
|
|
161
|
+
paths: outputPaths,
|
|
162
|
+
instanceConfig: config.instance,
|
|
163
|
+
logger,
|
|
164
|
+
});
|
|
165
|
+
// Validate flag combination
|
|
166
|
+
if (flags["types-only"] && flags["operations-only"]) {
|
|
167
|
+
logger.error("Cannot use --types-only and --operations-only together");
|
|
168
|
+
this.exit(1);
|
|
169
|
+
}
|
|
170
|
+
// Run generation
|
|
171
|
+
logger.info("Starting type and operation generation...");
|
|
172
|
+
const result = await generate({
|
|
173
|
+
paths: outputPaths,
|
|
174
|
+
logger,
|
|
175
|
+
dryRun: flags["dry-run"],
|
|
176
|
+
skipTypes: flags["operations-only"],
|
|
177
|
+
skipOperations: flags["types-only"],
|
|
178
|
+
});
|
|
179
|
+
// Handle dry-run output
|
|
180
|
+
if (flags["dry-run"] && result.dryRunResult) {
|
|
181
|
+
logSeparator(logger);
|
|
182
|
+
logger.info("Dry run complete - no files written");
|
|
183
|
+
logger.info({ operations: result.dryRunResult.operationCount }, "Operations found");
|
|
184
|
+
for (const file of result.dryRunResult.files) {
|
|
185
|
+
const info = file.lines > 0 ? ` (${file.lines} lines)` : " (types)";
|
|
186
|
+
logger.info(`Would ${file.action}: ${file.path}${info}`);
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
// Report success
|
|
191
|
+
logSeparator(logger);
|
|
192
|
+
logger.info({
|
|
193
|
+
operations: result.operationCount,
|
|
194
|
+
duration: formatDuration(result.durationMs),
|
|
195
|
+
}, "Fetch and generation completed successfully");
|
|
196
|
+
if (result.typesGenerated) {
|
|
197
|
+
logger.info({ types: outputPaths.types }, "Types output");
|
|
198
|
+
}
|
|
199
|
+
if (result.operationsGenerated) {
|
|
200
|
+
logger.info({ operations: outputPaths.operations }, "Operations output");
|
|
201
|
+
}
|
|
202
|
+
if (clientFiles.helpers ||
|
|
203
|
+
clientFiles.instance ||
|
|
204
|
+
clientFiles.error ||
|
|
205
|
+
clientFiles.client) {
|
|
206
|
+
logger.info("Client files created:");
|
|
207
|
+
if (clientFiles.helpers)
|
|
208
|
+
logger.info(` - ${outputPaths.helpers}`);
|
|
209
|
+
if (clientFiles.instance)
|
|
210
|
+
logger.info(` - ${outputPaths.instance}`);
|
|
211
|
+
if (clientFiles.error)
|
|
212
|
+
logger.info(` - ${outputPaths.error}`);
|
|
213
|
+
if (clientFiles.client)
|
|
214
|
+
logger.info(` - ${outputPaths.client}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
logger.error(formatError(error));
|
|
219
|
+
this.exit(1);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/commands/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACN,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,iBAAiB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EACN,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACzC,MAAM,CAAU,WAAW,GAC1B;;;;;;8CAM4C,CAAC;IAE9C,MAAM,CAAU,QAAQ,GAAG;QAC1B;YACC,OAAO,EAAE,yBAAyB;YAClC,WAAW,EAAE,qDAAqD;SAClE;QACD;YACC,OAAO,EAAE,iCAAiC;YAC1C,WAAW,EAAE,2CAA2C;SACxD;QACD;YACC,OAAO,EAAE,oDAAoD;YAC7D,WAAW,EAAE,uCAAuC;SACpD;QACD;YACC,OAAO,EAAE,mCAAmC;YAC5C,WAAW,EAAE,iCAAiC;SAC9C;QACD;YACC,OAAO,EAAE,sCAAsC;YAC/C,WAAW,EAAE,gCAAgC;SAC7C;KACD,CAAC;IAEF,MA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K,EAAE,CAAC,CAAC;gBAC/D,IAAI,WAAW,CAAC,MAAM;oBAAE,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;YAClE,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,CAAC;IACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate command - generates TypeScript types and operations from local OpenAPI spec.
|
|
3
|
+
* Auto-creates config if missing and ensures output directories exist.
|
|
4
|
+
*/
|
|
5
|
+
import { Command } from "@oclif/core";
|
|
6
|
+
/**
|
|
7
|
+
* Generate TypeScript types and operations from local OpenAPI spec.
|
|
8
|
+
*/
|
|
9
|
+
export default class Generate extends Command {
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: {
|
|
12
|
+
command: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}[];
|
|
15
|
+
static flags: {
|
|
16
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
"spec-file": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
"dry-run": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
"types-only": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
|
+
"operations-only": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
};
|
|
24
|
+
run(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAuB7C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,OAAO;IAC5C,OAAgB,WAAW,SAQqB;IAEhD,OAAgB,QAAQ;;;QAqBtB;IAEF,OAAgB,KAAK;;;;;;;;MAgCnB;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA8I1B"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate command - generates TypeScript types and operations from local OpenAPI spec.
|
|
3
|
+
* Auto-creates config if missing and ensures output directories exist.
|
|
4
|
+
*/
|
|
5
|
+
import { writeFile } from "node:fs/promises";
|
|
6
|
+
import { Command, Flags } from "@oclif/core";
|
|
7
|
+
import { ensureOutputFolders, getOutputPaths, loadConfig, resolveSpecSource, } from "../lib/config.js";
|
|
8
|
+
import { formatError, SpecNotFoundError } from "../lib/errors.js";
|
|
9
|
+
import { computeHash, hasLocalSpec, loadLocalSpec, saveCacheMetadata, } from "../lib/fetcher.js";
|
|
10
|
+
import { generate, generateClientFiles } from "../lib/generator.js";
|
|
11
|
+
import { createLogger, formatDuration, getLogLevel, logSeparator, } from "../lib/logger.js";
|
|
12
|
+
/**
|
|
13
|
+
* Generate TypeScript types and operations from local OpenAPI spec.
|
|
14
|
+
*/
|
|
15
|
+
export default class Generate extends Command {
|
|
16
|
+
static description = `Generate TypeScript types and operations from cached spec.
|
|
17
|
+
|
|
18
|
+
Uses the locally cached openapi.json (from a previous fetch).
|
|
19
|
+
Run 'fetch' first if you don't have a cached spec.
|
|
20
|
+
|
|
21
|
+
Generates:
|
|
22
|
+
- api.types.ts - TypeScript types from OpenAPI schemas
|
|
23
|
+
- api.operations.ts - Typed operation functions`;
|
|
24
|
+
static examples = [
|
|
25
|
+
{
|
|
26
|
+
command: "<%= config.bin %> generate",
|
|
27
|
+
description: "Regenerate from cached spec",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
command: "<%= config.bin %> generate --dry-run",
|
|
31
|
+
description: "Preview what would be generated",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
command: "<%= config.bin %> generate --types-only",
|
|
35
|
+
description: "Generate only api.types.ts",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
command: "<%= config.bin %> generate --operations-only",
|
|
39
|
+
description: "Generate only api.operations.ts",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
command: "<%= config.bin %> generate --spec-file ./openapi.json",
|
|
43
|
+
description: "Generate from specific local file",
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
static flags = {
|
|
47
|
+
config: Flags.string({
|
|
48
|
+
char: "c",
|
|
49
|
+
description: "Path to api.config.toml",
|
|
50
|
+
}),
|
|
51
|
+
"spec-file": Flags.string({
|
|
52
|
+
char: "s",
|
|
53
|
+
description: "Use local spec file (copies to cache before generating)",
|
|
54
|
+
}),
|
|
55
|
+
"dry-run": Flags.boolean({
|
|
56
|
+
char: "n",
|
|
57
|
+
description: "Show what would be generated without writing files",
|
|
58
|
+
default: false,
|
|
59
|
+
}),
|
|
60
|
+
"types-only": Flags.boolean({
|
|
61
|
+
description: "Generate only TypeScript types (skip operations)",
|
|
62
|
+
default: false,
|
|
63
|
+
}),
|
|
64
|
+
"operations-only": Flags.boolean({
|
|
65
|
+
description: "Generate only operations (skip types)",
|
|
66
|
+
default: false,
|
|
67
|
+
}),
|
|
68
|
+
quiet: Flags.boolean({
|
|
69
|
+
char: "q",
|
|
70
|
+
description: "Suppress non-error output",
|
|
71
|
+
default: false,
|
|
72
|
+
}),
|
|
73
|
+
verbose: Flags.boolean({
|
|
74
|
+
char: "v",
|
|
75
|
+
description: "Show detailed output",
|
|
76
|
+
default: false,
|
|
77
|
+
}),
|
|
78
|
+
};
|
|
79
|
+
async run() {
|
|
80
|
+
const { flags } = await this.parse(Generate);
|
|
81
|
+
// Create logger with appropriate level
|
|
82
|
+
const logger = createLogger({
|
|
83
|
+
level: getLogLevel(flags),
|
|
84
|
+
});
|
|
85
|
+
logSeparator(logger, "chowbea-axios generate");
|
|
86
|
+
try {
|
|
87
|
+
// Load configuration (auto-creates if missing)
|
|
88
|
+
logger.info("Loading configuration...");
|
|
89
|
+
const { config, projectRoot, configPath, wasCreated } = await loadConfig(flags.config);
|
|
90
|
+
if (wasCreated) {
|
|
91
|
+
logger.warn({ configPath }, "Created default api.config.toml - please review and update settings");
|
|
92
|
+
}
|
|
93
|
+
// Get output paths
|
|
94
|
+
const outputPaths = getOutputPaths(config, projectRoot);
|
|
95
|
+
logger.debug({ outputPaths }, "Resolved output paths");
|
|
96
|
+
// Ensure output folders exist (_internal, _generated)
|
|
97
|
+
await ensureOutputFolders(outputPaths);
|
|
98
|
+
logger.debug({ folder: outputPaths.folder }, "Output folders ready");
|
|
99
|
+
// Handle --spec-file flag: copy local spec to cache location
|
|
100
|
+
const specFile = flags["spec-file"];
|
|
101
|
+
if (specFile) {
|
|
102
|
+
const specSource = resolveSpecSource(config, projectRoot, specFile);
|
|
103
|
+
if (specSource.type === "local") {
|
|
104
|
+
logger.info({ specFile: specSource.path }, "Loading local spec file...");
|
|
105
|
+
// Load and validate the spec
|
|
106
|
+
const { buffer } = await loadLocalSpec(specSource.path);
|
|
107
|
+
const hash = computeHash(buffer);
|
|
108
|
+
// Copy to cache location
|
|
109
|
+
await writeFile(outputPaths.spec, buffer);
|
|
110
|
+
await saveCacheMetadata(outputPaths.cache, {
|
|
111
|
+
hash,
|
|
112
|
+
timestamp: Date.now(),
|
|
113
|
+
endpoint: specSource.path,
|
|
114
|
+
});
|
|
115
|
+
logger.info({ bytes: buffer.length, hash: hash.slice(0, 8) }, "Spec copied to cache");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Check if local spec exists
|
|
119
|
+
const specExists = await hasLocalSpec(outputPaths.spec);
|
|
120
|
+
if (!specExists) {
|
|
121
|
+
throw new SpecNotFoundError(outputPaths.spec);
|
|
122
|
+
}
|
|
123
|
+
// Generate client files if they don't exist
|
|
124
|
+
const clientFiles = await generateClientFiles({
|
|
125
|
+
paths: outputPaths,
|
|
126
|
+
instanceConfig: config.instance,
|
|
127
|
+
logger,
|
|
128
|
+
});
|
|
129
|
+
// Validate flag combination
|
|
130
|
+
if (flags["types-only"] && flags["operations-only"]) {
|
|
131
|
+
logger.error("Cannot use --types-only and --operations-only together");
|
|
132
|
+
this.exit(1);
|
|
133
|
+
}
|
|
134
|
+
// Run generation
|
|
135
|
+
logger.info("Starting type and operation generation...");
|
|
136
|
+
const result = await generate({
|
|
137
|
+
paths: outputPaths,
|
|
138
|
+
logger,
|
|
139
|
+
dryRun: flags["dry-run"],
|
|
140
|
+
skipTypes: flags["operations-only"],
|
|
141
|
+
skipOperations: flags["types-only"],
|
|
142
|
+
});
|
|
143
|
+
// Handle dry-run output
|
|
144
|
+
if (flags["dry-run"] && result.dryRunResult) {
|
|
145
|
+
logSeparator(logger);
|
|
146
|
+
logger.info("Dry run complete - no files written");
|
|
147
|
+
logger.info({ operations: result.dryRunResult.operationCount }, "Operations found");
|
|
148
|
+
for (const file of result.dryRunResult.files) {
|
|
149
|
+
const info = file.lines > 0 ? ` (${file.lines} lines)` : " (types)";
|
|
150
|
+
logger.info(`Would ${file.action}: ${file.path}${info}`);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// Report success
|
|
155
|
+
logSeparator(logger);
|
|
156
|
+
logger.info({
|
|
157
|
+
operations: result.operationCount,
|
|
158
|
+
duration: formatDuration(result.durationMs),
|
|
159
|
+
}, "Generation completed successfully");
|
|
160
|
+
if (result.typesGenerated) {
|
|
161
|
+
logger.info({ types: outputPaths.types }, "Types output");
|
|
162
|
+
}
|
|
163
|
+
if (result.operationsGenerated) {
|
|
164
|
+
logger.info({ operations: outputPaths.operations }, "Operations output");
|
|
165
|
+
}
|
|
166
|
+
if (clientFiles.helpers ||
|
|
167
|
+
clientFiles.instance ||
|
|
168
|
+
clientFiles.error ||
|
|
169
|
+
clientFiles.client) {
|
|
170
|
+
logger.info("Client files created:");
|
|
171
|
+
if (clientFiles.helpers)
|
|
172
|
+
logger.info(` - ${outputPaths.helpers}`);
|
|
173
|
+
if (clientFiles.instance)
|
|
174
|
+
logger.info(` - ${outputPaths.instance}`);
|
|
175
|
+
if (clientFiles.error)
|
|
176
|
+
logger.info(` - ${outputPaths.error}`);
|
|
177
|
+
if (clientFiles.client)
|
|
178
|
+
logger.info(` - ${outputPaths.client}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
logger.error(formatError(error));
|
|
183
|
+
this.exit(1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACN,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,iBAAiB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EACN,WAAW,EACX,YAAY,EACZ,aAAa,EACb,iBAAiB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EACN,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,QA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,EAAE,cAAc,CAAC,CAAC;YAC3D,CAAC;YACD,IAAI,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAChC,MAAM,CAAC,IAAI,CACV,EAAE,UAAU,EAAE,WAAW,CAAC,UAAU,EAAE,EACtC,mBAAmB,CACnB,CAAC;YACH,CAAC;YAED,IACC,WAAW,CAAC,OAAO;gBACnB,WAAW,CAAC,QAAQ;gBACpB,WAAW,CAAC,KAAK;gBACjB,WAAW,CAAC,MAAM,EACjB,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;gBACrC,IAAI,WAAW,CAAC,OAAO;oBAAE,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnE,IAAI,WAAW,CAAC,QAAQ;oBAAE,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;gBACrE,IAAI,WAAW,CAAC,KAAK;oBAAE,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;gBAC/D,IAAI,WAAW,CAAC,MAAM;oBAAE,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;YAClE,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,CAAC;IACF,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init command - full project setup for chowbea-axios.
|
|
3
|
+
* Creates config, adds workspace entry, adds npm scripts, generates client files,
|
|
4
|
+
* installs dependencies, builds CLI, and runs initial fetch.
|
|
5
|
+
*/
|
|
6
|
+
import { Command } from "@oclif/core";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize chowbea-axios in a project.
|
|
9
|
+
* Creates config, workspace file, and npm scripts.
|
|
10
|
+
*/
|
|
11
|
+
export default class Init extends Command {
|
|
12
|
+
static description: string;
|
|
13
|
+
static examples: {
|
|
14
|
+
command: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}[];
|
|
17
|
+
static flags: {
|
|
18
|
+
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
"skip-scripts": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
|
+
"skip-workspace": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
"skip-client": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
"skip-concurrent": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
"base-url-env": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
|
+
"token-key": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
25
|
+
"with-credentials": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
26
|
+
timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
27
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
28
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
29
|
+
};
|
|
30
|
+
run(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Detects existing setup files to notify user.
|
|
33
|
+
* Does NOT auto-create any files - only checks what exists.
|
|
34
|
+
*/
|
|
35
|
+
private detectExistingSetup;
|
|
36
|
+
/**
|
|
37
|
+
* Ensures openapi-typescript is installed as a dev dependency.
|
|
38
|
+
*/
|
|
39
|
+
private ensureOpenApiTypescript;
|
|
40
|
+
/**
|
|
41
|
+
* Runs pnpm install to link workspaces.
|
|
42
|
+
*/
|
|
43
|
+
private runPnpmInstall;
|
|
44
|
+
/**
|
|
45
|
+
* Builds the CLI.
|
|
46
|
+
*/
|
|
47
|
+
private buildCli;
|
|
48
|
+
/**
|
|
49
|
+
* Runs initial fetch to download spec and generate types.
|
|
50
|
+
*/
|
|
51
|
+
private runInitialFetch;
|
|
52
|
+
/**
|
|
53
|
+
* Creates api.config.toml if it doesn't exist or if user confirms overwrite.
|
|
54
|
+
*/
|
|
55
|
+
private setupConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Generates api.config.toml content with instance settings.
|
|
58
|
+
*/
|
|
59
|
+
private generateConfigContent;
|
|
60
|
+
/**
|
|
61
|
+
* Creates or updates pnpm-workspace.yaml to include cli/*.
|
|
62
|
+
*/
|
|
63
|
+
private setupWorkspace;
|
|
64
|
+
/**
|
|
65
|
+
* Adds cli/* to an existing pnpm-workspace.yaml content.
|
|
66
|
+
* Handles various YAML formats including comments and different indentation.
|
|
67
|
+
*/
|
|
68
|
+
private addCliToWorkspace;
|
|
69
|
+
/**
|
|
70
|
+
* Adds npm scripts to package.json.
|
|
71
|
+
*/
|
|
72
|
+
private setupScripts;
|
|
73
|
+
/**
|
|
74
|
+
* Generates client files (api.instance.ts, api.error.ts, api.client.ts).
|
|
75
|
+
*/
|
|
76
|
+
private setupClientFiles;
|
|
77
|
+
/**
|
|
78
|
+
* Detects the package manager based on lockfile presence.
|
|
79
|
+
* Returns 'pnpm', 'yarn', 'bun', or 'npm'.
|
|
80
|
+
*/
|
|
81
|
+
private detectPackageManager;
|
|
82
|
+
/**
|
|
83
|
+
* Sets up a concurrent watch script combining api:watch with user-selected dev scripts.
|
|
84
|
+
* Uses concurrently to run multiple scripts in parallel with labeled output.
|
|
85
|
+
*/
|
|
86
|
+
private setupConcurrentlyScript;
|
|
87
|
+
/**
|
|
88
|
+
* Ensures concurrently is installed as a dev dependency.
|
|
89
|
+
*/
|
|
90
|
+
private ensureConcurrently;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAuC7C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAYyB;IAEpD,OAAgB,QAAQ;;;QAatB;IAEF,OAAgB,KAAK;;;;;;;;;;;;MAkDnB;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAgH1B;;;OAGG;YACW,mBAAmB;IA6CjC;;OAEG;YACW,uBAAuB;IA+BrC;;OAEG;YACW,cAAc;IAkB5B;;OAEG;YACW,QAAQ;IAkBtB;;OAEG;YACW,eAAe;IAsB7B;;OAEG;YACW,WAAW;IAqCzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAsC7B;;OAEG;YACW,cAAc;IAoD5B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IA8DzB;;OAEG;YACW,YAAY;IAsF1B;;OAEG;YACW,gBAAgB;IAkC9B;;;OAGG;YACW,oBAAoB;IAoClC;;;OAGG;YACW,uBAAuB;IAiGrC;;OAEG;YACW,kBAAkB;CAkDhC"}
|