Feature(generate): Add generator for pipes

This commit is contained in:
jbavari
2015-10-30 23:38:10 -06:00
parent f413a9002a
commit bf6369175b
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,27 @@
var fs = require('fs'),
Generator = module.exports,
Generate = require('../../generate'),
path = require('path'),
Q = require('q');
/*
@options
name: Page name
appDirectory: App directory of where to save file
*/
Generator.run = function run(options) {
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file);
options.templatePath = templatePath;
var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join(''));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate);
});
};

View File

@ -0,0 +1,11 @@
import {Injectable, Pipe} from 'angular2/angular2';
@Pipe({
name: '<%= fileAndClassName %>'
})
@Injectable()
class <%= javascriptClassName %> {
transform(v, args) {
return v.toLowerCase();
}
}