Skip to content

Commit

Permalink
feat(plugins): Install commonly used plugins during scaffolding via c…
Browse files Browse the repository at this point in the history
…heckbox prompts
  • Loading branch information
diegonetto committed Mar 22, 2014
1 parent 82509e0 commit afcfab0
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 17 deletions.
53 changes: 39 additions & 14 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var mout = require('mout').string;
var mout = require('mout');
var cordova = require('cordova');
var chalk = require('chalk');
var common = require('../lib/common');
var ionicUtils = require('../utils');

var IonicGenerator = module.exports = function IonicGenerator(args, options) {
yeoman.generators.Base.apply(this, arguments);
console.log(ionicUtils.greeting);

this.argument('appName', { type: String, required: false });
this.appName = this.appName || path.basename(process.cwd());
this.appName = mout.pascalCase(this.appName);
this.appName = mout.string.pascalCase(this.appName);
this.appId = 'com.example.' + this.appName;
this.appPath = 'app';
this.root = process.cwd();
Expand All @@ -26,34 +27,58 @@ var IonicGenerator = module.exports = function IonicGenerator(args, options) {

util.inherits(IonicGenerator, yeoman.generators.Base);

IonicGenerator.prototype.init = function init() {
console.log(common.ionic);
IonicGenerator.prototype.askForCompass = function askForCompass() {
var done = this.async();

this.prompt([{
type: 'confirm',
name: 'compass',
message: 'Would you like to use Sass (with Compass)?',
default: true
}], function (props) {
this.compass = props.compass;

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

IonicGenerator.prototype.cordovaInit = function cordovaInit() {
var done = this.async();
cordova.create('.', this.appId, this.appName, function (error) {
if (error) {
console.log(chalk.yellow(error.message + ': Skipping `cordova create`'));
} else {
console.log(chalk.yellow('Creating a new cordova project with name "' + this.appName + '" and id "' + this.appId + '"'));
console.log(chalk.yellow('Created a new Cordova project with name "' + this.appName + '" and id "' + this.appId + '"'));
}
done();
}.bind(this));
};

IonicGenerator.prototype.askForCompass = function askForCompass() {
IonicGenerator.prototype.askForPlugins = function askForPlugins() {
var done = this.async();

this.prompt([{
type: 'confirm',
name: 'compass',
message: 'Would you like to use Sass (with Compass)?',
default: true
}], function (props) {
this.compass = props.compass;
this.prompt(ionicUtils.plugins.prompts, function (props) {
this.plugins = props.plugins;

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

IonicGenerator.prototype.installPlugins = function installPlugins() {
console.log(chalk.yellow('\nInstall plugins registered at plugins.cordova.io: ') + chalk.green('grunt plugin:add:org.apache.cordova.globalization'));
console.log(chalk.yellow('Or install plugins direct from source: ') + chalk.green('grunt plugin:add:https://github.com/apache/cordova-plugin-console.git\n'));
if (this.plugins.length > 0) {
var done = this.async();
console.log(chalk.yellow('Installing selected Cordova plugins, please wait.'));
cordova.plugin('add', this.plugins, function (error) {
if (error) {
console.log(chalk.red(error.message));
}
done();
});
}
};

IonicGenerator.prototype.setupEnv = function setupEnv() {
// Copies the contents of the generator example app
// directory into your users new application path
Expand Down
4 changes: 1 addition & 3 deletions lib/common.js → utils/greeting.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var chalk = require('chalk');

var common = module.exports;

common.ionic = chalk.cyan(
module.exports = chalk.cyan(
" _ _" +
"\n (_) (_)" +
"\n _ ___ _ __ _ ___" +
Expand Down
4 changes: 4 additions & 0 deletions utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
greeting: require('./greeting'),
plugins: require('./plugins')
};
76 changes: 76 additions & 0 deletions utils/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module.exports = {
prompts: [{
type: 'checkbox',
name: 'plugins',
message: 'Which Cordova plugins would you like to include?',
choices: [{
value: 'org.apache.cordova.console',
name: 'org.apache.cordova.console',
checked: true
}, {
value: 'org.apache.cordova.device',
name: 'org.apache.cordova.device',
checked: true
}, {
value: 'org.apache.cordova.network-information',
name: 'org.apache.cordova.network-information',
checked: false
}, {
value: 'org.apache.cordova.splashscreen',
name: 'org.apache.cordova.splashscreen',
checked: false
}, {
value: 'org.apache.cordova.battery-status',
name: 'org.apache.cordova.battery-status',
checked: false
}, {
value: 'org.apache.cordova.device-motion',
name: 'org.apache.cordova.device-motion',
checked: false
}, {
value: 'org.apache.cordova.device-orientation',
name: 'org.apache.cordova.device-orientation',
checked: false
}, {
value: 'org.apache.cordova.geolocation',
name: 'org.apache.cordova.geolocation',
checked: false
}, {
value: 'org.apache.cordova.camera',
name: 'org.apache.cordova.camera',
checked: false
}, {
value: 'org.apache.cordova.media-capture',
name: 'org.apache.cordova.media-capture',
checked: false
}, {
value: 'org.apache.cordova.media',
name: 'org.apache.cordova.media',
checked: false
}, {
value: 'org.apache.cordova.file',
name: 'org.apache.cordova.file',
checked: false
}, {
value: 'org.apache.cordova.file-transfer',
name: 'org.apache.cordova.file-transfer',
checked: false
}, {
value: 'org.apache.cordova.dialogs',
name: 'org.apache.cordova.dialogs',
checked: false
}, {
value: 'org.apache.cordova.vibration',
name: 'org.apache.cordova.vibration',
checked: false
}, {
value: 'org.apache.cordova.contacts',
name: 'org.apache.cordova.contacts',
checked: false
}, {
value: 'org.apache.cordova.inappbrowser',
name: 'org.apache.cordova.inappbrowser',
checked: false
}]
}]
};

0 comments on commit afcfab0

Please sign in to comment.