swagger-sdk-generator 0.0.0-stage → 3.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/README.md +58 -2
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.js +196 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +130 -0
- package/dist/cli/commands/inspect.d.ts +2 -0
- package/dist/cli/commands/inspect.js +164 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +126 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/context.js +85 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.js +82 -0
- package/dist/config/interpolate.d.ts +8 -0
- package/dist/config/interpolate.js +85 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +182 -0
- package/dist/config/migrate-v3.d.ts +5 -0
- package/dist/config/migrate-v3.js +6 -0
- package/dist/config/mode-compatibility.d.ts +9 -0
- package/dist/config/mode-compatibility.js +17 -0
- package/dist/config/modes.d.ts +13 -0
- package/dist/config/modes.js +27 -0
- package/dist/config/preset-definitions.d.ts +2 -0
- package/dist/config/preset-definitions.js +4 -0
- package/dist/config/presets.d.ts +25 -0
- package/dist/config/presets.js +36 -0
- package/dist/config/resolve.d.ts +32 -0
- package/dist/config/resolve.js +288 -0
- package/dist/config/schema.d.ts +93 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/types.d.ts +42 -0
- package/dist/config/types.js +2 -0
- package/dist/config/workspace.d.ts +30 -0
- package/dist/config/workspace.js +95 -0
- package/dist/core/case-align.d.ts +5 -0
- package/dist/core/case-align.js +90 -0
- package/dist/core/deep-merge.d.ts +2 -0
- package/dist/core/deep-merge.js +21 -0
- package/dist/core/file-set.d.ts +10 -0
- package/dist/core/file-set.js +31 -0
- package/dist/core/import-module.d.ts +1 -0
- package/dist/core/import-module.js +61 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +24 -0
- package/dist/core/manifest.d.ts +17 -0
- package/dist/core/manifest.js +195 -0
- package/dist/core/overlaps.d.ts +6 -0
- package/dist/core/overlaps.js +67 -0
- package/dist/core/package-version.d.ts +1 -0
- package/dist/core/package-version.js +44 -0
- package/dist/core/pipeline.d.ts +30 -0
- package/dist/core/pipeline.js +335 -0
- package/dist/core/plugin.d.ts +72 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/targets.d.ts +14 -0
- package/dist/core/targets.js +120 -0
- package/dist/core/unmanaged.d.ts +3 -0
- package/dist/core/unmanaged.js +101 -0
- package/dist/core/writer.d.ts +28 -0
- package/dist/core/writer.js +148 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +37 -0
- package/dist/ir/casing.d.ts +5 -0
- package/dist/ir/casing.js +22 -0
- package/dist/ir/graph.d.ts +8 -0
- package/dist/ir/graph.js +95 -0
- package/dist/ir/operations/grouping.d.ts +17 -0
- package/dist/ir/operations/grouping.js +39 -0
- package/dist/ir/operations/legacy-naming.d.ts +2 -0
- package/dist/ir/operations/legacy-naming.js +8 -0
- package/dist/ir/operations/naming.d.ts +6 -0
- package/dist/ir/operations/naming.js +54 -0
- package/dist/ir/option-errors.d.ts +3 -0
- package/dist/ir/option-errors.js +68 -0
- package/dist/ir/transforms/builtins.d.ts +2 -0
- package/dist/ir/transforms/builtins.js +4 -0
- package/dist/ir/transforms/index.d.ts +10 -0
- package/dist/ir/transforms/index.js +39 -0
- package/dist/ir/transforms/types.d.ts +9 -0
- package/dist/ir/transforms/types.js +2 -0
- package/dist/ir/types.d.ts +140 -0
- package/dist/ir/types.js +2 -0
- package/dist/runtime/axios.d.ts +28 -0
- package/dist/runtime/axios.js +132 -0
- package/dist/runtime/fetch.d.ts +6 -0
- package/dist/runtime/fetch.js +38 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +167 -0
- package/dist/runtime/rtk.d.ts +35 -0
- package/dist/runtime/rtk.js +36 -0
- package/dist/runtime/transport.d.ts +38 -0
- package/dist/runtime/transport.js +30 -0
- package/dist/runtime/wire.d.ts +27 -0
- package/dist/runtime/wire.js +148 -0
- package/dist/spec/html-entities.d.ts +1 -0
- package/dist/spec/html-entities.js +25 -0
- package/dist/spec/load.d.ts +26 -0
- package/dist/spec/load.js +130 -0
- package/dist/spec/openapi/all-of.d.ts +3 -0
- package/dist/spec/openapi/all-of.js +9 -0
- package/dist/spec/openapi/normalize.d.ts +4 -0
- package/dist/spec/openapi/normalize.js +31 -0
- package/dist/spec/openapi/operations.d.ts +4 -0
- package/dist/spec/openapi/operations.js +173 -0
- package/dist/spec/openapi/schema.d.ts +51 -0
- package/dist/spec/openapi/schema.js +307 -0
- package/dist/targets/declarative/config.d.ts +533 -0
- package/dist/targets/declarative/config.js +280 -0
- package/dist/targets/declarative/extensions.d.ts +45 -0
- package/dist/targets/declarative/extensions.js +123 -0
- package/dist/targets/declarative/files.d.ts +13 -0
- package/dist/targets/declarative/files.js +127 -0
- package/dist/targets/declarative/format.d.ts +4 -0
- package/dist/targets/declarative/format.js +104 -0
- package/dist/targets/declarative/index.d.ts +9 -0
- package/dist/targets/declarative/index.js +170 -0
- package/dist/targets/declarative/liquid.d.ts +8 -0
- package/dist/targets/declarative/liquid.js +57 -0
- package/dist/targets/declarative/naming-case.d.ts +3 -0
- package/dist/targets/declarative/naming-case.js +31 -0
- package/dist/targets/declarative/naming.d.ts +42 -0
- package/dist/targets/declarative/naming.js +174 -0
- package/dist/targets/declarative/scaffold.d.ts +5 -0
- package/dist/targets/declarative/scaffold.js +146 -0
- package/dist/targets/declarative/types.d.ts +52 -0
- package/dist/targets/declarative/types.js +287 -0
- package/dist/targets/declarative/views.d.ts +180 -0
- package/dist/targets/declarative/views.js +447 -0
- package/dist/targets/python/extensions.js +152 -0
- package/dist/targets/python/target.json +549 -0
- package/dist/targets/python/templates/client/client.liquid +114 -0
- package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
- package/dist/targets/python/templates/client/init.liquid +20 -0
- package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
- package/dist/targets/python/templates/client/resource.liquid +28 -0
- package/dist/targets/python/templates/client/runtime.liquid +133 -0
- package/dist/targets/python/templates/client/transport.liquid +62 -0
- package/dist/targets/python/templates/models/module.liquid +48 -0
- package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
- package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
- package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
- package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
- package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
- package/dist/targets/typescript/compatibility-naming.js +28 -0
- package/dist/targets/typescript/compatibility-options.d.ts +5 -0
- package/dist/targets/typescript/compatibility-options.js +8 -0
- package/dist/targets/typescript/compatibility-target.d.ts +5 -0
- package/dist/targets/typescript/compatibility-target.js +10 -0
- package/dist/targets/typescript/http-operations.d.ts +34 -0
- package/dist/targets/typescript/http-operations.js +155 -0
- package/dist/targets/typescript/imports.d.ts +43 -0
- package/dist/targets/typescript/imports.js +154 -0
- package/dist/targets/typescript/index.d.ts +7 -0
- package/dist/targets/typescript/index.js +52 -0
- package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
- package/dist/targets/typescript/mock-compatibility.js +6 -0
- package/dist/targets/typescript/mock-hints.d.ts +13 -0
- package/dist/targets/typescript/mock-hints.js +75 -0
- package/dist/targets/typescript/mock-reachability.d.ts +12 -0
- package/dist/targets/typescript/mock-reachability.js +87 -0
- package/dist/targets/typescript/model-compatibility.d.ts +14 -0
- package/dist/targets/typescript/model-compatibility.js +16 -0
- package/dist/targets/typescript/naming.d.ts +13 -0
- package/dist/targets/typescript/naming.js +50 -0
- package/dist/targets/typescript/options.d.ts +124 -0
- package/dist/targets/typescript/options.js +90 -0
- package/dist/targets/typescript/outputs/client.d.ts +67 -0
- package/dist/targets/typescript/outputs/client.js +187 -0
- package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
- package/dist/targets/typescript/outputs/mocks.js +371 -0
- package/dist/targets/typescript/outputs/models.d.ts +85 -0
- package/dist/targets/typescript/outputs/models.js +246 -0
- package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
- package/dist/targets/typescript/outputs/rtk-query.js +266 -0
- package/dist/targets/typescript/prettier.d.ts +7 -0
- package/dist/targets/typescript/prettier.js +44 -0
- package/dist/targets/typescript/templates/client/client.liquid +30 -0
- package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
- package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
- package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
- package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
- package/dist/targets/typescript/templates/client/resource.liquid +34 -0
- package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
- package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
- package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/models/alias.liquid +16 -0
- package/dist/targets/typescript/templates/models/enum.liquid +27 -0
- package/dist/targets/typescript/templates/models/index.liquid +14 -0
- package/dist/targets/typescript/templates/models/model.liquid +25 -0
- package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
- package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
- package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
- package/dist/targets/typescript/ts-type.d.ts +70 -0
- package/dist/targets/typescript/ts-type.js +62 -0
- package/dist/targets/typescript/type-printer.d.ts +21 -0
- package/dist/targets/typescript/type-printer.js +115 -0
- package/dist/templates/engine.d.ts +20 -0
- package/dist/templates/engine.js +161 -0
- package/dist/templates/inspect.d.ts +27 -0
- package/dist/templates/inspect.js +331 -0
- package/package.json +65 -4
- package/schema/sdk-gen.local.schema.json +75 -0
- package/schema/sdk-gen.schema.json +980 -0
- package/schema/sdk-gen.target.schema.json +1384 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.registerTemplates = registerTemplates;
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const log_1 = require("../../core/log");
|
|
49
|
+
const targets_1 = require("../../core/targets");
|
|
50
|
+
const engine_1 = require("../../templates/engine");
|
|
51
|
+
const inspect_1 = require("../../templates/inspect");
|
|
52
|
+
const context_1 = require("../context");
|
|
53
|
+
function registerTemplates(program) {
|
|
54
|
+
const cmd = program
|
|
55
|
+
.command('templates')
|
|
56
|
+
.description('Explore and customize templates (what slots into what, eject for override)');
|
|
57
|
+
const withCommon = (c) => c
|
|
58
|
+
.option('-c, --config <file>', 'config file (default: discovered in cwd)')
|
|
59
|
+
.option('--target <name>', 'target: built-in name or a config target dir (default: from config, else typescript)')
|
|
60
|
+
.option('-t, --templates <dirs...>', 'override dirs (default: from config)');
|
|
61
|
+
withCommon(cmd.command('tree [name]'))
|
|
62
|
+
.description('Print the composition tree of entry templates (or of one template)')
|
|
63
|
+
.action((name, flags) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const infos = yield load(flags);
|
|
65
|
+
if (name && !infos.some((i) => i.name === name))
|
|
66
|
+
(0, context_1.fail)(`No template "${name}". Try \`sdk-gen templates list\`.`);
|
|
67
|
+
console.log((0, inspect_1.renderTemplateTree)(infos, { root: name }));
|
|
68
|
+
}));
|
|
69
|
+
withCommon(cmd.command('list'))
|
|
70
|
+
.description('List every template with its layer and description')
|
|
71
|
+
.action((flags) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
var _a;
|
|
73
|
+
for (const info of yield load(flags)) {
|
|
74
|
+
const layer = info.shadowsBuiltin ? 'override*' : info.layer;
|
|
75
|
+
console.log(`${info.name.padEnd(44)} ${layer.padEnd(9)} ${(_a = info.description) !== null && _a !== void 0 ? _a : ''}`.trimEnd());
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
withCommon(cmd.command('eject <names...>'))
|
|
79
|
+
.description('Copy built-in template(s) into an override dir to customize them (a name may be a folder, e.g. "stores")')
|
|
80
|
+
.option('--to <dir>', 'destination override dir (default: first configured templates dir, else ./sdk-templates)')
|
|
81
|
+
.option('--force', 'overwrite existing files')
|
|
82
|
+
.action((names, flags) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const log = (0, log_1.createLogger)();
|
|
85
|
+
const { builtinDir, overrideDirs, fallbackDirs } = yield locate(flags);
|
|
86
|
+
const dest = path.resolve((_b = (_a = flags.to) !== null && _a !== void 0 ? _a : overrideDirs[0]) !== null && _b !== void 0 ? _b : 'sdk-templates');
|
|
87
|
+
const builtin = (0, inspect_1.inspectTemplates)({ builtinDir, fallbackDirs });
|
|
88
|
+
for (const name of names) {
|
|
89
|
+
const matches = builtin.filter((t) => t.name === name || t.name.startsWith(`${name.replace(/\/$/, '')}/`));
|
|
90
|
+
if (!matches.length)
|
|
91
|
+
(0, context_1.fail)(`No built-in template "${name}".`);
|
|
92
|
+
for (const t of matches) {
|
|
93
|
+
const out = path.join(dest, ...`${t.name}${engine_1.TEMPLATE_EXT}`.split('/'));
|
|
94
|
+
if (fs.existsSync(out) && !flags.force) {
|
|
95
|
+
log.warn(`skip ${path.relative(process.cwd(), out)} (exists; --force to overwrite)`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
99
|
+
fs.copyFileSync(t.file, out);
|
|
100
|
+
log.info(`ejected ${t.name} → ${path.relative(process.cwd(), out)}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
log.info(`\nTip: to change one section only, replace the file body with\n {% layout '@builtin/<name>' %}{% block <block> %}…{% endblock %}`);
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
function locate(flags) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
var _a, _b, _c, _d, _e, _f;
|
|
109
|
+
const project = yield (0, context_1.loadProject)((0, log_1.createLogger)('error'), flags.config);
|
|
110
|
+
const baseDir = (_a = project === null || project === void 0 ? void 0 : project.baseDir) !== null && _a !== void 0 ? _a : process.cwd();
|
|
111
|
+
const configured = project === null || project === void 0 ? void 0 : project.config.templates;
|
|
112
|
+
const overrideDirs = ((_b = flags.templates) !== null && _b !== void 0 ? _b : (configured === undefined ? [] : Array.isArray(configured) ? configured : [configured])).map((d) => path.resolve(baseDir, d));
|
|
113
|
+
const target = yield (0, targets_1.loadTarget)({
|
|
114
|
+
target: (_d = (_c = flags.target) !== null && _c !== void 0 ? _c : project === null || project === void 0 ? void 0 : project.config.target) !== null && _d !== void 0 ? _d : 'typescript',
|
|
115
|
+
targetOptions: { prettier: false, biome: false },
|
|
116
|
+
plugins: ((_e = project === null || project === void 0 ? void 0 : project.config.plugins) !== null && _e !== void 0 ? _e : []).map((p) => path.resolve(baseDir, p)),
|
|
117
|
+
cwd: baseDir,
|
|
118
|
+
});
|
|
119
|
+
return { builtinDir: target.templatesDir, overrideDirs, fallbackDirs: (_f = target.templateFallbackDirs) !== null && _f !== void 0 ? _f : [] };
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function load(flags) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
return (0, inspect_1.inspectTemplates)(yield locate(flags));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UserConfig } from '../config/schema';
|
|
2
|
+
import type { Logger } from '../core/log';
|
|
3
|
+
export interface LoadedProject {
|
|
4
|
+
config: UserConfig;
|
|
5
|
+
baseDir: string;
|
|
6
|
+
file?: string;
|
|
7
|
+
localFile?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function loadProject(log: Logger, explicitPath?: string): Promise<LoadedProject | undefined>;
|
|
10
|
+
export declare function fail(message: string): never;
|
|
11
|
+
export declare class CliError extends Error {
|
|
12
|
+
}
|
|
13
|
+
export declare function terminalPrompt(): {
|
|
14
|
+
ask: (question: string) => Promise<string>;
|
|
15
|
+
isInteractive: boolean;
|
|
16
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.CliError = void 0;
|
|
46
|
+
exports.loadProject = loadProject;
|
|
47
|
+
exports.fail = fail;
|
|
48
|
+
exports.terminalPrompt = terminalPrompt;
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const readline = __importStar(require("readline"));
|
|
51
|
+
const load_1 = require("../config/load");
|
|
52
|
+
function loadProject(log, explicitPath) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const cwd = process.cwd();
|
|
55
|
+
const loaded = yield (0, load_1.loadConfigFile)(cwd, explicitPath);
|
|
56
|
+
if (!loaded)
|
|
57
|
+
return undefined;
|
|
58
|
+
for (const warning of loaded.warnings)
|
|
59
|
+
log.warn(`⚠️ ${warning}`);
|
|
60
|
+
return {
|
|
61
|
+
config: loaded.config,
|
|
62
|
+
baseDir: loaded.file ? path.dirname(loaded.file) : cwd,
|
|
63
|
+
file: loaded.file,
|
|
64
|
+
localFile: loaded.localFile,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function fail(message) {
|
|
69
|
+
throw new CliError(message);
|
|
70
|
+
}
|
|
71
|
+
class CliError extends Error {
|
|
72
|
+
}
|
|
73
|
+
exports.CliError = CliError;
|
|
74
|
+
function terminalPrompt() {
|
|
75
|
+
return {
|
|
76
|
+
isInteractive: Boolean(process.stdin.isTTY),
|
|
77
|
+
ask: (question) => new Promise((resolve) => {
|
|
78
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
79
|
+
rl.question(question, (answer) => {
|
|
80
|
+
rl.close();
|
|
81
|
+
resolve(answer);
|
|
82
|
+
});
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const package_version_1 = require("../core/package-version");
|
|
6
|
+
const generate_1 = require("./commands/generate");
|
|
7
|
+
const init_1 = require("./commands/init");
|
|
8
|
+
const inspect_1 = require("./commands/inspect");
|
|
9
|
+
const templates_1 = require("./commands/templates");
|
|
10
|
+
const context_1 = require("./context");
|
|
11
|
+
const program = new commander_1.Command()
|
|
12
|
+
.name('sdk-gen')
|
|
13
|
+
.description('Generate SDKs from OpenAPI specs')
|
|
14
|
+
.version((0, package_version_1.getPackageVersion)());
|
|
15
|
+
(0, generate_1.registerGenerate)(program);
|
|
16
|
+
(0, templates_1.registerTemplates)(program);
|
|
17
|
+
(0, inspect_1.registerInspect)(program);
|
|
18
|
+
(0, init_1.registerInit)(program);
|
|
19
|
+
program.parseAsync(process.argv).catch((error) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const debug = Boolean(process.env.SDK_GEN_DEBUG) && !(error instanceof context_1.CliError);
|
|
22
|
+
const message = error instanceof Error ? (debug ? (_a = error.stack) !== null && _a !== void 0 ? _a : error.message : error.message) : String(error);
|
|
23
|
+
console.error(`❌ ${message}`);
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.parseDotenv = parseDotenv;
|
|
37
|
+
exports.loadEnvFiles = loadEnvFiles;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
function parseDotenv(text) {
|
|
41
|
+
const out = {};
|
|
42
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
43
|
+
const line = rawLine.trim();
|
|
44
|
+
if (!line || line.startsWith('#'))
|
|
45
|
+
continue;
|
|
46
|
+
const match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.*)$/.exec(line);
|
|
47
|
+
if (!match)
|
|
48
|
+
continue;
|
|
49
|
+
const [, key, rest] = match;
|
|
50
|
+
out[key] = parseValue(rest);
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function parseValue(raw) {
|
|
55
|
+
const value = raw.trim();
|
|
56
|
+
const quote = value[0];
|
|
57
|
+
if (quote === '"' || quote === "'") {
|
|
58
|
+
const end = value.indexOf(quote, 1);
|
|
59
|
+
if (end !== -1)
|
|
60
|
+
return value.slice(1, end);
|
|
61
|
+
}
|
|
62
|
+
const comment = value.search(/\s#/);
|
|
63
|
+
return (comment === -1 ? value : value.slice(0, comment)).trim();
|
|
64
|
+
}
|
|
65
|
+
function loadEnvFiles(files, dir) {
|
|
66
|
+
const list = files === undefined ? [] : Array.isArray(files) ? files : [files];
|
|
67
|
+
const out = {};
|
|
68
|
+
for (const file of list) {
|
|
69
|
+
const abs = path.isAbsolute(file) ? file : path.resolve(dir, file);
|
|
70
|
+
let text;
|
|
71
|
+
try {
|
|
72
|
+
text = fs.readFileSync(abs, 'utf8');
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error.code === 'ENOENT')
|
|
76
|
+
continue;
|
|
77
|
+
throw new Error(`Failed to read envFile ${abs}: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
Object.assign(out, parseDotenv(text));
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Env = Record<string, string | undefined>;
|
|
2
|
+
export declare function resolveWorkspace(cli?: string, configured?: string, env?: Env): string;
|
|
3
|
+
export declare function interpolateString(input: string, opts?: {
|
|
4
|
+
workspace?: () => string;
|
|
5
|
+
host?: () => string;
|
|
6
|
+
env?: Env;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function interpolateEnv(input: string, env: Env): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveWorkspace = resolveWorkspace;
|
|
4
|
+
exports.interpolateString = interpolateString;
|
|
5
|
+
exports.interpolateEnv = interpolateEnv;
|
|
6
|
+
function resolveWorkspace(cli, configured, env = process.env) {
|
|
7
|
+
if (cli)
|
|
8
|
+
return cli;
|
|
9
|
+
if (configured)
|
|
10
|
+
return configured;
|
|
11
|
+
if (env.SDK_WORKSPACE)
|
|
12
|
+
return env.SDK_WORKSPACE;
|
|
13
|
+
throw new Error('Workspace could not be resolved: no workspace was provided. ' +
|
|
14
|
+
'Set it via the --workspace <name> CLI option, "workspace" in your <config>.local.json (sdk-gen init --local), or the SDK_WORKSPACE environment variable.');
|
|
15
|
+
}
|
|
16
|
+
function interpolateString(input, opts = {}) {
|
|
17
|
+
var _a;
|
|
18
|
+
let result = input;
|
|
19
|
+
if (result.includes('{host}')) {
|
|
20
|
+
if (!opts.host) {
|
|
21
|
+
throw new Error('Placeholder "{host}" found in configuration but no "hosts" are configured.');
|
|
22
|
+
}
|
|
23
|
+
const host = opts.host();
|
|
24
|
+
if (/^https?:\/\//i.test(host)) {
|
|
25
|
+
result = result.replace(/https?:\/\/\{host\}/gi, host).split('{host}').join(host.replace(/^https?:\/\//i, ''));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
result = result.split('{host}').join(host);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (result.includes('{workspace}')) {
|
|
32
|
+
if (!opts.workspace) {
|
|
33
|
+
throw new Error('Workspace placeholder "{workspace}" found in configuration but no workspace was resolved. ' +
|
|
34
|
+
'Set it via the --workspace <name> CLI option, config workspace, or the SDK_WORKSPACE environment variable.');
|
|
35
|
+
}
|
|
36
|
+
result = result.split('{workspace}').join(opts.workspace());
|
|
37
|
+
}
|
|
38
|
+
return interpolateEnv(result, (_a = opts.env) !== null && _a !== void 0 ? _a : process.env);
|
|
39
|
+
}
|
|
40
|
+
function interpolateEnv(input, env) {
|
|
41
|
+
let out = '';
|
|
42
|
+
let i = 0;
|
|
43
|
+
while (i < input.length) {
|
|
44
|
+
const start = input.indexOf('${', i);
|
|
45
|
+
if (start === -1) {
|
|
46
|
+
out += input.slice(i);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
out += input.slice(i, start);
|
|
50
|
+
const end = matchingBrace(input, start + 2);
|
|
51
|
+
if (end === -1) {
|
|
52
|
+
out += input.slice(start);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
out += expand(input.slice(start + 2, end), env);
|
|
56
|
+
i = end + 1;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function expand(body, env) {
|
|
61
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)(?::-([\s\S]*))?$/.exec(body);
|
|
62
|
+
if (!match)
|
|
63
|
+
return `\${${body}}`;
|
|
64
|
+
const [, name, fallback] = match;
|
|
65
|
+
const value = env[name];
|
|
66
|
+
if (fallback !== undefined)
|
|
67
|
+
return value ? value : interpolateEnv(fallback, env);
|
|
68
|
+
if (value === undefined) {
|
|
69
|
+
throw new Error(`Environment variable "${name}" referenced as "\${${name}}" in configuration is not set.`);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function matchingBrace(input, from) {
|
|
74
|
+
let depth = 1;
|
|
75
|
+
for (let i = from; i < input.length; i++) {
|
|
76
|
+
if (input.startsWith('${', i)) {
|
|
77
|
+
depth++;
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
else if (input[i] === '}' && --depth === 0) {
|
|
81
|
+
return i;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LocalConfig, UserConfig } from './schema';
|
|
2
|
+
export interface LoadedConfigFile {
|
|
3
|
+
config: UserConfig;
|
|
4
|
+
file?: string;
|
|
5
|
+
localFile?: string;
|
|
6
|
+
warnings: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function loadConfigFile(cwd: string, explicitPath?: string): Promise<LoadedConfigFile | undefined>;
|
|
9
|
+
export declare function localConfigPath(configFile: string): string;
|
|
10
|
+
export declare function applyLocalConfig(config: UserConfig, local: LocalConfig, localFile?: string): UserConfig;
|
|
11
|
+
export declare function findConfigFile(cwd: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.loadConfigFile = loadConfigFile;
|
|
46
|
+
exports.localConfigPath = localConfigPath;
|
|
47
|
+
exports.applyLocalConfig = applyLocalConfig;
|
|
48
|
+
exports.findConfigFile = findConfigFile;
|
|
49
|
+
const fs = __importStar(require("fs/promises"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const import_module_1 = require("../core/import-module");
|
|
52
|
+
const schema_1 = require("./schema");
|
|
53
|
+
const migrate_v3_1 = require("./migrate-v3");
|
|
54
|
+
const presets_1 = require("./presets");
|
|
55
|
+
const CONFIG_FILES = [
|
|
56
|
+
'sdk-gen.config.js',
|
|
57
|
+
'sdk-gen.config.cjs',
|
|
58
|
+
'sdk-gen.config.mjs',
|
|
59
|
+
'sdk-gen.config.json',
|
|
60
|
+
'.sdk-gen.json',
|
|
61
|
+
'.sdk-gen.js',
|
|
62
|
+
];
|
|
63
|
+
function loadConfigFile(cwd, explicitPath) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const file = explicitPath ? path.resolve(cwd, explicitPath) : yield findConfigFile(cwd);
|
|
66
|
+
if (!file)
|
|
67
|
+
return undefined;
|
|
68
|
+
if (explicitPath && !(yield exists(file))) {
|
|
69
|
+
throw new Error(`Config file not found: ${file}`);
|
|
70
|
+
}
|
|
71
|
+
const raw = yield readConfigModule(file);
|
|
72
|
+
const { config: parsed, warnings } = isV4(raw)
|
|
73
|
+
? { config: parseWithFile(raw, file), warnings: [] }
|
|
74
|
+
: (() => {
|
|
75
|
+
const migrated = (0, migrate_v3_1.migrateV3)(raw);
|
|
76
|
+
return { config: parseWithFile(migrated.config, file), warnings: migrated.warnings };
|
|
77
|
+
})();
|
|
78
|
+
const config = (0, presets_1.applyPresetBase)(parsed);
|
|
79
|
+
const localFile = localConfigPath(file);
|
|
80
|
+
if (!(yield exists(localFile)))
|
|
81
|
+
return { config, file, warnings };
|
|
82
|
+
const local = yield readLocalConfig(localFile);
|
|
83
|
+
return { config: applyLocalConfig(config, local, localFile), file, localFile, warnings };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function localConfigPath(configFile) {
|
|
87
|
+
const ext = path.extname(configFile);
|
|
88
|
+
return path.join(path.dirname(configFile), `${path.basename(configFile, ext)}.local.json`);
|
|
89
|
+
}
|
|
90
|
+
function readLocalConfig(file) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
let raw;
|
|
93
|
+
try {
|
|
94
|
+
raw = JSON.parse(yield fs.readFile(file, 'utf8'));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
98
|
+
throw new Error(`Failed to parse local config ${file}: ${message}`);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return (0, schema_1.parseLocalConfig)(raw);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
105
|
+
throw new Error(`Invalid local config ${file}:\n${message}`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function applyLocalConfig(config, local, localFile = 'local config') {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const configSources = (_a = config.sources) !== null && _a !== void 0 ? _a : [];
|
|
112
|
+
const known = configSources.map((s) => s.name);
|
|
113
|
+
const unknown = Object.keys((_b = local.sources) !== null && _b !== void 0 ? _b : {}).filter((name) => !known.includes(name));
|
|
114
|
+
if (unknown.length) {
|
|
115
|
+
throw new Error(`${localFile}: unknown source(s) ${unknown.join(', ')} (configured: ${known.join(', ')})`);
|
|
116
|
+
}
|
|
117
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, config), (local.workspace ? { workspace: local.workspace } : {})), (config.env || local.env ? { env: Object.assign(Object.assign({}, config.env), local.env) } : {})), { sources: configSources.map((source) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const override = (_a = local.sources) === null || _a === void 0 ? void 0 : _a[source.name];
|
|
120
|
+
if (!override)
|
|
121
|
+
return source;
|
|
122
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, source), (override.url !== undefined ? { url: override.url } : {})), (override.file !== undefined ? { file: override.file } : {})), (override.headers ? { headers: Object.assign(Object.assign({}, source.headers), override.headers) } : {}));
|
|
123
|
+
}) });
|
|
124
|
+
}
|
|
125
|
+
function findConfigFile(cwd) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
for (const name of CONFIG_FILES) {
|
|
128
|
+
const file = path.resolve(cwd, name);
|
|
129
|
+
if (yield exists(file)) {
|
|
130
|
+
return file;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function readConfigModule(file) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
if (file.endsWith('.json')) {
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(yield fs.readFile(file, 'utf8'));
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
145
|
+
throw new Error(`Failed to parse JSON config ${file}: ${message}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (file.endsWith('.mjs')) {
|
|
149
|
+
const imported = (yield (0, import_module_1.importModule)(file));
|
|
150
|
+
return (_a = imported.default) !== null && _a !== void 0 ? _a : imported;
|
|
151
|
+
}
|
|
152
|
+
delete require.cache[require.resolve(file)];
|
|
153
|
+
const required = require(file);
|
|
154
|
+
return (_b = required.default) !== null && _b !== void 0 ? _b : required;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function parseWithFile(raw, file) {
|
|
158
|
+
try {
|
|
159
|
+
return (0, schema_1.parseUserConfig)(raw);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
163
|
+
throw new Error(`Invalid config ${file}:\n${message}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function isV4(raw) {
|
|
167
|
+
return isRecord(raw) && raw.version === 4;
|
|
168
|
+
}
|
|
169
|
+
function exists(file) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
try {
|
|
172
|
+
yield fs.access(file);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
catch (_a) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function isRecord(value) {
|
|
181
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
182
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const HAS_COMPATIBILITY_OUTPUTS: boolean;
|
|
2
|
+
export declare const COMPATIBILITY_MODES: readonly [];
|
|
3
|
+
export declare function compatibilityOutputs(): never;
|
|
4
|
+
export declare function compatibilityModeOptions(_mode: unknown): {
|
|
5
|
+
outputOptions: {};
|
|
6
|
+
normalize: undefined;
|
|
7
|
+
transforms: undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function sourceModeOptions(_mode: unknown, _sourceName: string, _sourceFolder?: string): undefined;
|