-
Notifications
You must be signed in to change notification settings - Fork 4
/
exporter.ts
41 lines (35 loc) · 1.22 KB
/
exporter.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
import Mustache from "mustache";
import { join } from "path";
import { existsSync, readFileSync } from "fs";
let list = require('../templates/list.json');
export class Exporter {
public setExportFormat (name: string): boolean {
name = name.toLowerCase();
let templatePath: string = name;
for (let t of list) {
if (t.type.toLowerCase() === name) {
templatePath = join(__dirname, "../templates", t.template);
this.ext = t.fileExt;
break;
}
}
if (!existsSync(templatePath)) {
console.error(`Spritesheet template [${templatePath}] not found.`);
return false;
}
this.template = readFileSync(templatePath).toString();
return true;
}
public getExtension (): string {
return this.ext;
}
public compile (view: any): string {
if (!this.template) {
// Apply default template if not set by setExportFormat
this.template = readFileSync(join(__dirname, "../templates", "JsonHash")).toString();
}
return Mustache.render(this.template, view);
}
private template: string = "";
private ext: string = "json";
}