chore(generators): update pipe generator

This commit is contained in:
Tim Lancina
2016-01-07 15:24:02 -06:00
parent 10e0558cd1
commit 9b860ea091
2 changed files with 40 additions and 27 deletions

View File

@ -1,27 +1,30 @@
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) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pipes', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('app', 'pipes'); var path = require('path'),
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName); fs = require('fs'),
shell = require('shelljs'),
Generator = require('../../generator');
var templates = Generate.loadGeneratorTemplates(__dirname); module.exports = PipeGenerator;
function PipeGenerator(options) {
Generator.call(this, options);
this.directory = path.join('app', 'pipes');
}
PipeGenerator.prototype = Object.create(Generator.prototype);
PipeGenerator.prototype.makeDirectories = function(){
shell.mkdir('-p', path.join(this.appDirectory, this.directory));
}
PipeGenerator.prototype.renderTemplates = function renderTemplates() {
var templates = this.loadTemplates();
templates.forEach(function(template) { templates.forEach(function(template) {
options.templatePath = template.file; var renderedTemplate = this.renderTemplate(template);
var renderedTemplate = Generate.renderTemplateFromFile(options); var renderedTemplateDest = path.join(this.appDirectory, this.directory, this.name + template.extension);
var saveFilePath = path.join(savePath, [options.fileName, template.type].join('')); console.log('√ Create'.blue, path.relative(this.appDirectory, renderedTemplateDest));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); fs.writeFileSync(renderedTemplateDest, renderedTemplate);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); }, this);
fs.writeFileSync(saveFilePath, renderedTemplate); }
});
};

View File

@ -1,11 +1,21 @@
import {Injectable, Pipe} from 'angular2/angular2'; import {Injectable, Pipe} from 'angular2/core';
/*
Generated class for the <%= jsClassName %> pipe.
See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
Angular 2 Pipes.
*/
@Pipe({ @Pipe({
name: '<%= fileName %>' name: '<%= fileName %>'
}) })
@Injectable() @Injectable()
class <%= jsClassName %> { export class <%= jsClassName %> {
transform(v, args) { /*
return v.toLowerCase(); Takes a value and makes it lowercase.
*/
transform(value, args) {
value = value + ''; // make sure it's a string
return value.toLowerCase();
} }
} }