-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-renderer.ts
48 lines (44 loc) · 1.31 KB
/
template-renderer.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
46
47
48
/// <reference path="tds/node.d.ts" />
/// <reference path="tds/pug.d.ts" />
import * as pug from "pug";
import * as files from "fs";
import {INSTALLED_LOCATION, PUG_OPTIONS, PUG_DATA} from './application';
import {ArgumentParser} from './argument-parser';
export /**
* TemplateRenderer
*/
class TemplateRenderer {
compiled: Function;
result: string;
data: { [d: string]: any } = {};
cdn: boolean;
constructor(public parser: ArgumentParser) {
this.compile();
}
renderIndex() {
this.generateData(PUG_DATA);
this.result = this.compiled(this.data);
this.writeFile();
}
compile() {
this.compiled = pug.compileFile(INSTALLED_LOCATION + '\\templates\\web.pug', PUG_OPTIONS);
}
writeFile() {
files.writeFile(this.parser.option.projectName + "\\index.html", this.result, (err) => {
if (err) {
console.log(err);
return;
}
console.log(this.data);
console.log("Sample created successfully");
});
}
generateData(source: any) {
this.data["version"] = this.parser.option.ejVersion;
for (var prop in source) {
this.data[prop] = source[prop];
}
if (this.cdn)
this.data["useCDN"] = this.cdn;
}
}