use promises

This commit is contained in:
Thomas Ruoff
2017-02-24 21:17:10 +01:00
parent 722accbe5d
commit f51daddc65
3 changed files with 48 additions and 58 deletions

View File

@@ -1,13 +1,13 @@
const path = require('path');
module.exports.get = (templateName, options, callback) => {
const modulePath = path.join(__dirname, 'templates', templateName);
let template;
try {
template = require(modulePath);
callback(null, template(options));
} catch (e) {
callback(`${templateName} not found!`);
}
module.exports.get = function(templateName, options) {
return new Promise((resolve, reject) => {
const modulePath = path.join(__dirname, 'templates', templateName);
try {
const template = require(modulePath);
resolve(template(options));
} catch (e) {
reject(`${templateName} not found!`);
}
});
};