api-core-lib 12.0.39 → 12.0.41
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 +23 -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,33 @@ 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
|
+
// **الخيار السحري**: أخبر المولد بتوليد النماذج فقط
|
|
144
|
+
`--global-property models`,
|
|
145
|
+
`--additional-properties=supportsES6=true,withInterfaces=true,modelPropertyNaming=original`
|
|
146
|
+
].join(" ");
|
|
147
|
+
console.log(import_chalk.default.gray(`Executing command: npx @openapitools/openapi-generator-cli...`));
|
|
148
|
+
(0, import_child_process.execSync)(generatorCommand, { stdio: "inherit" });
|
|
145
149
|
console.log(import_chalk.default.green(`\u2713 Types generated successfully at ${typesOutputPath}`));
|
|
146
150
|
console.log("\n" + import_chalk.default.blue("Step 4: Generating custom API modules..."));
|
|
147
151
|
const modules = parseSpecToModules(spec);
|
|
@@ -160,9 +164,7 @@ README.md
|
|
|
160
164
|
const moduleData = modules[moduleName];
|
|
161
165
|
const fileName = `${moduleName}.module.ts`;
|
|
162
166
|
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
|
-
});
|
|
167
|
+
const actionsTypeParts = Object.entries(moduleData.actions).map(([actionName, actionData]) => ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`);
|
|
166
168
|
const actionsTypeDefinition = `{
|
|
167
169
|
${actionsTypeParts.join("\n")}
|
|
168
170
|
}`;
|
|
@@ -180,7 +182,6 @@ ${actionsValueParts.join(",\n")}
|
|
|
180
182
|
*/
|
|
181
183
|
|
|
182
184
|
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
185
|
import type { ${[...allModelTypes].join(", ")} } from '../types';
|
|
185
186
|
|
|
186
187
|
/**
|
|
@@ -209,10 +210,14 @@ export const ${moduleName}Module: ApiModuleConfig<${actionsTypeDefinition}> = {
|
|
|
209
210
|
}
|
|
210
211
|
process.exit(1);
|
|
211
212
|
} finally {
|
|
212
|
-
if (import_fs.default.existsSync(tempSpecPath)) {
|
|
213
|
+
if (tempSpecPath && import_fs.default.existsSync(tempSpecPath)) {
|
|
213
214
|
import_fs.default.unlinkSync(tempSpecPath);
|
|
214
215
|
console.log(import_chalk.default.gray("\nTemporary spec file cleaned up."));
|
|
215
216
|
}
|
|
217
|
+
if (ignoreFilePath && import_fs.default.existsSync(ignoreFilePath)) {
|
|
218
|
+
import_fs.default.unlinkSync(ignoreFilePath);
|
|
219
|
+
console.log(import_chalk.default.gray("Temporary ignore file cleaned up."));
|
|
220
|
+
}
|
|
216
221
|
}
|
|
217
222
|
}
|
|
218
223
|
|