add checks for templates and templates directory existence

This commit is contained in:
Sebastian McKenzie 2014-10-07 21:17:40 +11:00
parent 8310b288cb
commit 1ddb70839e

View File

@ -132,7 +132,10 @@ exports.buildDefineProperties = function (mutatorMap, keyNode) {
};
exports.template = function (name, nodes, keepExpression) {
var template = _.cloneDeep(exports.templates[name]);
var template = exports.templates[name];
if (!template) throw new ReferenceError("unknown template " + name);
template = _.cloneDeep(template);
if (!_.isEmpty(nodes)) {
traverse.replace(template, function (node) {
@ -197,6 +200,9 @@ if (fs.existsSync(templatesCacheLoc)) {
exports.templates = {};
var templatesLoc = __dirname + "/templates";
if (!fs.existsSync(templatesLoc)) {
throw new Error("no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/sebmck/6to5/issues");
}
_.each(fs.readdirSync(templatesLoc), function (name) {
var key = path.basename(name, path.extname(name));