api-core-lib 12.0.38 → 12.0.40
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/cli.cjs +30 -21
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -105,9 +105,11 @@ async function runGenerator(options) {
|
|
|
105
105
|
process.exit(1);
|
|
106
106
|
}
|
|
107
107
|
console.log(import_chalk.default.green("\u2713 Environment variables loaded."));
|
|
108
|
-
|
|
108
|
+
let tempSpecPath = "";
|
|
109
|
+
let ignoreFilePath = "";
|
|
109
110
|
try {
|
|
110
111
|
console.log("\n" + import_chalk.default.blue(`Step 2: Fetching OpenAPI spec from ${specUrl}...`));
|
|
112
|
+
tempSpecPath = import_path.default.join(process.cwd(), `swagger-${Date.now()}.json`);
|
|
111
113
|
const response = await import_axios.default.get(specUrl, { timeout: 15e3 });
|
|
112
114
|
const spec = response.data;
|
|
113
115
|
if (!spec.openapi || !spec.paths) {
|
|
@@ -117,25 +119,31 @@ async function runGenerator(options) {
|
|
|
117
119
|
console.log(import_chalk.default.green(`\u2713 OpenAPI spec saved temporarily to ${tempSpecPath}`));
|
|
118
120
|
console.log("\n" + import_chalk.default.blue("Step 3: Generating organized TypeScript types..."));
|
|
119
121
|
const typesOutputPath = import_path.default.join(options.output, "types");
|
|
120
|
-
|
|
122
|
+
ignoreFilePath = import_path.default.join(process.cwd(), `.openapi-generator-ignore-${Date.now()}`);
|
|
121
123
|
const ignoreContent = `
|
|
122
|
-
#
|
|
124
|
+
# Main generator metadata
|
|
125
|
+
.openapi-generator/
|
|
126
|
+
# Documentation files
|
|
123
127
|
docs/
|
|
124
|
-
#
|
|
125
|
-
.
|
|
126
|
-
.npmignore
|
|
128
|
+
# Git helper files
|
|
129
|
+
.gitignore
|
|
127
130
|
git_push.sh
|
|
128
|
-
#
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!import_fs.default.existsSync(typesOutputPath)) {
|
|
133
|
-
import_fs.default.mkdirSync(typesOutputPath, { recursive: true });
|
|
134
|
-
}
|
|
131
|
+
# NPM helper files
|
|
132
|
+
.npmignore
|
|
133
|
+
README.md
|
|
134
|
+
`;
|
|
135
135
|
import_fs.default.writeFileSync(ignoreFilePath, ignoreContent);
|
|
136
|
-
console.log(import_chalk.default.gray("\u2713 Created .openapi-generator-ignore
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
console.log(import_chalk.default.gray("\u2713 Created temporary .openapi-generator-ignore file."));
|
|
137
|
+
const generatorCommand = [
|
|
138
|
+
"npx --yes @openapitools/openapi-generator-cli generate",
|
|
139
|
+
`-i "${tempSpecPath}"`,
|
|
140
|
+
`-g typescript-axios`,
|
|
141
|
+
`-o "${typesOutputPath}"`,
|
|
142
|
+
`--ignore-file-override "${ignoreFilePath}"`,
|
|
143
|
+
`--additional-properties=supportsES6=true,useSingleRequestParameter=true,withInterfaces=true,modelPropertyNaming=original`
|
|
144
|
+
].join(" ");
|
|
145
|
+
console.log(import_chalk.default.gray(`Executing command: npx @openapitools/openapi-generator-cli...`));
|
|
146
|
+
(0, import_child_process.execSync)(generatorCommand, { stdio: "inherit" });
|
|
139
147
|
console.log(import_chalk.default.green(`\u2713 Types generated successfully at ${typesOutputPath}`));
|
|
140
148
|
console.log("\n" + import_chalk.default.blue("Step 4: Generating custom API modules..."));
|
|
141
149
|
const modules = parseSpecToModules(spec);
|
|
@@ -154,9 +162,7 @@ git_push.sh
|
|
|
154
162
|
const moduleData = modules[moduleName];
|
|
155
163
|
const fileName = `${moduleName}.module.ts`;
|
|
156
164
|
const filePath = import_path.default.join(modulesOutputPath, fileName);
|
|
157
|
-
const actionsTypeParts = Object.entries(moduleData.actions).map(([actionName, actionData]) => {
|
|
158
|
-
return ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`;
|
|
159
|
-
});
|
|
165
|
+
const actionsTypeParts = Object.entries(moduleData.actions).map(([actionName, actionData]) => ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`);
|
|
160
166
|
const actionsTypeDefinition = `{
|
|
161
167
|
${actionsTypeParts.join("\n")}
|
|
162
168
|
}`;
|
|
@@ -174,7 +180,6 @@ ${actionsValueParts.join(",\n")}
|
|
|
174
180
|
*/
|
|
175
181
|
|
|
176
182
|
import type { ApiModuleConfig, ActionConfigModule, QueryOptions } from 'api-core-lib';
|
|
177
|
-
// [\u0625\u0635\u0644\u0627\u062D] \u0627\u0633\u062A\u064A\u0631\u0627\u062F \u0627\u0644\u0623\u0646\u0648\u0627\u0639 \u0645\u0646 \u0627\u0644\u0645\u0644\u0641 \u0627\u0644\u0631\u0626\u064A\u0633\u064A \u0627\u0644\u0645\u0646\u0638\u0645
|
|
178
183
|
import type { ${[...allModelTypes].join(", ")} } from '../types';
|
|
179
184
|
|
|
180
185
|
/**
|
|
@@ -203,10 +208,14 @@ export const ${moduleName}Module: ApiModuleConfig<${actionsTypeDefinition}> = {
|
|
|
203
208
|
}
|
|
204
209
|
process.exit(1);
|
|
205
210
|
} finally {
|
|
206
|
-
if (import_fs.default.existsSync(tempSpecPath)) {
|
|
211
|
+
if (tempSpecPath && import_fs.default.existsSync(tempSpecPath)) {
|
|
207
212
|
import_fs.default.unlinkSync(tempSpecPath);
|
|
208
213
|
console.log(import_chalk.default.gray("\nTemporary spec file cleaned up."));
|
|
209
214
|
}
|
|
215
|
+
if (ignoreFilePath && import_fs.default.existsSync(ignoreFilePath)) {
|
|
216
|
+
import_fs.default.unlinkSync(ignoreFilePath);
|
|
217
|
+
console.log(import_chalk.default.gray("Temporary ignore file cleaned up."));
|
|
218
|
+
}
|
|
210
219
|
}
|
|
211
220
|
}
|
|
212
221
|
|