@paulpugovkin/api-docs-axios-ts-generator 1.0.7 → 1.0.8

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/package.json +1 -1
  2. package/src/index.js +46 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paulpugovkin/api-docs-axios-ts-generator",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Generate TypeScript interfaces and axios classes from OpenAPI documentation",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -18,14 +18,51 @@ const {
18
18
  } = require("./generate-main-index-file/generateMainIndexFile");
19
19
  const {generateAxiosConfig} = require("./generators/axiosConfigGenerator");
20
20
 
21
- // Модуль загрузки конфигурации (компилированный TypeScript)
22
- let loadConfig;
23
- try {
24
- loadConfig = require("./config/loadConfig").loadConfig;
25
- } catch (e) {
26
- // Если скомпилированный файл не существует, используем простой режим
27
- console.warn("Config module not found, using CLI mode only");
28
- loadConfig = null;
21
+ // Simple configuration loader
22
+ const fs = require('fs');
23
+ const path = require('path');
24
+
25
+ async function loadConfig(configPath, cliOptions = {}) {
26
+ const resolvedPath = path.resolve(configPath);
27
+
28
+ if (!fs.existsSync(resolvedPath)) {
29
+ throw new Error(`Configuration file not found: ${resolvedPath}`);
30
+ }
31
+
32
+ const ext = path.extname(resolvedPath);
33
+ let config;
34
+
35
+ try {
36
+ if (ext === '.js') {
37
+ const modulePath = resolvedPath;
38
+ config = require(modulePath);
39
+ } else if (ext === '.json') {
40
+ const content = fs.readFileSync(resolvedPath, 'utf8');
41
+ config = JSON.parse(content);
42
+ } else if (ext === '.ts') {
43
+ const ts = require('typescript');
44
+ const result = ts.transpileModule(content, {
45
+ compilerOptions: {
46
+ module: 1, // CommonJS
47
+ target: 99, // ESNext
48
+ esModuleInterop: true,
49
+ },
50
+ });
51
+ const modulePath = resolvedPath.replace('.ts', '.js');
52
+ fs.writeFileSync(modulePath, result.outputText);
53
+ config = require(modulePath);
54
+ } else {
55
+ throw new Error(`Unsupported configuration file format. Use .js, .json, or .ts`);
56
+ }
57
+ } catch (error) {
58
+ throw new Error(`Failed to load configuration: ${error.message}`);
59
+ }
60
+
61
+ // Merge CLI options with config
62
+ return {
63
+ ...config,
64
+ ...cliOptions,
65
+ };
29
66
  }
30
67
 
31
68
  // Основной инструмент CLI
@@ -47,7 +84,7 @@ async function main() {
47
84
  let config = null;
48
85
 
49
86
  // Загрузка конфигурации из файла или использование CLI аргументов
50
- if (configPath && loadConfig) {
87
+ if (configPath) {
51
88
  try {
52
89
  config = await loadConfig(configPath, {
53
90
  apiDocsUrl: options.apiDocsUrl,