From afcfab0a13509c559fa3a2c48487e597d64e19b5 Mon Sep 17 00:00:00 2001 From: Diego Netto Date: Sat, 22 Mar 2014 17:48:51 -0500 Subject: [PATCH] feat(plugins): Install commonly used plugins during scaffolding via checkbox prompts --- app/index.js | 53 +++++++++++++++------ lib/common.js => utils/greeting.js | 4 +- utils/index.js | 4 ++ utils/plugins.js | 76 ++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 17 deletions(-) rename lib/common.js => utils/greeting.js (79%) create mode 100644 utils/index.js create mode 100644 utils/plugins.js diff --git a/app/index.js b/app/index.js index d14e9c5..10abc5e 100644 --- a/app/index.js +++ b/app/index.js @@ -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(); @@ -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 diff --git a/lib/common.js b/utils/greeting.js similarity index 79% rename from lib/common.js rename to utils/greeting.js index d858cb5..9e33645 100644 --- a/lib/common.js +++ b/utils/greeting.js @@ -1,8 +1,6 @@ var chalk = require('chalk'); -var common = module.exports; - -common.ionic = chalk.cyan( +module.exports = chalk.cyan( " _ _" + "\n (_) (_)" + "\n _ ___ _ __ _ ___" + diff --git a/utils/index.js b/utils/index.js new file mode 100644 index 0000000..1973dee --- /dev/null +++ b/utils/index.js @@ -0,0 +1,4 @@ +module.exports = { + greeting: require('./greeting'), + plugins: require('./plugins') +}; diff --git a/utils/plugins.js b/utils/plugins.js new file mode 100644 index 0000000..f034fdf --- /dev/null +++ b/utils/plugins.js @@ -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 + }] + }] +};