apeman-tmpl
Version:
Template manager for apeman.
49 lines (44 loc) • 1.53 kB
JavaScript
;
const argx = require('argx'),
async = require('async'),
listTemplate = require('./templating/list_template'),
renderTemplate = require('./templating/render_template'),
apemanfile = require('apemanfile');
/** @lends apemanTmpl */
function apemanTmpl(options, callback) {
let args = argx(arguments);
callback = args.pop('function') || argx.noop;
options = args.pop('object') || {};
async.waterfall([
(callback) => {
apemanfile.load(options.configuration, {
safe: true // Ignore error when tmpl working.
}, callback);
},
(apemanfile, callback) => {
let here = process.cwd(),
cwd = apemanfile.$cwd || process.cwd();
let verbose = options.verbose;
async.series([
(callback) => {
process.chdir(cwd);
callback(null);
},
(callback) => {
if (options.list) {
listTemplate(apemanfile, options.pattern, callback);
} else {
renderTemplate(apemanfile, options.pattern, {
verbose: verbose
}, callback);
}
},
(callback) => {
process.chdir(here);
callback(null);
}
], callback);
}
], callback);
}
module.exports = apemanTmpl;