Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
#358, #364: prompts - move to separate file and test for proper forma…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
gruppjo committed Jun 8, 2016
1 parent 34e91fe commit 85a52cd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 75 deletions.
78 changes: 3 additions & 75 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var fs = require('fs');
var utils = require('../../utils/utils.js');
var config = require('../../utils/config.js');
var bowerConfig = require('./sources/bower-config.js');
var cordovaConfig = require('./sources/cordova-config.js');
var prompts = require('./sources/prompts.js');
var sampleAnswers = require('./sources/sample-answers.js');

module.exports = yeoman.Base.extend({
Expand Down Expand Up @@ -49,71 +49,13 @@ module.exports = yeoman.Base.extend({
this.appName = this.options['app-name'];
}

var prompts = [
// appName
{
type: 'input',
name: 'appName',
message: '\nEnter a name for your project \nThis name will be displayed below the app icon.\n',
validate: utils.validateAppName,
when: function () {
// Show this prompt only if appName is not already set
return !this.appName;
}.bind(this)
},
// appId
{
type: 'input',
name: 'appId',
message: '\nEnter an app identifier for your project \ne.g. com.company.project\n',
validate: utils.validateAppId
},
// ionic css
{
type: 'list',
name: 'ionicCss',
message: '\nInclude Ionic styles as CSS or Sass\n',
choices: [
{
name: 'Ionic CSS (faster, for starters)',
value: true
},
{
name: 'Ionic Sass (more flexible, for pros)',
value: false
}
]
},
// bower packages
{
type: 'checkbox',
name: 'bowerPackages',
message: '\nChoose additional bower packages \nBesides angular, ionic, angular-ui-router and ngCordova.\n',
choices: bowerConfig.optional
},
// select platforms
{
type: 'checkbox',
name: 'platforms',
message: '\nSelect Cordova platforms \nOnly works if you have the platforms correctly set up.\n',
choices: cordovaConfig.platforms
},
// select plugins
{
type: 'checkbox',
name: 'plugins',
message: '\nSelect Cordova plugins \nInstall more later at any time.\n',
choices: cordovaConfig.plugins
},
];

// prompt and save results in this.answers
if (!this.options['skip-prompts']) {
// tell yeoman we're doing asynchronous stuff here
// so it can wait with subsequent tasks
var done = this.async();

this.prompt(prompts, function (answers) { // prompt
this.prompt(prompts.main, function (answers) { // prompt
this.answers = answers;

done();
Expand Down Expand Up @@ -255,21 +197,7 @@ module.exports = yeoman.Base.extend({
if (!this.options['skip-prompts']) {
// ecosystem prompts
var done = this.async();
this.prompt([{
type: 'checkbox',
name: 'ecosystems',
message: '\nIntegrate into the following ecosystems \nCan als be done later, check out the README for further instructions.\n',
choices: [{
name: 'Ionic Platform (beta)',
value: 'ionic-platform'
}, {
name: 'Appmobi (have your APP_NAME, PROJECT_ID & CONFIG_URL ready)',
value: 'appmobi'
}, {
name: 'ApiOmat (beta)',
value: 'apiomat'
}]
}], function (answers) { // prompt
this.prompt(prompts.ecosystems, function (answers) { // prompt
this.answers.ecosystems = answers.ecosystems;
done();
}.bind(this));
Expand Down
82 changes: 82 additions & 0 deletions generators/app/sources/prompts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict';

var utils = require('../../../utils/utils.js');
var bowerConfig = require('./bower-config.js');
var cordovaConfig = require('./cordova-config.js');

module.exports = {
main: [
// appName
{
type: 'input',
name: 'appName',
message: '\nEnter a name for your project \nThis name will be displayed below the app icon.\n',
validate: utils.validateAppName,
when: function () {
// Show this prompt only if appName is not already set
return !this.appName;
}.bind(this)
},
// appId
{
type: 'input',
name: 'appId',
message: '\nEnter an app identifier for your project \ne.g. com.company.project\n',
validate: utils.validateAppId
},
// ionic css
{
type: 'list',
name: 'ionicCss',
message: '\nInclude Ionic styles as CSS or Sass\n',
choices: [
{
name: 'Ionic CSS (faster, for starters)',
value: true
},
{
name: 'Ionic Sass (more flexible, for pros)',
value: false
}
]
},
// bower packages
{
type: 'checkbox',
name: 'bowerPackages',
message: '\nChoose additional bower packages \nBesides angular, ionic, angular-ui-router and ngCordova.\n',
choices: bowerConfig.optional
},
// select platforms
{
type: 'checkbox',
name: 'platforms',
message: '\nSelect Cordova platforms \nOnly works if you have the platforms correctly set up.\n',
choices: cordovaConfig.platforms
},
// select plugins
{
type: 'checkbox',
name: 'plugins',
message: '\nSelect Cordova plugins \nInstall more later at any time.\n',
choices: cordovaConfig.plugins
},
],
ecosystems: [
{
type: 'checkbox',
name: 'ecosystems',
message: '\nIntegrate into the following ecosystems \nCan als be done later, check out the README for further instructions.\n',
choices: [{
name: 'Ionic Platform (beta)',
value: 'ionic-platform'
}, {
name: 'Appmobi (have your APP_NAME, PROJECT_ID & CONFIG_URL ready)',
value: 'appmobi'
}, {
name: 'ApiOmat (beta)',
value: 'apiomat'
}]
}
]
};
17 changes: 17 additions & 0 deletions test/app-prompts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var assert = require('yeoman-assert');
var prompts = require('../generators/app/sources/prompts.js');

describe('generators/app/prompts', function () {
it('prompts have proper formatting with \\n at beginning and end', function () {
for (var key in prompts) {
if (prompts.hasOwnProperty(key)) {
for (var i = 0, prompt; (prompt = prompts[key][i]); i++) {
assert.equal(prompt.message[0], '\n');
assert.equal(prompt.message[prompt.message.length - 1], '\n');
}
}
}
});
});

0 comments on commit 85a52cd

Please sign in to comment.