api-core-lib 12.0.35 → 12.0.36

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.
Files changed (2) hide show
  1. package/dist/cli.cjs +16 -27
  2. package/package.json +16 -19
package/dist/cli.cjs CHANGED
@@ -33,7 +33,6 @@ var import_path = __toESM(require("path"), 1);
33
33
  var import_axios = __toESM(require("axios"), 1);
34
34
  var import_chalk = __toESM(require("chalk"), 1);
35
35
  var import_dotenv = __toESM(require("dotenv"), 1);
36
- var import_openapi_typescript = __toESM(require("openapi-typescript"), 1);
37
36
 
38
37
  // src/generator/module-parser.ts
39
38
  function parseSpecToModules(spec) {
@@ -68,6 +67,7 @@ function parseSpecToModules(spec) {
68
67
  }
69
68
 
70
69
  // src/generator/index.ts
70
+ var import_child_process = require("child_process");
71
71
  async function runGenerator(options) {
72
72
  console.log(import_chalk.default.cyan(`Starting API module generation...`));
73
73
  console.log(import_chalk.default.gray(`Output directory: ${options.output}`));
@@ -79,38 +79,27 @@ async function runGenerator(options) {
79
79
  process.exit(1);
80
80
  }
81
81
  try {
82
- const specUrl = `${apiUrl}`;
82
+ const specUrl = `${apiUrl}/docs-json`;
83
83
  console.log(`Fetching OpenAPI spec from ${specUrl}...`);
84
84
  const response = await import_axios.default.get(specUrl);
85
85
  const spec = response.data;
86
- if (!import_fs.default.existsSync(options.output)) {
87
- import_fs.default.mkdirSync(options.output, { recursive: true });
88
- }
89
- console.log("Generating TypeScript types...");
90
- const typesContent = await (0, import_openapi_typescript.default)(spec);
91
- const typesPath = import_path.default.join(options.output, "api-types.generated.ts");
92
- import_fs.default.writeFileSync(typesPath, typesContent);
93
- console.log(import_chalk.default.green(`\u2713 Types generated successfully at ${typesPath}`));
94
- console.log("Generating API modules...");
86
+ const specPath = import_path.default.join(process.cwd(), "swagger.json");
87
+ import_fs.default.writeFileSync(specPath, JSON.stringify(spec, null, 2));
88
+ console.log(import_chalk.default.green(`\u2713 OpenAPI spec saved to ${specPath}`));
89
+ console.log("Generating organized TypeScript types and services...");
90
+ const typesOutputPath = import_path.default.join(options.output, "types");
91
+ const generatorCommand = `npx @openapitools/openapi-generator-cli generate -i ${specPath} -g typescript-axios -o ${typesOutputPath} --additional-properties=supportsES6=true,useSingleRequestParameter=true,withInterfaces=true`;
92
+ (0, import_child_process.execSync)(generatorCommand, { stdio: "inherit" });
93
+ console.log(import_chalk.default.green(`\u2713 Types generated successfully at ${typesOutputPath}`));
94
+ console.log("Generating API modules for api-core-lib...");
95
95
  const modules = parseSpecToModules(spec);
96
+ const modulesOutputPath = import_path.default.join(options.output, "modules");
97
+ if (!import_fs.default.existsSync(modulesOutputPath)) {
98
+ import_fs.default.mkdirSync(modulesOutputPath, { recursive: true });
99
+ }
96
100
  for (const moduleName in modules) {
97
- const moduleConfig = modules[moduleName];
98
- const fileName = `${moduleName}.module.ts`;
99
- const filePath = import_path.default.join(options.output, fileName);
100
- const fileContent = `
101
- // This file is auto-generated by api-core-lib.
102
- // Do not edit this file directly.
103
-
104
- import type { ApiModuleConfig } from 'api-core-lib';
105
- import type { paths } from './api-types.generated'; // \u0631\u0628\u0637 \u0627\u0644\u0623\u0646\u0648\u0627\u0639 \u0627\u0644\u0645\u0648\u0644\u062F\u0629
106
-
107
- // A more advanced generator could automatically map the correct input/output types.
108
- // For now, we use 'any' as a placeholder.
109
- export const ${moduleName}Module: ApiModuleConfig<any> = ${JSON.stringify(moduleConfig, null, 2)};
110
- `;
111
- import_fs.default.writeFileSync(filePath, fileContent);
112
- console.log(import_chalk.default.green(`\u2713 Module generated: ${fileName}`));
113
101
  }
102
+ import_fs.default.unlinkSync(specPath);
114
103
  console.log(import_chalk.default.bold.green("\n\u{1F389} API generation complete!"));
115
104
  } catch (error) {
116
105
  console.error(import_chalk.default.red("\nAn error occurred during generation:"));
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.35",
3
+ "version": "12.0.36",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
-
7
6
  "exports": {
8
- ".": {
7
+ ".": {
9
8
  "types": "./dist/index.d.ts",
10
9
  "import": "./dist/index.js",
11
10
  "require": "./dist/index.cjs"
@@ -21,50 +20,48 @@
21
20
  "require": "./dist/client.cjs"
22
21
  }
23
22
  },
24
-
25
23
  "main": "./dist/index.cjs",
26
24
  "module": "./dist/index.js",
27
25
  "types": "./dist/index.d.ts",
28
26
  "bin": {
29
- "api-core-generate": "./bin/cli-launcher.cjs"
27
+ "api-core-generate": "./bin/cli-launcher.cjs"
30
28
  },
31
29
  "scripts": {
32
- "build": "tsup",
30
+ "build": "tsup",
33
31
  "dev": "tsup --watch"
34
32
  },
35
-
36
33
  "peerDependencies": {
37
34
  "react": ">=19.0.0",
38
35
  "react-dom": ">=19.0.0"
39
36
  },
40
-
41
37
  "dependencies": {
42
38
  "axios": "^1.6.8",
43
39
  "axios-retry": "^4.1.0",
44
- "colorette": "^2.0.20",
45
- "fast-deep-equal": "^3.1.3",
46
- "path": "^0.12.7",
47
- "uuid": "^9.0.1",
48
-
49
40
  "chalk": "^4.1.2",
41
+ "colorette": "^2.0.20",
50
42
  "commander": "^9.4.1",
51
43
  "dotenv": "^16.0.3",
52
- "openapi-typescript": "^6.2.4"
44
+ "fast-deep-equal": "^3.1.3",
45
+ "openapi-typescript": "^6.2.4",
46
+ "path": "^0.12.7",
47
+ "uuid": "^9.0.1"
53
48
  },
54
-
55
49
  "devDependencies": {
56
- "react": "19.1.0",
57
- "react-dom": "19.1.0",
50
+ "@openapitools/openapi-generator-cli": "^2.23.1",
58
51
  "@types/jest": "^30.0.0",
59
52
  "@types/node": "^24.2.1",
60
53
  "@types/react": "^18.3.2",
61
54
  "@types/uuid": "^9.0.8",
62
55
  "javascript-obfuscator": "^4.1.1",
63
56
  "jest": "^30.0.5",
57
+ "react": "19.1.0",
58
+ "react-dom": "19.1.0",
64
59
  "ts-jest": "^29.4.1",
65
60
  "tsup": "^8.0.2",
66
61
  "typescript": "^5.4.5"
67
62
  },
68
-
69
- "files": ["dist" , "bin"]
63
+ "files": [
64
+ "dist",
65
+ "bin"
66
+ ]
70
67
  }