Comparing version 0.1.2 to 0.1.3
@@ -14,3 +14,7 @@ var chalk = require('chalk'); | ||
}; | ||
/** | ||
* Generates files from templates | ||
* @param {[type]} names Array of parameters, first is template type (element, fragment, module, page) | ||
* @return {[type]} | ||
*/ | ||
function generate(names) { | ||
@@ -25,2 +29,3 @@ var type = names.shift(); | ||
var templates = {}; | ||
// go thru all extensions in type and cache templates | ||
_.each(extensions, function(extension) { | ||
@@ -30,4 +35,6 @@ var template = fs.readFileSync(path.join(sources, type + '.' + extension), 'utf-8'); | ||
}); | ||
// create template for each requested names and each extension type contains | ||
_.each(names, function(name) { | ||
_.each(extensions, function(extension) { | ||
// template string + data for template | ||
var data = templates[extension]({ | ||
@@ -39,3 +46,12 @@ partName: name, | ||
}); | ||
// target path | ||
var filePath = path.join(config.sourceDir, config.sourcePaths.viewsDir, pluralize(type), name, name + '.' + extension); | ||
// ensure directories exists before saving template | ||
filePath.split('/').slice(0, -1).reduce(function(prev, curr, i) { | ||
if (fs.existsSync(prev) === false) { | ||
fs.mkdirSync(prev); | ||
} | ||
return prev + '/' + curr; | ||
}); | ||
// write file | ||
fs.writeFileSync(filePath, data, 'utf-8'); | ||
@@ -42,0 +58,0 @@ console.log(chalk.green.bold('Success: ' + chalk.underline.white(filePath))); |
{ | ||
"name": "cml-cli", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Simple wrapper for build scripts to stabilize API and to scaffold views and common patterns of cml-frontend boilerplate. Not for standalone usage.", | ||
@@ -5,0 +5,0 @@ "bin": { |
14905
402