-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathTemplateFileGenerator.ts
45 lines (44 loc) · 1.42 KB
/
TemplateFileGenerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { TemplateGenerator, TemplateRenderCompleteModelOptions } from '.';
import { InputMetaModel, OutputModel } from '../../models';
import * as path from 'path';
import { AbstractFileGenerator } from '../AbstractFileGenerator';
import { FileHelpers } from '../../helpers';
export class TemplateFileGenerator
extends TemplateGenerator
implements AbstractFileGenerator<TemplateRenderCompleteModelOptions>
{
/**
* Generates all the models to an output directory each model with their own separate files.
*
* @param input
* @param outputDirectory where you want the models generated to
* @param options
*/
public async generateToFiles(
input: any | InputMetaModel,
outputDirectory: string,
options?: TemplateRenderCompleteModelOptions,
ensureFilesWritten = false
): Promise<OutputModel[]> {
let generatedModels = await this.generateCompleteModels(
input,
options || {}
);
//Filter anything out that have not been successfully generated
generatedModels = generatedModels.filter((outputModel) => {
return outputModel.modelName !== '';
});
for (const outputModel of generatedModels) {
const filePath = path.resolve(
outputDirectory,
`${outputModel.modelName}.MYEXTENSION`
);
await FileHelpers.writerToFileSystem(
outputModel.result,
filePath,
ensureFilesWritten
);
}
return generatedModels;
}
}