|
1 | 1 | import * as changeCase from "change-case";
|
2 | 2 | import * as fs from "fs";
|
| 3 | +import * as path from "path"; |
| 4 | +import {TemplateRequest} from "../utils/TemplateRequest"; |
3 | 5 |
|
4 | 6 | const chalk = require("chalk"),
|
5 | 7 | commander = require("commander"),
|
6 | 8 | walk = require('walk');
|
7 | 9 |
|
8 | 10 | export class GenerateController {
|
9 | 11 |
|
10 |
| - |
11 | 12 | /**
|
12 | 13 | * @desc Generate rendered out file
|
13 | 14 | *
|
14 | 15 | * @param {string} componentType - Type of component
|
15 | 16 | * @param {string} componentName - Name of component
|
16 | 17 | * @param {string} targetPkg - Targeted package name
|
17 | 18 | */
|
18 |
| - public generateRenderedOutFile(componentType: string, componentName: string, targetPkg: string) { |
19 |
| - |
20 |
| - console.log(process.argv[1]); |
| 19 | + public async generateRenderedOutFile(componentType: string, componentName: string, targetPkg: string) { |
21 | 20 |
|
22 |
| - //TODO GET REAL BOILERPLATES PATH |
23 |
| - const boilerplatesPath = `../../boilerplates/${componentType}`, |
24 |
| - boilerplateNameOfJAVA = `index.ac.src`, |
25 |
| - boilerplateNameOfXML = `index.ac.layout`, |
26 |
| - |
27 |
| - javaFileName: string = `${changeCase.pascalCase(componentName)}${changeCase.pascalCase(componentType)}.java`, |
| 21 | + const javaFileName: string = `${changeCase.pascalCase(componentName)}${changeCase.pascalCase(componentType)}.java`, |
28 | 22 | xmlFileName: string = `${changeCase.lowerCase(componentType)}_${changeCase.lowerCase(componentName)}.xml`,
|
29 | 23 |
|
30 |
| - javaContent: string = fs.readFileSync(`${boilerplatesPath}/${boilerplateNameOfJAVA}`, 'utf-8').toString(), |
31 |
| - xmlContent: string = fs.readFileSync(`${boilerplatesPath}/${boilerplateNameOfXML}`, 'utf-8').toString(), |
| 24 | + templates : any = await TemplateRequest.getTemplateContents(componentType), |
| 25 | + |
| 26 | + javaContent: string = templates.src, |
| 27 | + xmlContent: string = templates.layout, |
32 | 28 |
|
33 | 29 | parsedJavaContent: string = this.renderAcFile(javaContent, targetPkg, componentName),
|
34 | 30 | parsedXMLContent: string = this.renderAcFile(xmlContent, targetPkg, componentName);
|
|
0 commit comments