diff --git a/blueprints/cordova-init/index.js b/blueprints/cordova-init/index.js index cc4d5f4..7b4a902 100644 --- a/blueprints/cordova-init/index.js +++ b/blueprints/cordova-init/index.js @@ -1,6 +1,7 @@ var projectWithConfig = require('../../lib/models/project-with-config'); var Promise = require('../../lib/ext/promise'); var stringUtils = require('../../lib/utils/string'); +var defaultPlatform = require('../../lib/utils/default-platform'); module.exports = { locals: function(options) { @@ -13,8 +14,8 @@ module.exports = { }, afterInstall: function(options) { - this.options = options.entity.options; - this.options.platform = options.platform || 'ios'; + this.options = options.entity.options; + this.options.platform = options.platform || defaultPlatform(this.project); projectWithConfig(this.project, options.entity.name); diff --git a/docs/getting-started.md b/docs/getting-started.md index b45f9f1..331d3a2 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1,7 +1,7 @@ # Getting Started This guide will walk you through setting up your first app with -ember-cli-cordova. +ember-cli-cordova. ## Prerequisites @@ -22,9 +22,9 @@ After that's set up, we need to add the ember-cli-cordova addon to the applicati npm install --save-dev ember-cli-cordova ``` -Ember cli-cordova requires cordova. If you don't have cordova, use this line to install it. +Ember cli-cordova requires cordova. If you don't have cordova, use this line to install it. -``` +``` npm install -g cordova ``` @@ -33,7 +33,7 @@ ember-cli-cordova. You pass in the com domain identifier that you want to use with your app. It can be anything you like as long as it's unique. This matters if you plan on releasing it to the app stores. It takes an optional `platform` argument that defaults to `ios`. If you want to generate an android project you -would pass in `--platform=android` at the end. +would pass in `--platform=android` at the end or set your default platform in [cordova configuration](https://github.com/poetic/ember-cli-cordova/blob/master/docs/configuration.md). ```sh ember generate cordova-init com.poeticsystems.hello diff --git a/lib/commands/build.js b/lib/commands/build.js index a8cce02..e0a0835 100644 --- a/lib/commands/build.js +++ b/lib/commands/build.js @@ -1,7 +1,8 @@ 'use strict'; -var path = require('path'); -var chalk = require('chalk'); +var path = require('path'); +var chalk = require('chalk'); +var defaultPlatform = require('../utils/default-platform'); module.exports = { name: 'cordova:build', @@ -11,10 +12,11 @@ module.exports = { availableOptions: [ { name: 'environment', type: String, default: 'development' }, - { name: 'platform', type: String, default: 'ios' } + { name: 'platform', type: String } ], run: function(options) { - return require('../tasks/build')(options.environment, options.platform, this.project)(); + var platform = options.platform || defaultPlatform(this.project); + return require('../tasks/build')(options.environment, platform, this.project)(); } }; diff --git a/lib/commands/open.js b/lib/commands/open.js index d5176e6..936c64f 100644 --- a/lib/commands/open.js +++ b/lib/commands/open.js @@ -1,6 +1,7 @@ 'use strict'; -var path = require('path'); +var path = require('path'); +var defaultPlatform = require('../utils/default-platform'); module.exports = { name: 'cordova:open', @@ -9,11 +10,12 @@ module.exports = { works: 'insideProject', availableOptions: [ - { name: 'platform', type: String, default: 'ios' }, + { name: 'platform', type: String }, { name: 'application', type: String} ], run: function(options) { - return require('../tasks/open')(this.project, options.platform, options.application)(); + var platform = options.platform || defaultPlatform(this.project); + return require('../tasks/open')(this.project, platform, options.application)(); } }; diff --git a/lib/tasks/archive.js b/lib/tasks/archive.js index 0ccb654..51e56dc 100644 --- a/lib/tasks/archive.js +++ b/lib/tasks/archive.js @@ -3,6 +3,7 @@ var path = require('path'); var runCommand = require('../utils/run-command'); var Promise = require('../ext/promise'); +var defaultPlatform = require('../utils/default-platform'); module.exports = function(version, options, project) { var config = project.cordovaConfig; @@ -13,10 +14,9 @@ module.exports = function(version, options, project) { updateXml = require('./update-config-xml-version')(version, project); } - var platform = options.platform || 'ios'; + var platform = options.platform || defaultPlatform(project); var build = require('./build')(options.environment, platform, project); - if(platform === 'ios') { var iosPath = path.join(project.root, 'cordova', 'platforms/ios'); var archiveCommand = 'xcodebuild -scheme ' + config.name + ' archive'; diff --git a/lib/tasks/post-build.js b/lib/tasks/post-build.js index e61d557..927e7e3 100644 --- a/lib/tasks/post-build.js +++ b/lib/tasks/post-build.js @@ -1,14 +1,15 @@ 'use strict'; -var runCommand = require('../utils/run-command'); -var path = require('path'); -var chalk = require('chalk'); -var ui = require('../ui'); -var Promise = require('../ext/promise'); +var runCommand = require('../utils/run-command'); +var defaultPlatform = require('../utils/default-platform'); +var path = require('path'); +var chalk = require('chalk'); +var ui = require('../ui'); +var Promise = require('../ext/promise'); function createCommand(project, options) { - var platform = options.platform || 'ios'; - var command = 'cordova build ' + platform; + var platform = options.platform || defaultPlatform(this.project); + var command = 'cordova build ' + platform; if (options.emulate) { command += ' && cordova emulate ' + platform; diff --git a/lib/utils/default-platform.js b/lib/utils/default-platform.js new file mode 100644 index 0000000..1f64f59 --- /dev/null +++ b/lib/utils/default-platform.js @@ -0,0 +1,4 @@ +module.exports = function defaultPlatform(project) { + var config = project.config().cordova || {} + return config.platform || 'ios'; +}