Skip to content

Commit 6000957

Browse files
Added cli.ts:
- Changed package.json - Some settings still was loaded from arguments, but now from ConfigModel - cli.ts file is the input path to cli mode - Now you can include main.ts for pragmatically launch with settings
1 parent 17a1eb9 commit 6000957

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "node",
99
"request": "launch",
1010
"name": "Launch Program",
11-
"program": "${workspaceFolder}/src/main.ts",
11+
"program": "${workspaceFolder}/src/cli.ts",
1212
"preLaunchTask": "tsc: build - tsconfig.json",
1313
"args": [
1414
"-f",

nodemon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"watch": ["src", "templates"],
33
"ext": "ts,json",
44
"ignore": ["src/**/*.spec.ts"],
5-
"exec": "npx ts-node ./src/main.ts"
5+
"exec": "npx ts-node ./src/cli.ts"
66
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"time-saver",
1818
"tool"
1919
],
20-
"main": "dist/main.js",
21-
"types": "dist/main.d.ts",
20+
"main": "dist/cli",
21+
"types": "dist/cli.d.ts",
2222
"scripts": {
2323
"prepublish": "npm run build",
24-
"start": "ts-node src/main.ts",
24+
"start": "ts-node src/cli",
2525
"start:dev": "npx nodemon",
2626
"start:build": "node build/index.js",
2727
"start:webpack": "npx webpack --watch",
@@ -44,7 +44,7 @@
4444
"url": "https://patreon.com/ProtocolNebula"
4545
},
4646
"bin": {
47-
"transform-swagger": "./cli.js"
47+
"transform-swagger": "./build/cli.js"
4848
},
4949
"homepage": "https://github.com/ProtocolNebula/ts-openapi-generator",
5050
"repository": {

src/cli.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
import { config } from './models/config.model';
3+
import { argumentsInstance } from './services/arguments.service';
4+
import { generateAPIFiles } from './main';
5+
6+
config.parseYargs(argumentsInstance);
7+
// FOLDERS INFORMATION
8+
console.info('Output folders:');
9+
console.table({
10+
OUTPUT_PATH: config.outputPath,
11+
BASE_FOLDER: config.exportPath,
12+
MODELS: config.exportPath,
13+
APIS: config.exportPath,
14+
});
15+
generateAPIFiles(config);

src/main.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
11
import * as fs from 'fs-extra';
2-
import { config } from './models/config.model';
3-
import { argumentsInstance } from './services/arguments.service';
2+
import { config, ConfigI } from './models/config.model';
43
import { FileReaderService } from './services/parsers/file-reader.service';
54
import { APIParserService } from './services/parsers/open-api-v3/api-parser.service';
65
import { ComponentsParserService } from './services/parsers/open-api-v3/components-parser.service';
76
import { ApiWritterService } from './services/writters/api-writter.service';
87
import { ModelWritterService } from './services/writters/model-writter.service';
98
import { Store } from './stores/entities.store';
109

11-
config.parseYargs(argumentsInstance);
12-
13-
// FOLDERS INFORMATION
14-
console.info('Output folders:');
15-
console.table({
16-
OUTPUT_PATH: config.outputPath,
17-
BASE_FOLDER: config.exportPath,
18-
MODELS: config.exportPath,
19-
APIS: config.exportPath,
20-
});
21-
2210
// Read the file
23-
async function run() {
11+
export async function generateAPIFiles(config: ConfigI) {
2412
try {
2513
// Check if the template does not exist
2614
config.templatePath;
2715

2816
console.log('');
29-
if (argumentsInstance.clean) {
17+
if (config.cleanFolder) {
3018
console.log('Removing previously generated data...');
3119
fs.removeSync(config.exportPath);
3220
} else {
3321
console.log('no-clean flag recevived, clean folder skipped');
3422
}
3523
console.log('');
3624

37-
console.log('Opening file:', argumentsInstance.file);
38-
const fileParser = new FileReaderService(argumentsInstance.file, config);
25+
console.log('Opening file:', config.fileURI);
26+
const fileParser = new FileReaderService(config.fileURI, config);
3927
console.log('Parsing file...');
4028
console.log('');
4129
const documentParsed = await fileParser.readFile();
@@ -68,5 +56,3 @@ async function run() {
6856
console.error('Application stopped');
6957
}
7058
}
71-
72-
run();

0 commit comments

Comments
 (0)