Merge pull request #822 from 3dd13/update-generator-to-new-folder-structure

update generators to work with latest folder structure
This commit is contained in:
Tim Lancina
2016-01-07 09:23:00 -06:00
13 changed files with 133 additions and 121 deletions

View File

@ -49,8 +49,6 @@ Generate.generate = function generate(options) {
template: options.generator template: options.generator
}; };
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, fileName: generateOptions.fileName});
try { try {
//Try to run the generator if it supplies a run method. //Try to run the generator if it supplies a run method.
var generator = Generate.generators[options.generator]; var generator = Generate.generators[options.generator];
@ -144,27 +142,27 @@ Generate.renderTemplateFromFile = function renderTemplateFromFile(options) {
// Tabs - name = name of the page with the tabs, // Tabs - name = name of the page with the tabs,
// tabs = array of the tabs to create. // tabs = array of the tabs to create.
Generate.tabPages = function tabPages(appDirectory, name, tabs) { // Generate.tabPages = function tabPages(appDirectory, name, tabs) {
Generate.createScaffoldDirectories(appDirectory, name); // Generate.createScaffoldDirectories(appDirectory, 'tabs', name);
//
// Generate page with tabs: // // Generate page with tabs:
var tabsfileName = Generate.fileName(name); // var tabsfileName = Generate.fileName(name);
//
var tabsHtml = Generate.generateTabsHtmlTemplate(appDirectory, name, tabs); // var tabsHtml = Generate.generateTabsHtmlTemplate(appDirectory, name, tabs);
var tabsJs = Generate.generateTabsJsTemplate(appDirectory, name, tabs); // var tabsJs = Generate.generateTabsJsTemplate(appDirectory, name, tabs);
// var tabsScss = Generate.generateTabsScssTemplate(appDirectory, name, tabs); // // var tabsScss = Generate.generateTabsScssTemplate(appDirectory, name, tabs);
var pagePath = path.join(appDirectory, 'www', 'app', tabsfileName), // var pagePath = path.join(appDirectory, 'app', tabsfileName),
jsPath = path.join(pagePath, [tabsfileName, '.js'].join('')), // jsPath = path.join(pagePath, [tabsfileName, '.js'].join('')),
htmlPath = path.join(pagePath, [tabsfileName, '.html'].join('')); // htmlPath = path.join(pagePath, [tabsfileName, '.html'].join(''));
// scssPath = path.join(pagePath, [tabsfileName, '.scss'].join('')); // // scssPath = path.join(pagePath, [tabsfileName, '.scss'].join(''));
//
tabs.forEach(function(tab) { // tabs.forEach(function(tab) {
Generate.createScaffoldDirectories(appDirectory, tab); // Generate.createScaffoldDirectories(appDirectory, 'tabs', tab);
var tabJs = Generate.generateJsTemplate(appDirectory, tab); // var tabJs = Generate.generateJsTemplate(appDirectory, tab);
var tabHtml = Generate.generateHtmlTemplate(appDirectory, tab); // var tabHtml = Generate.generateHtmlTemplate(appDirectory, tab);
//
}) // })
}; // };
Generate.generateTabJsTemplate = function generateTabJsTemplate(appDirectory, name) { Generate.generateTabJsTemplate = function generateTabJsTemplate(appDirectory, name) {
throw new Error('not implemented'); throw new Error('not implemented');
@ -201,8 +199,9 @@ Generate.generateTabsJsTemplate = function generateTabsJsTemplate(appDirectory,
}; };
Generate.createScaffoldDirectories = function createScaffoldDirectories(options) { Generate.createScaffoldDirectories = function createScaffoldDirectories(options) {
console.log('createScaffoldDirectories', options);
// Generate.log('Create', options.appDirectory, options.fileName); // Generate.log('Create', options.appDirectory, options.fileName);
var componentPath = path.join(options.appDirectory, 'www', 'app', options.fileName); var componentPath = path.join(options.appDirectory, 'app', options.componentDirectory, options.fileName);
shell.mkdir('-p', componentPath); shell.mkdir('-p', componentPath);
}; };

View File

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

View File

@ -9,16 +9,18 @@ var fs = require('fs'),
appDirectory: App directory of where to save file appDirectory: App directory of where to save file
*/ */
Generator.run = function run(options) { Generator.run = function run(options) {
options.rootDirectory = options.rootDirectory || path.join('www', 'app'); Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'components', fileName: options.fileName});
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
options.rootDirectory = options.rootDirectory || path.join('app', 'components');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname); var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) { templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file); options.templatePath = template.file;
options.templatePath = templatePath;
var renderedTemplate = Generate.renderTemplateFromFile(options); var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join('')); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate); fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -9,16 +9,17 @@ var fs = require('fs'),
appDirectory: App directory of where to save file appDirectory: App directory of where to save file
*/ */
Generator.run = function run(options) { Generator.run = function run(options) {
options.rootDirectory = options.rootDirectory || path.join('www', 'app'); Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'directives', fileName: options.fileName});
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
options.rootDirectory = options.rootDirectory || path.join('app', 'directives');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname); var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) { templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file); options.templatePath = template.file;
options.templatePath = templatePath;
var renderedTemplate = Generate.renderTemplateFromFile(options); var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join('')); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate); fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -1,27 +1,23 @@
// var fs = require('fs'), var fs = require('fs'),
// Generator = module.exports, Generator = module.exports,
// Generate = require('../../generate'), Generate = require('../../generate'),
// path = require('path'), path = require('path'),
// Q = require('q'); 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'); Generator.run = function run(options) {
// var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName); Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'injectables', fileName: options.fileName});
// var templates = Generate.loadGeneratorTemplates(__dirname); options.rootDirectory = options.rootDirectory || path.join('app', 'injectables');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
// templates.forEach(function(template) { var templates = Generate.loadGeneratorTemplates(__dirname);
// var templatePath = path.join(__dirname, template.file);
// options.templatePath = templatePath; templates.forEach(function(template) {
// var renderedTemplate = Generate.renderTemplateFromFile(options); options.templatePath = template.file;
// var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join('')); var renderedTemplate = Generate.renderTemplateFromFile(options);
// // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
// fs.writeFileSync(saveFilePath, renderedTemplate); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
// }); fs.writeFileSync(saveFilePath, renderedTemplate);
// }; });
};

View File

@ -8,14 +8,25 @@ export class <%= jsClassName %> {
this.data = null; this.data = null;
} }
retrieveData() { load() {
//Here, we're going to get a JSON data file, use the `map` call to parse json if (this.data) {
// and finally subscribe to the observable and set our data // already loaded data
//to the value it provides once the http request is complete. return Promise.resolve(this.data);
}
// don't have the data yet
return new Promise(resolve => {
// We're using Angular Http provider to request the data,
// then on the response it'll map the JSON data to a parsed JS object.
// Next we process the data and resolve the promise with the new data.
this.http.get('path/to/data.json') this.http.get('path/to/data.json')
.map(res => res.json()) .map(res => res.json())
.subscribe(data => { .subscribe(data => {
// we've got back the raw data, now generate the core schedule data
// and save the data for later reference
this.data = data; this.data = data;
resolve(this.data);
});
}); });
} }
} }

View File

@ -9,16 +9,17 @@ var fs = require('fs'),
appDirectory: App directory of where to save file appDirectory: App directory of where to save file
*/ */
Generator.run = function run(options) { Generator.run = function run(options) {
options.rootDirectory = options.rootDirectory || path.join('www', 'app'); Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pages', fileName: options.fileName});
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
options.rootDirectory = options.rootDirectory || path.join('app', 'pages');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname); var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) { templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file); options.templatePath = template.file;
options.templatePath = templatePath;
var renderedTemplate = Generate.renderTemplateFromFile(options); var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join('')); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate); fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -9,17 +9,17 @@ var fs = require('fs'),
appDirectory: App directory of where to save file appDirectory: App directory of where to save file
*/ */
Generator.run = function run(options) { Generator.run = function run(options) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pages', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('www', 'app'); options.rootDirectory = options.rootDirectory || path.join('app', 'pages');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName); var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname); var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) { templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file); options.templatePath = template.file;
options.templatePath = templatePath;
var renderedTemplate = Generate.renderTemplateFromFile(options); var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join('')); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate); fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -1,36 +1,36 @@
// /* /*
// ionic g page about ionic g page about
// what should happen: what should happen:
// create directories if not existing: /www, /www/app, /www/app/about create directories if not existing: /www, /www/app, /www/app/about
// create files (about.html, about.scss, about.js) in /www/app/about create files (about.html, about.scss, about.js) in /www/app/about
// */ */
// var fs = require('fs'), var fs = require('fs'),
// Generator = module.exports, Generator = module.exports,
// Generate = require('../../generate'), Generate = require('../../generate'),
// path = require('path'), path = require('path'),
// Q = require('q'); Q = require('q');
// /* /*
// Run: generate a page template from the name and save Run: generate a page template from the name and save
// it in the desired app directory it in the desired app directory
// @options @options
// name: Page name name: Page name
// appDirectory: App directory of where to save file appDirectory: App directory of where to save file
// */ */
// Generator.run = function run(options) { Generator.run = function run(options) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pages', fileName: options.fileName});
// // Generate.defaultTemplates(options) // Generate.defaultTemplates(options)
// // options.rootDirectory = options.rootDirectory || path.join('www', 'app'); options.rootDirectory = options.rootDirectory || path.join('app', 'pages');
// // var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName); var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
// // var templates = Generate.loadGeneratorTemplates(__dirname); var templates = Generate.loadGeneratorTemplates(__dirname);
// // templates.forEach(function(template) { templates.forEach(function(template) {
// // var templatePath = path.join(__dirname, template.file); options.templatePath = template.file;
// // options.templatePath = templatePath; var renderedTemplate = Generate.renderTemplateFromFile(options);
// // var renderedTemplate = Generate.renderTemplateFromFile(options); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// // var saveFilePath = path.join(savePath, [options.fileName, template.type].join('')); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
// // // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
// // console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); fs.writeFileSync(saveFilePath, renderedTemplate);
// // fs.writeFileSync(saveFilePath, renderedTemplate); });
// // }); };
// };

View File

@ -1,4 +1,5 @@
import {Page, NavController} from 'ionic/ionic'; import {Page, NavController} from 'ionic/ionic';
@Page({ @Page({
templateUrl: 'app/<%= fileName %>/<%= fileName %>.html', templateUrl: 'app/<%= fileName %>/<%= fileName %>.html',
}) })

View File

@ -9,17 +9,17 @@ var fs = require('fs'),
appDirectory: App directory of where to save file appDirectory: App directory of where to save file
*/ */
Generator.run = function run(options) { Generator.run = function run(options) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pipes', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('www', 'app'); options.rootDirectory = options.rootDirectory || path.join('app', 'pipes');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName); var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname); var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) { templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file); options.templatePath = template.file;
options.templatePath = templatePath;
var renderedTemplate = Generate.renderTemplateFromFile(options); var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join('')); var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath); // console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath)); console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate); fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -41,8 +41,10 @@ Generator.promptForTabName = function promptForTabName(tabIndex, options) {
} }
Generator.run = function run(options) { Generator.run = function run(options) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'tabs', fileName: options.fileName});
//Need to query user for tabs: //Need to query user for tabs:
options.rootDirectory = options.rootDirectory || path.join('www', 'app'); options.rootDirectory = options.rootDirectory || path.join('app', 'tabs');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName); var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
Generator.tabs = []; Generator.tabs = [];

View File

@ -1,6 +1,6 @@
import {NavController, Page} from 'ionic/ionic'; import {NavController, Page} from 'ionic/ionic';
<% _.forEach(tabs, function(tab) { %>import {<%= tab.jsClassName %>} from '../<%= tab.fileName %>/<%= tab.fileName %>'; <% _.forEach(tabs, function(tab) { %>import {<%= tab.jsClassName %>} from '../../<%= tab.fileName %>/<%= tab.fileName %>';
<% }); %> <% }); %>
@Page({ @Page({
templateUrl: 'app/<%= fileName %>/<%= fileName %>.html' templateUrl: 'app/<%= fileName %>/<%= fileName %>.html'