From a8d8f9ca439142b505c539587d363dd961f07698 Mon Sep 17 00:00:00 2001 From: gruppjo Date: Wed, 16 Mar 2016 21:47:06 +0100 Subject: [PATCH] work on #341: integrated appmobi in generator/app --- generators/app/index.js | 56 ++++++++++++++++++------ generators/app/sources/sample-answers.js | 9 +++- test/app.js | 23 ++++++++++ 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/generators/app/index.js b/generators/app/index.js index 58f348b..da9f718 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -139,12 +139,20 @@ module.exports = yeoman.Base.extend({ } // save appModule in answers this.answers.appModule = utils.moduleName(this.answers.appName); - - // store answers in .yo-rc.json - this.config.set('answers', this.answers); }, writing: { + subgenerators: function () { + // create main module + this.composeWith('m-ionic:module', { + arguments: config.DEFAULT_MODULE, + options: { + mainModule: true, + ionicCss: this.answers.ionicCss, + 'skip-prompts': this.options['skip-prompts'] + } + }); + }, cordova: function () { if (this.update) { @@ -242,16 +250,38 @@ module.exports = yeoman.Base.extend({ this.write(this.destinationRoot() + '/README.md', readme); }, - subgenerators: function () { - // create main module - this.composeWith('m-ionic:module', { - arguments: config.DEFAULT_MODULE, - options: { - mainModule: true, - ionicCss: this.answers.ionicCss, - 'skip-prompts': this.options['skip-prompts'] - } - }); + ecosystemPrompts: function () { + if (!this.options['skip-prompts']) { + // ecosystem prompts + var done = this.async(); + this.prompt([{ + type: 'checkbox', + name: 'ecosystems', + message: 'integrate into the following ecosystems: (can still be done later)', + choices: [{ + name: 'appmobi - have your APP_NAME, PROJECT_ID & CONFIG_URL ready', + value: 'appmobi' + }] + }], function (answers) { // prompt + this.answers.ecosystems = answers.ecosystems; + done(); + }.bind(this)); + } + }, + + ecosystemIntegration: function () { + // store answers in .yo-rc.json, all questions now asked + this.config.set('answers', this.answers); + + if (this.answers.ecosystems.indexOf('appmobi') > -1) { + this.composeWith('generator-appmobi', { + options: { + 'skip-sdk': this.options['skip-sdk'] + } + }, { + local: require.resolve('generator-appmobi/generators/app/index.js') + }); + } } }, diff --git a/generators/app/sources/sample-answers.js b/generators/app/sources/sample-answers.js index 37e76d5..2b1c23a 100644 --- a/generators/app/sources/sample-answers.js +++ b/generators/app/sources/sample-answers.js @@ -27,7 +27,8 @@ module.exports = { 'cordova-plugin-dialogs', 'ionic-plugin-keyboard' ], - template: 'tabs' + template: 'tabs', + ecosystems: [] }, /** @@ -55,6 +56,12 @@ module.exports = { }); standardCopy.bowerPackages = bowerPackages; } + if (options && options.appmobi) { + standardCopy.ecosystems.push('appmobi'); + standardCopy['APP_NAME'] = '0f50dcbf-5c79-41ee-b038-330de3ee07a5.Test'; + standardCopy['PROJECT_ID'] = '5buk7ayx'; + standardCopy['CONFIG_URL'] = 'https://cloud.appmobi.com'; + } return standardCopy; }, diff --git a/test/app.js b/test/app.js index e74f910..ecf207f 100644 --- a/test/app.js +++ b/test/app.js @@ -201,6 +201,29 @@ describe('m', function () { }); }); + describe('appmobi', function () { + var answers = sampleAnswers.getStandard({appmobi: true}); + + before(function (done) { + helpers.run(path.join(__dirname, '../generators/app')) + .withGenerators([ // configure path to subgenerators + path.join(__dirname, '../generators/appmobi'), + path.join(__dirname, '../generators/module'), + path.join(__dirname, '../generators/constant'), + path.join(__dirname, '../generators/controller'), + path.join(__dirname, '../generators/template'), + path.join(__dirname, '../generators/service') + ]) + .withOptions({ 'skip-install': true, 'skip-sdk': true }) // execute with options + .withPrompts(answers) // answer prompts + .on('end', done); + }); + + it('runs', function () { + assert(true); + }); + }); + describe('--app-name=tradecore', function () { var answers = sampleAnswers.getForAppNameOption();