Skip to content

Commit

Permalink
major refactor to simplify and reuse utils etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Aug 2, 2015
1 parent 55a8e9a commit ca56d03
Show file tree
Hide file tree
Showing 21 changed files with 491 additions and 424 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ Generate an [Aurelia](aurelia.io) Quick Start project with: - [Aurelia CLI](http

Generator tested on MacOSX via `npm link`

- `aurelia-ts`
- `aurelia-ts:plugins`
- `aurelia-ts:cli`
- `aurelia-ts:styles`
- `aurelia-ts:layout`
- `aurelia-ts:typescript`
- `aurelia-ts:state`
- `aurelia-ts:amp` - Ampersand models

Now includes IE9 support via polyfill for mutationobservers ;)
- `aurelia-ts` (new app)
- `aurelia-ts:decorate` (decorate app)
- `aurelia-ts:plugins` (add plugins)
- `aurelia-ts:cli` (add CLI)
- `aurelia-ts:styles` (add CSS preprocessors: SASS/Stylus )
- `aurelia-ts:layout` (add ui/layout framework:)
- `aurelia-ts:typescript` (add typescript)
- `aurelia-ts:state` (add state or stores)
- `aurelia-ts:amp` - (add Ampersand models/collections)

Now includes IE9 support ;)

### Layout Frameworks

Expand Down
145 changes: 1 addition & 144 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,13 @@ require('sugar');

var generator;

function normalizeName(name) {
return name.replace(/ /,'-').toLowerCase();
}

function info(msg) {
console.log(msg);
}

function command(msg) {
console.log(' $ ' + msg);
}

var uiFrameworkMap = {
bs: 'Bootstrap',
zurb: 'Foundation',
sem: 'Semantic-UI',
f7: 'Framework7'
};

function runJspmInstall(list) {
if (!list || list.length == 0) return;
list.unshift('install');
generator.spawnCommand('jspm', list);
}

function jspmInstall(names) {
var params = names.map(function(name) {
var resolved = jspmInstalls[name];
if (!resolved) {
resolved = name;
}
return resolved;
});
runJspmInstall(params);
}

module.exports = yeoman.generators.Base.extend({

Expand Down Expand Up @@ -114,69 +86,8 @@ module.exports = yeoman.generators.Base.extend({
name: 'authorName',
message: 'Your name',
default: this.props.authorName
}, {
type: 'confirm',
name: 'installStyles',
message: 'Install Styles',
default: true
}, {
type: 'confirm',
name: 'installCLI',
message: 'Install Aurelia CLI',
default: true
}, {
type: 'confirm',
name: 'ie9Support',
message: 'Support IE9',
default: true
}];

var pluginsPrompt ={
type: 'confirm',
name: 'installPlugins',
message: 'Install Aurelia Plugins',
default: false
};

// should not prompt to install
// if options are passed to force install
var typeScriptPrompt = {
type: 'confirm',
name: 'installTypeScript',
message: 'Install TypeScript',
default: false
};

var vsPrompt = {
type: 'confirm',
name: 'visualStudio',
message: 'Visual Studio',
default: false
};

var layoutPrompt = {
type: 'confirm',
name: 'installLayout',
message: 'Install UI Frameworks',
default: true
};

if (!this.props.vs) {
prompts.push(vsPrompt);
}

if (!this.props.plugins) {
prompts.push(pluginsPrompt);
}

if (!this.props.ts) {
prompts.push(typeScriptPrompt);
}

if (!this.props.uiFramework) {
prompts.push(layoutPrompt);
}

// info('Create Aurelia Application:');
this.prompt(prompts, function(answers) {
this.title = answers.title;
Expand All @@ -187,12 +98,6 @@ module.exports = yeoman.generators.Base.extend({
this.authorEmail = answers.authorEmail;
this.githubAccount = answers.githubAccount;

this.installStyles = answers.installStyles;
this.installLayout = answers.installLayout || this.props.uiFramework;
this.installCLI = answers.installCLI || this.props.cli;
this.installPlugins = answers.installPlugins || this.props.plugins;
this.installTypeScript = answers.installTypeScript || this.props.ts;

this.visualStudio = answers.visualStudio || this.props.vs;
this.ie9Support = answers.ie9Support;

Expand Down Expand Up @@ -298,55 +203,7 @@ module.exports = yeoman.generators.Base.extend({
},

end: function() {
if (this.installStyles) {
this.composeWith('aurelia-ts:styles', {
options: {
styleLang: this.props.styleLang,
sass: this.options.sass,
stylus: this.options.stylus
}
});
}

if (this.installTypeScript) {
this.composeWith('aurelia-ts:typescript', {
options: {
cssFrameworks: this.cssFrameworks,
githubAccount: this.githubAccount,
authorName: this.authorName,
authorEmail: this.authorEmail,
appDesc: this.appDesc,
appName: this.appName
}
});
}

if (this.installLayout) {
this.composeWith('aurelia-ts:layout', {
options: {
appTitle: this.appTitle,
appDesc: this.appDesc,
ui: this.options.ui,
fa: this.options.fa
}
});
}

if (this.installPlugins) {
this.composeWith('aurelia-ts:plugins', {
options: {
bootstrap: this.bootstrap
}
});
}

if (this.installCLI) {
this.composeWith('aurelia-ts:cli', {
options: {}
});
}

this.composeWith('aurelia-ts:state', {
this.composeWith('aurelia-ts:decorate', {
options: {}
});
}
Expand Down
170 changes: 170 additions & 0 deletions generators/decorate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
require('sugar');

var fs = require('fs');

var generator;

function info(msg) {
console.log(msg);
}

function command(msg) {
console.log(' $ ' + msg);
}

module.exports = yeoman.generators.Base.extend({

// note: arguments and options should be defined in the constructor.
constructor: function() {
yeoman.generators.Base.apply(this, arguments);
this.option('ts'); // typescript
this.option('vs'); // visual studio
this.option('fa'); // font awesome
this.option('cli'); // aurelia CLI
this.option('plugins');

this.props = {};
this.props.vs = this.options.vs;
this.props.ts = this.options.ts;
this.props.fa = this.options.fa;
this.props.plugins = this.options.plugins;

generator = this;
},

initializing: function() {
},

prompting: function() {
var done = this.async();
var prompts = [{
type: 'confirm',
name: 'installStyles',
message: 'Install Styles',
default: true
}, {
type: 'confirm',
name: 'installCLI',
message: 'Install Aurelia CLI',
default: true
}];

var pluginsPrompt ={
type: 'confirm',
name: 'installPlugins',
message: 'Install Aurelia Plugins',
default: false
};

// should not prompt to install
// if options are passed to force install
var typeScriptPrompt = {
type: 'confirm',
name: 'installTypeScript',
message: 'Install TypeScript',
default: false
};

var vsPrompt = {
type: 'confirm',
name: 'visualStudio',
message: 'Visual Studio',
default: false
};

var layoutPrompt = {
type: 'confirm',
name: 'installLayout',
message: 'Install UI Frameworks',
default: true
};

if (!this.props.vs) {
prompts.push(vsPrompt);
}

if (!this.props.plugins) {
prompts.push(pluginsPrompt);
}

if (!this.props.ts) {
prompts.push(typeScriptPrompt);
}

if (!this.props.uiFramework) {
prompts.push(layoutPrompt);
}

// info('Install Aurelia CLI:');

this.prompt(prompts, function(answers) {

this.installStyles = answers.installStyles;
this.installLayout = answers.installLayout || this.props.uiFramework;
this.installCLI = answers.installCLI || this.props.cli;
this.installPlugins = answers.installPlugins || this.props.plugins;
this.installTypeScript = answers.installTypeScript || this.props.ts;
// this.config.save();

done();
}.bind(this));
},

end: function() {
if (this.installStyles) {
this.composeWith('aurelia-ts:styles', {
options: {
styleLang: this.props.styleLang,
sass: this.options.sass,
stylus: this.options.stylus
}
});
}

if (this.installTypeScript) {
this.composeWith('aurelia-ts:typescript', {
options: {
cssFrameworks: this.cssFrameworks,
githubAccount: this.githubAccount,
authorName: this.authorName,
authorEmail: this.authorEmail,
appDesc: this.appDesc,
appName: this.appName
}
});
}

if (this.installLayout) {
this.composeWith('aurelia-ts:layout', {
options: {
appTitle: this.appTitle,
appDesc: this.appDesc,
ui: this.options.ui,
fa: this.options.fa
}
});
}

if (this.installPlugins) {
this.composeWith('aurelia-ts:plugins', {
options: {
bootstrap: this.bootstrap
}
});
}

if (this.installCLI) {
this.composeWith('aurelia-ts:cli', {
options: {}
});
}

this.composeWith('aurelia-ts:state', {
options: {}
});
}
});

0 comments on commit ca56d03

Please sign in to comment.