mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
chore(generators): update generator scripts
This commit is contained in:

committed by
Adam Bradley

parent
35e4033343
commit
2359437114
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Generated template for the <%= jsClassName %> component.
|
Generated template for the $CLASSNAME component.
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
|
See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
|
||||||
for more info on Angular 2 Components.
|
for more info on Angular 2 Components.
|
3
scripts/templates/component/scss.tmpl
Normal file
3
scripts/templates/component/scss.tmpl
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.$FILENAME {
|
||||||
|
|
||||||
|
}
|
6
scripts/templates/component/spec.ts.tmpl
Normal file
6
scripts/templates/component/spec.ts.tmpl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
describe('$CLASSNAME', () => {
|
||||||
|
it('should do something', () => {
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
@ -1,16 +1,16 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generated class for the <%= jsClassName %> component.
|
Generated class for the $CLASSNAME component.
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
|
See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
|
||||||
for more info on Angular 2 Components.
|
for more info on Angular 2 Components.
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: '<%= fileName %>',
|
selector: '$FILENAME',
|
||||||
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html'
|
templateUrl: '$FILENAME.html'
|
||||||
})
|
})
|
||||||
export class <%= jsClassName %> {
|
export class $CLASSNAME {
|
||||||
|
|
||||||
text: string;
|
text: string;
|
||||||
|
|
6
scripts/templates/directive/spec.ts.tmpl
Normal file
6
scripts/templates/directive/spec.ts.tmpl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
describe('$CLASSNAME', () => {
|
||||||
|
it('should do something', () => {
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
@ -1,15 +1,15 @@
|
|||||||
import { Directive } from '@angular/core';
|
import { Directive } from '@angular/core';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generated class for the <%= jsClassName %> directive.
|
Generated class for the $CLASSNAME directive.
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
|
See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
|
||||||
for more info on Angular 2 Directives.
|
for more info on Angular 2 Directives.
|
||||||
*/
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[<%= fileName %>]' // Attribute selector
|
selector: '[$FILENAME]' // Attribute selector
|
||||||
})
|
})
|
||||||
export class <%= jsClassName %> {
|
export class $CLASSNAME {
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log('Hello World');
|
console.log('Hello World');
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Generated template for the <%= jsClassName %> page.
|
Generated template for the $CLASSNAME page.
|
||||||
|
|
||||||
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
||||||
Ionic pages and navigation.
|
Ionic pages and navigation.
|
||||||
@ -7,7 +7,7 @@
|
|||||||
<ion-header>
|
<ion-header>
|
||||||
|
|
||||||
<ion-navbar>
|
<ion-navbar>
|
||||||
<ion-title><%= name %></ion-title>
|
<ion-title>$SUPPLIEDNAME</ion-title>
|
||||||
</ion-navbar>
|
</ion-navbar>
|
||||||
|
|
||||||
</ion-header>
|
</ion-header>
|
3
scripts/templates/page/scss.tmpl
Normal file
3
scripts/templates/page/scss.tmpl
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.$FILENAME {
|
||||||
|
|
||||||
|
}
|
6
scripts/templates/page/spec.ts.tmpl
Normal file
6
scripts/templates/page/spec.ts.tmpl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
describe('$CLASSNAME', () => {
|
||||||
|
it('should do something', () => {
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
@ -2,15 +2,15 @@ import { Component } from '@angular/core';
|
|||||||
import { NavController } from 'ionic-angular';
|
import { NavController } from 'ionic-angular';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generated class for the <%= jsClassName %> page.
|
Generated class for the $CLASSNAME page.
|
||||||
|
|
||||||
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
||||||
Ionic pages and navigation.
|
Ionic pages and navigation.
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html',
|
templateUrl: '$FILENAME.html'
|
||||||
})
|
})
|
||||||
export class <%= jsClassName %> {
|
export class $CLASSNAME {
|
||||||
|
|
||||||
constructor(private navCtrl: NavController) {
|
constructor(private navCtrl: NavController) {
|
||||||
|
|
6
scripts/templates/pipe/spec.ts.tmpl
Normal file
6
scripts/templates/pipe/spec.ts.tmpl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
describe('$CLASSNAME', () => {
|
||||||
|
it('should do something', () => {
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
@ -1,16 +1,16 @@
|
|||||||
import { Injectable, Pipe } from '@angular/core';
|
import { Injectable, Pipe } from '@angular/core';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generated class for the <%= jsClassName %> pipe.
|
Generated class for the $CLASSNAME pipe.
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
|
See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
|
||||||
Angular 2 Pipes.
|
Angular 2 Pipes.
|
||||||
*/
|
*/
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: '<%= fileName %>'
|
name: '$FILENAME'
|
||||||
})
|
})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class <%= jsClassName %> {
|
export class $CLASSNAME {
|
||||||
/*
|
/*
|
||||||
Takes a value and makes it lowercase.
|
Takes a value and makes it lowercase.
|
||||||
*/
|
*/
|
6
scripts/templates/provider/spec.ts.tmpl
Normal file
6
scripts/templates/provider/spec.ts.tmpl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
describe('$CLASSNAME', () => {
|
||||||
|
it('should do something', () => {
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
@ -3,15 +3,15 @@ import { Http } from '@angular/http';
|
|||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generated class for the <%= jsClassName %> provider.
|
Generated class for the $CLASSNAME provider.
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
|
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
|
||||||
for more info on providers and Angular 2 DI.
|
for more info on providers and Angular 2 DI.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class <%= jsClassName %> {
|
export class $CLASSNAME {
|
||||||
|
|
||||||
constructor(private http: Http) {}
|
constructor(private http: Http) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,61 +0,0 @@
|
|||||||
var fs = require('fs'),
|
|
||||||
path = require('path'),
|
|
||||||
inquirer = require('inquirer');
|
|
||||||
|
|
||||||
Generate = module.exports;
|
|
||||||
|
|
||||||
Generate.__defineGetter__('generators', function() {
|
|
||||||
if (!Generate._generators) {
|
|
||||||
Generate._generators = Generate.loadGenerators();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Generate._generators;
|
|
||||||
});
|
|
||||||
|
|
||||||
Generate.generate = function generate(options) {
|
|
||||||
if (!options) {
|
|
||||||
throw new Error('No options passed to generator');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!options.generator) {
|
|
||||||
throw new Error('No generator passed to generate');
|
|
||||||
}
|
|
||||||
|
|
||||||
var GeneratorType = Generate.loadGenerator(options.generator);
|
|
||||||
return new GeneratorType(options).run();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Generate.loadGenerator = function loadGenerator(generator) {
|
|
||||||
var generateModule;
|
|
||||||
try {
|
|
||||||
generateModule = require(path.join(__dirname, 'generators', generator));
|
|
||||||
} catch (err) {
|
|
||||||
if (err.code === 'MODULE_NOT_FOUND') {
|
|
||||||
throw new Error('There is no generator available with the name ' + generator + '.');
|
|
||||||
} else {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return generateModule;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Return array of filenames in the generators directory
|
|
||||||
*/
|
|
||||||
Generate.loadGenerators = function loadGenerators() {
|
|
||||||
var generators = {};
|
|
||||||
try {
|
|
||||||
generators = fs.readdirSync(path.join(__dirname, 'generators'));
|
|
||||||
} catch(err) {
|
|
||||||
throw new Error('There was an error loading the generators list', err);
|
|
||||||
}
|
|
||||||
return generators;
|
|
||||||
};
|
|
||||||
|
|
||||||
Generate.printAvailableGenerators = function printAvailableGenerators() {
|
|
||||||
console.log('Available generators:'.blue);
|
|
||||||
Generate.generators.forEach(function(generator){
|
|
||||||
console.log(' *'.blue, generator);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
var _ = require('lodash'),
|
|
||||||
fs = require('fs'),
|
|
||||||
path = require('path'),
|
|
||||||
mkdirp = require('mkdirp-no-bin');
|
|
||||||
|
|
||||||
module.exports = Generator;
|
|
||||||
|
|
||||||
function Generator(options) {
|
|
||||||
this.name = options.name;
|
|
||||||
this.type = options.generator;
|
|
||||||
this.appDirectory = options.appDirectory;
|
|
||||||
this.isTS = options.isTS;
|
|
||||||
|
|
||||||
//templateVars
|
|
||||||
this.fileName = _.kebabCase(this.name);
|
|
||||||
this.jsClassName = _.capitalize(_.camelCase(this.name));
|
|
||||||
}
|
|
||||||
|
|
||||||
Generator.prototype.run = function(){
|
|
||||||
this.makeDirectories();
|
|
||||||
this.renderTemplates();
|
|
||||||
}
|
|
||||||
|
|
||||||
Generator.prototype.makeDirectories = function(){
|
|
||||||
if (!this.directory) {
|
|
||||||
throw new Error('Generators must define their directory in their constructor.\nEx: \'pages\', \'components\', etc.');
|
|
||||||
}
|
|
||||||
mkdirp.sync(path.join(this.appDirectory, 'app', this.directory, this.fileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
Generator.prototype.renderTemplates = function renderTemplates() {
|
|
||||||
var templates = this.loadTemplates();
|
|
||||||
|
|
||||||
templates.forEach(function(template) {
|
|
||||||
var renderedTemplate = this.renderTemplate(template);
|
|
||||||
var renderedTemplateDest = path.join(this.appDirectory, 'app', this.directory, this.fileName, this.fileName + template.extension);
|
|
||||||
console.log('√ Create'.blue, path.relative(this.appDirectory, renderedTemplateDest));
|
|
||||||
fs.writeFileSync(renderedTemplateDest, renderedTemplate);
|
|
||||||
}, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Generator.prototype.loadTemplates = function() {
|
|
||||||
var generatorPath = path.join(__dirname, 'generators', this.type);
|
|
||||||
var templates = [];
|
|
||||||
fs.readdirSync(generatorPath)
|
|
||||||
.forEach(function(template) {
|
|
||||||
var type;
|
|
||||||
// Go through all the files in the folder, grab the templates, read in the file contents
|
|
||||||
// return as template type, contents
|
|
||||||
if (template.indexOf('.tmpl') == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If not using typescript, ignore .ts files
|
|
||||||
if(!this.isTS && template.indexOf('.ts') != -1){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If using typescript, ignore .js files
|
|
||||||
if(this.isTS && template.indexOf('.js') != -1){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
templates.push({path: path.join(generatorPath, template), extension: path.extname(template)});
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
return templates;
|
|
||||||
};
|
|
||||||
|
|
||||||
Generator.prototype.renderTemplate = function(template) {
|
|
||||||
var templateContents = fs.readFileSync(template.path, 'utf8');
|
|
||||||
var templateCompiler = _.template(templateContents);
|
|
||||||
var result = templateCompiler(this);
|
|
||||||
return result;
|
|
||||||
};
|
|
@ -1,17 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
|
|
||||||
/*
|
|
||||||
Generated class for the <%= jsClassName %> component.
|
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
|
|
||||||
for more info on Angular 2 Components.
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
selector: '<%= fileName %>',
|
|
||||||
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html'
|
|
||||||
})
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
constructor() {
|
|
||||||
this.text = 'Hello World';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
var path = require('path'),
|
|
||||||
Generator = require('../../generator');
|
|
||||||
|
|
||||||
module.exports = ComponentGenerator;
|
|
||||||
|
|
||||||
function ComponentGenerator(options) {
|
|
||||||
Generator.call(this, options);
|
|
||||||
this.directory = 'components';
|
|
||||||
}
|
|
||||||
|
|
||||||
ComponentGenerator.prototype = Object.create(Generator.prototype);
|
|
@ -1,16 +0,0 @@
|
|||||||
import { Directive } from '@angular/core';
|
|
||||||
|
|
||||||
/*
|
|
||||||
Generated class for the <%= jsClassName %> directive.
|
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
|
|
||||||
for more info on Angular 2 Directives.
|
|
||||||
*/
|
|
||||||
@Directive({
|
|
||||||
selector: '[<%= fileName %>]' // Attribute selector
|
|
||||||
})
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
constructor() {
|
|
||||||
console.log('Hello World');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
var path = require('path'),
|
|
||||||
Generator = require('../../generator');
|
|
||||||
|
|
||||||
module.exports = DirectiveGenerator;
|
|
||||||
|
|
||||||
function DirectiveGenerator(options) {
|
|
||||||
Generator.call(this, options);
|
|
||||||
this.directory = 'components';
|
|
||||||
}
|
|
||||||
|
|
||||||
DirectiveGenerator.prototype = Object.create(Generator.prototype);
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
|||||||
var path = require('path'),
|
|
||||||
fs = require('fs'),
|
|
||||||
Generator = require('../../generator');
|
|
||||||
|
|
||||||
module.exports = PageGenerator;
|
|
||||||
|
|
||||||
function PageGenerator(options) {
|
|
||||||
Generator.call(this, options);
|
|
||||||
this.directory = 'pages';
|
|
||||||
this.jsClassName += 'Page';
|
|
||||||
}
|
|
||||||
|
|
||||||
PageGenerator.prototype = Object.create(Generator.prototype);
|
|
||||||
|
|
||||||
Generator.prototype.renderTemplates = function renderTemplates() {
|
|
||||||
var templates = this.loadTemplates();
|
|
||||||
var scssPath = null;
|
|
||||||
|
|
||||||
templates.forEach(function(template) {
|
|
||||||
var renderedTemplate = this.renderTemplate(template);
|
|
||||||
var renderedTemplateDest = path.join(this.appDirectory, 'app', this.directory, this.fileName, this.fileName + template.extension);
|
|
||||||
if (template.extension === '.scss') {
|
|
||||||
scssName = this.fileName + template.extension;
|
|
||||||
scssPath = renderedTemplateDest;
|
|
||||||
}
|
|
||||||
console.log('√ Create'.blue, path.relative(this.appDirectory, renderedTemplateDest));
|
|
||||||
fs.writeFileSync(renderedTemplateDest, renderedTemplate);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
console.log(('\nDon\'t forget to add an import for ' + scssName + ' ' + 'in ' +
|
|
||||||
path.join('app', 'themes', 'app.core.scss') + ':\n\n @import "' +
|
|
||||||
path.relative(path.join(this.appDirectory, 'app', 'themes'), scssPath) +
|
|
||||||
'";\n').green);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
import { NavController } from 'ionic-angular';
|
|
||||||
|
|
||||||
/*
|
|
||||||
Generated class for the <%= jsClassName %> page.
|
|
||||||
|
|
||||||
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
|
||||||
Ionic pages and navigation.
|
|
||||||
*/
|
|
||||||
@Component({
|
|
||||||
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html',
|
|
||||||
})
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
static get parameters() {
|
|
||||||
return [[NavController]];
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(nav) {
|
|
||||||
this.nav = nav;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
.<%= fileName %> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
var path = require('path'),
|
|
||||||
fs = require('fs'),
|
|
||||||
mkdirp = require('mkdirp-no-bin'),
|
|
||||||
Generator = require('../../generator');
|
|
||||||
|
|
||||||
module.exports = PipeGenerator;
|
|
||||||
|
|
||||||
function PipeGenerator(options) {
|
|
||||||
Generator.call(this, options);
|
|
||||||
this.directory = 'pipes';
|
|
||||||
}
|
|
||||||
|
|
||||||
PipeGenerator.prototype = Object.create(Generator.prototype);
|
|
||||||
|
|
||||||
PipeGenerator.prototype.makeDirectories = function(){
|
|
||||||
mkdirp.sync(path.join(this.appDirectory, 'app', this.directory));
|
|
||||||
}
|
|
||||||
|
|
||||||
PipeGenerator.prototype.renderTemplates = function renderTemplates() {
|
|
||||||
var templates = this.loadTemplates();
|
|
||||||
|
|
||||||
templates.forEach(function(template) {
|
|
||||||
var renderedTemplate = this.renderTemplate(template);
|
|
||||||
var renderedTemplateDest = path.join(this.appDirectory, 'app', this.directory, this.name + template.extension);
|
|
||||||
console.log('√ Create'.blue, path.relative(this.appDirectory, renderedTemplateDest));
|
|
||||||
fs.writeFileSync(renderedTemplateDest, renderedTemplate);
|
|
||||||
}, this);
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
import { Injectable, Pipe } from '@angular/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({
|
|
||||||
name: '<%= fileName %>'
|
|
||||||
})
|
|
||||||
@Injectable()
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
/*
|
|
||||||
Takes a value and makes it lowercase.
|
|
||||||
*/
|
|
||||||
transform(value: string, args: any[]) {
|
|
||||||
value = value + ''; // make sure it's a string
|
|
||||||
return value.toLowerCase();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
var path = require('path'),
|
|
||||||
Generator = require('../../generator');
|
|
||||||
|
|
||||||
module.exports = ProviderGenerator;
|
|
||||||
|
|
||||||
function ProviderGenerator(options) {
|
|
||||||
Generator.call(this, options);
|
|
||||||
this.directory = 'providers';
|
|
||||||
}
|
|
||||||
|
|
||||||
ProviderGenerator.prototype = Object.create(Generator.prototype);
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Http } from '@angular/http';
|
|
||||||
import 'rxjs/add/operator/map';
|
|
||||||
|
|
||||||
/*
|
|
||||||
Generated class for the <%= jsClassName %> provider.
|
|
||||||
|
|
||||||
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
|
|
||||||
for more info on providers and Angular 2 DI.
|
|
||||||
*/
|
|
||||||
@Injectable()
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
static get parameters() {
|
|
||||||
return [[Http]]
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(http) {
|
|
||||||
this.http = http;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
|||||||
var path = require('path'),
|
|
||||||
inquirer = require('inquirer'),
|
|
||||||
Q = require('q'),
|
|
||||||
Generator = require('../../generator'),
|
|
||||||
Generate = require('../../generate');
|
|
||||||
|
|
||||||
module.exports = TabsGenerator;
|
|
||||||
|
|
||||||
function TabsGenerator(options) {
|
|
||||||
Generator.call(this, options);
|
|
||||||
this.directory = 'pages';
|
|
||||||
this.jsClassName += 'Page';
|
|
||||||
this.tabs = [];
|
|
||||||
this.tabNames = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
TabsGenerator.prototype = Object.create(Generator.prototype);
|
|
||||||
|
|
||||||
TabsGenerator.prototype.run = function(){
|
|
||||||
return tabCountPrompt()
|
|
||||||
|
|
||||||
.then(function(numTabs){
|
|
||||||
var promise = Q();
|
|
||||||
|
|
||||||
for (var i = 0, j = parseInt(numTabs); i < j; i++) {
|
|
||||||
promise = promise.then(function(index) {
|
|
||||||
return tabNamePrompt.bind(this)(index);
|
|
||||||
}.bind(this, i));
|
|
||||||
}
|
|
||||||
return promise;
|
|
||||||
}.bind(this))
|
|
||||||
|
|
||||||
.then(function(){
|
|
||||||
var PageGenerator = Generate.loadGenerator('page');
|
|
||||||
|
|
||||||
this.tabNames.forEach(function(tabName){
|
|
||||||
var pageGenerator = new PageGenerator({
|
|
||||||
name: tabName,
|
|
||||||
generator: 'page',
|
|
||||||
appDirectory: this.appDirectory,
|
|
||||||
isTS: this.isTS
|
|
||||||
});
|
|
||||||
|
|
||||||
pageGenerator.run();
|
|
||||||
this.tabs.push(pageGenerator);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
this.makeDirectories();
|
|
||||||
this.renderTemplates();
|
|
||||||
}.bind(this))
|
|
||||||
|
|
||||||
.catch(function(err){
|
|
||||||
console.error(err.stack);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function tabCountPrompt(){
|
|
||||||
var q = Q.defer();
|
|
||||||
|
|
||||||
inquirer.prompt({
|
|
||||||
choices: ['1', '2', '3', '4', '5'],
|
|
||||||
message: 'How many tabs would you like?',
|
|
||||||
name: 'count',
|
|
||||||
type: 'list',
|
|
||||||
validate: validate
|
|
||||||
}, function(result) {
|
|
||||||
q.resolve(result.count);
|
|
||||||
});
|
|
||||||
|
|
||||||
return q.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tabNamePrompt(index){
|
|
||||||
var q = Q.defer();
|
|
||||||
var numberNames = ['first', 'second', 'third', 'fourth', 'fifth'];
|
|
||||||
|
|
||||||
inquirer.prompt({
|
|
||||||
message: 'Enter the ' + numberNames[index] + ' tab name:',
|
|
||||||
name: 'name',
|
|
||||||
type: 'input'
|
|
||||||
}, function(response) {
|
|
||||||
this.tabNames.push(response.name);
|
|
||||||
q.resolve();
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
return q.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function validate(){
|
|
||||||
if (isNaN(parseInt(input))) {
|
|
||||||
// Pass the return value in the done callback
|
|
||||||
return 'You need to provide a number';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
<ion-tabs>
|
|
||||||
<% _.forEach(tabs, function(tab, i) { %>
|
|
||||||
<ion-tab [root]="tab<%= ++i %>Root" tabTitle="<%= tab.name %>" tabIcon="star"></ion-tab>
|
|
||||||
<% }); %>
|
|
||||||
</ion-tabs>
|
|
@ -1,19 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
import { NavController } from 'ionic-angular';
|
|
||||||
<% _.forEach(tabs, function(tab) { %>import { <%= tab.jsClassName %> } from '../<%= tab.fileName %>/<%= tab.fileName %>';
|
|
||||||
<% }); %>
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html'
|
|
||||||
})
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
static get parameters() {
|
|
||||||
return [[NavController]];
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(nav) {
|
|
||||||
// set the root pages for each tab
|
|
||||||
<% _.forEach(tabs, function(tab, i) { %>this.tab<%= ++i %>Root = <%= tab.jsClassName %>;
|
|
||||||
<% }); %>
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
.<%= fileName %> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
import { NavController } from 'ionic-angular';
|
|
||||||
<% _.forEach(tabs, function(tab) { %>import { <%= tab.jsClassName %> } from '../<%= tab.fileName %>/<%= tab.fileName %>';
|
|
||||||
<% }); %>
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html'
|
|
||||||
})
|
|
||||||
export class <%= jsClassName %> {
|
|
||||||
|
|
||||||
constructor(public navCtrl: NavController) {
|
|
||||||
// set the root pages for each tab
|
|
||||||
<% _.forEach(tabs, function(tab, i) { %>this.tab<%= ++i %>Root = <%= tab.jsClassName %>;
|
|
||||||
<% }); %>
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user