Feature(generators): Add generators for components, directives, and injectables

This commit is contained in:
jbavari
2015-10-30 23:21:54 -06:00
parent 25b672dabe
commit c79ccfc5ca
7 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,3 @@
<div *ng-if="value">
<%= javascriptClassName %>
</div>

View File

@ -0,0 +1,15 @@
import {Component, NgIf} from 'angular2/angular2';
@Component({
directives: [NgIf],
properties: ['value'], //Change to be whatever properties you want, ex: <<%= fileAndClassName %> value="5">
selector: '<%= fileAndClassName %>',
templateUrl: 'app/<%= fileAndClassName %>/<%= fileAndClassName %>.html'
})
export class <%= javascriptClassName %> {
constructor() {
this.nav = nav;
this.popup = popup;
this.dataService = dataService;
}
}

View File

@ -0,0 +1,26 @@
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 {Directive, ElementRef} from 'angular2/angular2';
@Directive({
properties: ['<%= fileAndClassName %>'], //Change to be whatever properties you want, ex: <<%= fileAndClassName %> value="5">
inputs: ['<%= fileAndClassName %>']
})
export class <%= javascriptClassName %> {
constructor(elementRef: ElementRef) {
this.ele = elementRef;
}
}

View File

@ -0,0 +1,26 @@
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,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,21 @@
import {Injectable} from 'angular2/angular2';
import {Http} from 'angular2/http';
@Injectable()
export class <%= javascriptClassName %> {
constructor(http: Http) {
this.http = http;
this.data = null;
}
retrieveData() {
//Here, we're going to get a JSON data file, use the `map` call to parse json
// and finally subscribe to the observable and set our data
//to the value it provides once the http request is complete.
this.http.get('path/to/data.json')
.map(res => res.json())
.subscribe(data => {
this.data = data;
});
}
}