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
};
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, fileName: generateOptions.fileName});
try {
//Try to run the generator if it supplies a run method.
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 = array of the tabs to create.
Generate.tabPages = function tabPages(appDirectory, name, tabs) {
Generate.createScaffoldDirectories(appDirectory, name);
// Generate page with tabs:
var tabsfileName = Generate.fileName(name);
var tabsHtml = Generate.generateTabsHtmlTemplate(appDirectory, name, tabs);
var tabsJs = Generate.generateTabsJsTemplate(appDirectory, name, tabs);
// var tabsScss = Generate.generateTabsScssTemplate(appDirectory, name, tabs);
var pagePath = path.join(appDirectory, 'www', 'app', tabsfileName),
jsPath = path.join(pagePath, [tabsfileName, '.js'].join('')),
htmlPath = path.join(pagePath, [tabsfileName, '.html'].join(''));
// scssPath = path.join(pagePath, [tabsfileName, '.scss'].join(''));
tabs.forEach(function(tab) {
Generate.createScaffoldDirectories(appDirectory, tab);
var tabJs = Generate.generateJsTemplate(appDirectory, tab);
var tabHtml = Generate.generateHtmlTemplate(appDirectory, tab);
})
};
// Generate.tabPages = function tabPages(appDirectory, name, tabs) {
// Generate.createScaffoldDirectories(appDirectory, 'tabs', name);
//
// // Generate page with tabs:
// var tabsfileName = Generate.fileName(name);
//
// var tabsHtml = Generate.generateTabsHtmlTemplate(appDirectory, name, tabs);
// var tabsJs = Generate.generateTabsJsTemplate(appDirectory, name, tabs);
// // var tabsScss = Generate.generateTabsScssTemplate(appDirectory, name, tabs);
// var pagePath = path.join(appDirectory, 'app', tabsfileName),
// jsPath = path.join(pagePath, [tabsfileName, '.js'].join('')),
// htmlPath = path.join(pagePath, [tabsfileName, '.html'].join(''));
// // scssPath = path.join(pagePath, [tabsfileName, '.scss'].join(''));
//
// tabs.forEach(function(tab) {
// Generate.createScaffoldDirectories(appDirectory, 'tabs', tab);
// var tabJs = Generate.generateJsTemplate(appDirectory, tab);
// var tabHtml = Generate.generateHtmlTemplate(appDirectory, tab);
//
// })
// };
Generate.generateTabJsTemplate = function generateTabJsTemplate(appDirectory, name) {
throw new Error('not implemented');
@ -201,8 +199,9 @@ Generate.generateTabsJsTemplate = function generateTabsJsTemplate(appDirectory,
};
Generate.createScaffoldDirectories = function createScaffoldDirectories(options) {
console.log('createScaffoldDirectories', options);
// 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);
};

View File

@ -1,15 +1,14 @@
import {Component, NgIf} from 'angular2/angular2';
import {NavController} from 'ionic/ionic';
@Component({
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 %>',
templateUrl: 'app/<%= fileName %>/<%= fileName %>.html'
})
export class <%= jsClassName %> {
constructor() {
constructor(nav: NavController) {
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
*/
Generator.run = function run(options) {
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'components', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('app', 'components');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file);
options.templatePath = templatePath;
options.templatePath = template.file;
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('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -9,16 +9,17 @@ var fs = require('fs'),
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);
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'directives', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('app', 'directives');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file);
options.templatePath = templatePath;
options.templatePath = template.file;
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('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -1,27 +1,23 @@
// 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) {
var fs = require('fs'),
Generator = module.exports,
Generate = require('../../generate'),
path = require('path'),
Q = require('q');
// options.rootDirectory = options.rootDirectory || path.join('www', 'app');
// var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
Generator.run = function run(options) {
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 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);
// });
// };
var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) {
options.templatePath = template.file;
var renderedTemplate = Generate.renderTemplateFromFile(options);
var saveFilePath = path.join(savePath, [options.fileName, 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

@ -8,14 +8,25 @@ export class <%= jsClassName %> {
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.
load() {
if (this.data) {
// already loaded data
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')
.map(res => res.json())
.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;
resolve(this.data);
});
});
}
}

View File

@ -9,16 +9,17 @@ var fs = require('fs'),
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);
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pages', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('app', 'pages');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file);
options.templatePath = templatePath;
options.templatePath = template.file;
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('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -9,17 +9,17 @@ var fs = require('fs'),
appDirectory: App directory of where to save file
*/
Generator.run = function run(options) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pages', fileName: options.fileName});
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
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);
templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file);
options.templatePath = templatePath;
options.templatePath = template.file;
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('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate);

View File

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

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

View File

@ -9,17 +9,17 @@ var fs = require('fs'),
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('www', 'app');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
options.rootDirectory = options.rootDirectory || path.join('app', 'pipes');
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
var templates = Generate.loadGeneratorTemplates(__dirname);
templates.forEach(function(template) {
var templatePath = path.join(__dirname, template.file);
options.templatePath = templatePath;
options.templatePath = template.file;
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('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
fs.writeFileSync(saveFilePath, renderedTemplate);

View File

@ -41,8 +41,10 @@ Generator.promptForTabName = function promptForTabName(tabIndex, options) {
}
Generator.run = function run(options) {
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'tabs', fileName: options.fileName});
//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);
Generator.tabs = [];

View File

@ -1,6 +1,6 @@
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({
templateUrl: 'app/<%= fileName %>/<%= fileName %>.html'