Skip to content

Commit 17a1eb9

Browse files
Added missing arguments to configModel
1 parent 312d751 commit 17a1eb9

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

src/models/config.model.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { resolve as pathResolve } from 'path';
33
import { TemplateConfigModel } from './template-config.model';
44

55
export interface ConfigI {
6-
tempFilePath: string;
6+
cleanFolder: boolean;
7+
fileURI: string;
78
outputPath: string;
9+
tempFilePath: string;
10+
template: string;
11+
812
readonly exportPath: string;
9-
readonly outputModelsPath: string;
1013
readonly outputApisPath: string;
11-
template: string;
14+
readonly outputModelsPath: string;
1215
readonly templateConfig: TemplateConfigModel;
16+
readonly templatePath;
1317
}
1418

1519
class ConfigModel implements ConfigI {
@@ -23,9 +27,15 @@ class ConfigModel implements ConfigI {
2327
private _templatePath: string;
2428
private _templateConfig: TemplateConfigModel;
2529

30+
fileURI: string;
31+
cleanFolder: boolean;
32+
2633
get outputPath(): string {
2734
return this._outputPath;
2835
}
36+
set outputPath(outputPath: string) {
37+
this._outputPath = pathResolve(outputPath);
38+
}
2939

3040
get exportPath(): string {
3141
return pathResolve(this.outputPath, this._outputBaseFolder);
@@ -44,7 +54,7 @@ class ConfigModel implements ConfigI {
4454
}
4555

4656
set tempFilePath(tempFilePath: string) {
47-
this._tempFilePath = tempFilePath;
57+
this._tempFilePath = pathResolve(tempFilePath);
4858
}
4959

5060
get template(): string {
@@ -85,17 +95,44 @@ class ConfigModel implements ConfigI {
8595

8696
get templateConfig(): TemplateConfigModel {
8797
if (!this._templateConfig) {
88-
this._templateConfig = new TemplateConfigModel(pathResolve(this.templatePath, 'config'));
98+
this._templateConfig = new TemplateConfigModel(
99+
pathResolve(this.templatePath, 'config'),
100+
);
89101
}
90102
return this._templateConfig;
91103
}
92104

93105
constructor() {}
94106

107+
setConfig(config: ConfigI) {
108+
for (const key in config) {
109+
const value = config[key];
110+
if (value) {
111+
this[key] = value;
112+
} else {
113+
console.warn(`${key} in config not recognized`);
114+
}
115+
}
116+
}
117+
95118
parseYargs(yargs): void {
96-
this._outputPath = yargs.outputFolder;
97-
this.tempFilePath = pathResolve(yargs.saveFile);
98-
this.template = yargs.template;
119+
const config = {} as ConfigI;
120+
if (yargs.saveFile) {
121+
config.tempFilePath = yargs.saveFile;
122+
}
123+
if (yargs.file) {
124+
config.fileURI = yargs.file;
125+
}
126+
if (yargs.template) {
127+
config.template = yargs.template;
128+
}
129+
if (yargs.outputFolder) {
130+
config.outputPath = yargs.outputFolder;
131+
}
132+
if (this.cleanFolder === undefined || yargs.clean === false) {
133+
config.cleanFolder = yargs.clean;
134+
}
135+
this.setConfig(config);
99136
}
100137
}
101138

0 commit comments

Comments
 (0)