You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
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)
|
|
}
|
|
}
|
|
|
|
|