@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.
- package/package.json +1 -1
- package/src/index.js +46 -9
package/package.json
CHANGED
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
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
87
|
+
if (configPath) {
|
|
51
88
|
try {
|
|
52
89
|
config = await loadConfig(configPath, {
|
|
53
90
|
apiDocsUrl: options.apiDocsUrl,
|