api-core-lib 12.0.39 → 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 +21 -18
- 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,31 +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
|
-
# Ignore helper files and documentation that we don't need in a TypeScript project.
|
|
123
|
-
|
|
124
124
|
# Main generator metadata
|
|
125
125
|
.openapi-generator/
|
|
126
|
-
|
|
127
126
|
# Documentation files
|
|
128
127
|
docs/
|
|
129
|
-
|
|
130
128
|
# Git helper files
|
|
131
129
|
.gitignore
|
|
132
130
|
git_push.sh
|
|
133
|
-
|
|
134
131
|
# NPM helper files
|
|
135
132
|
.npmignore
|
|
136
133
|
README.md
|
|
137
134
|
`;
|
|
138
|
-
if (!import_fs.default.existsSync(typesOutputPath)) {
|
|
139
|
-
import_fs.default.mkdirSync(typesOutputPath, { recursive: true });
|
|
140
|
-
}
|
|
141
135
|
import_fs.default.writeFileSync(ignoreFilePath, ignoreContent);
|
|
142
|
-
console.log(import_chalk.default.gray("\u2713 Created .openapi-generator-ignore
|
|
143
|
-
|
|
144
|
-
|
|
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" });
|
|
145
147
|
console.log(import_chalk.default.green(`\u2713 Types generated successfully at ${typesOutputPath}`));
|
|
146
148
|
console.log("\n" + import_chalk.default.blue("Step 4: Generating custom API modules..."));
|
|
147
149
|
const modules = parseSpecToModules(spec);
|
|
@@ -160,9 +162,7 @@ README.md
|
|
|
160
162
|
const moduleData = modules[moduleName];
|
|
161
163
|
const fileName = `${moduleName}.module.ts`;
|
|
162
164
|
const filePath = import_path.default.join(modulesOutputPath, fileName);
|
|
163
|
-
const actionsTypeParts = Object.entries(moduleData.actions).map(([actionName, actionData]) => {
|
|
164
|
-
return ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`;
|
|
165
|
-
});
|
|
165
|
+
const actionsTypeParts = Object.entries(moduleData.actions).map(([actionName, actionData]) => ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`);
|
|
166
166
|
const actionsTypeDefinition = `{
|
|
167
167
|
${actionsTypeParts.join("\n")}
|
|
168
168
|
}`;
|
|
@@ -180,7 +180,6 @@ ${actionsValueParts.join(",\n")}
|
|
|
180
180
|
*/
|
|
181
181
|
|
|
182
182
|
import type { ApiModuleConfig, ActionConfigModule, QueryOptions } from 'api-core-lib';
|
|
183
|
-
// [\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
|
|
184
183
|
import type { ${[...allModelTypes].join(", ")} } from '../types';
|
|
185
184
|
|
|
186
185
|
/**
|
|
@@ -209,10 +208,14 @@ export const ${moduleName}Module: ApiModuleConfig<${actionsTypeDefinition}> = {
|
|
|
209
208
|
}
|
|
210
209
|
process.exit(1);
|
|
211
210
|
} finally {
|
|
212
|
-
if (import_fs.default.existsSync(tempSpecPath)) {
|
|
211
|
+
if (tempSpecPath && import_fs.default.existsSync(tempSpecPath)) {
|
|
213
212
|
import_fs.default.unlinkSync(tempSpecPath);
|
|
214
213
|
console.log(import_chalk.default.gray("\nTemporary spec file cleaned up."));
|
|
215
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
|
+
}
|
|
216
219
|
}
|
|
217
220
|
}
|
|
218
221
|
|