let path = require('path') let fs = require('fs'); let fileExtensionToImage: object; export class Configurator { fileutils: FileUtils = new FileUtils(); getFileExtensionToImageMap(): Object { if (!fileExtensionToImage) { fileExtensionToImage = this.loadConfigMap("file-extensions.json"); } return fileExtensionToImage; }; loadConfigMap(fileName: string): object { let filePath = this.fileutils.getPathToConfig(fileName); let fileBuffer = fs.readFileSync(filePath); let content = fileBuffer.toString('utf8') return JSON.parse(content) } } export class FileUtils { getPathToView(templateName: string): string { return path.join(this.getPathToAssets(), "views", templateName + ".html") } getPathToImage(imageName: string): string { return path.join(this.getPathToAssets(), "images", imageName) } getPathToDocument(documentName: string): string { return path.join(this.getPathToAssets(), "documents", documentName) } getPathToConfig(documentName: string): string { return path.join(this.getPathToAssets(), "conf", documentName) } getPathToAssets(): string { return path.join(__dirname, "..", "assets"); } getFileExtension(fileName: string): string { return fileName.substr(fileName.lastIndexOf(".")+1) } }