Skip to content

Commit 38e2e68

Browse files
authored
Merge pull request #101 from isleofcode/develop
Develop
2 parents e0e3a6f + ba63261 commit 38e2e68

File tree

12 files changed

+87
-22
lines changed

12 files changed

+87
-22
lines changed

docs/cli.md

+15
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ Passes commands straight to cordova, without interference.
8585

8686
#### Examples
8787
+ `ember cordova platform add ios`
88+
89+
##Setting default Platform
90+
91+
If you are only ever building for one platform, you can set a default
92+
in config.environment.js.
93+
94+
This is handy if the defaults don't work out for you, e.g. you are
95+
only shipping for Android.
96+
97+
in config/environment.js:
98+
```
99+
cordova: {
100+
platform: 'android'
101+
}
102+
```

docs/livereload.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ or ios) and any options accepted by Ember serve.
2929
## Advanced Configuration
3030

3131
There are times you may find yourself wanting to enable live-reload
32-
from a remote host and port, or to customize a local url.
32+
from a remote host and port, or to customize a local url because we are
33+
not detecting it correctly.
3334

3435
## Customize the device live-reload url
3536

3637
In all cases below, `<url>` refers to the full url including protocol,
37-
host, and port.
38+
host, and port, e.g. http://localhost:4200
3839

3940
*via commandline arg*
4041

@@ -48,11 +49,13 @@ or
4849
ember cdv:s -r "<url>"
4950
```
5051

51-
*via .ember-cli*
52+
*via config/environment.js*
5253

5354
```json
5455
{
55-
deviceLiveReloadUrl: "<url>"
56+
cordova: {
57+
reloadUrl: "<url>"
58+
}
5659
}
5760
```
5861

index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ var fs = require('fs');
1313
module.exports = {
1414
name: 'ember-cordova',
1515

16-
config: function(/* env, baseConfig */) {
16+
config: function(env, baseConfig) {
1717
if (this.project.targetIsCordova) {
1818
var conf = { cordova: {} };
1919
if (!!this.project.RELOAD_PORT) {
2020
//If cordova live reload, set the reload url
21-
var networkAddress = getNetworkIp();
22-
var deviceServerUrl = 'http://' + networkAddress + ':' + this.project.RELOAD_PORT;
21+
if (baseConfig.cordova && baseConfig.cordova.reloadUrl) {
22+
conf.cordova.reloadUrl = baseConfig.cordova.reloadUrl;
23+
} else {
24+
var networkAddress = getNetworkIp();
25+
var deviceServerUrl = 'http://' + networkAddress + ':' + this.project.RELOAD_PORT;
2326

24-
conf.cordova.reloadUrl = deviceServerUrl;
27+
conf.cordova.reloadUrl = deviceServerUrl;
28+
}
2529
}
2630

2731
return conf;

lib/commands/build.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var CdvBuildTask = require('../tasks/cordova-build');
44
var HookTask = require('../tasks/run-hook');
55
var BuildTask = require('../tasks/ember-build');
6+
var getPlatform = require('../utils/get-platform');
67

78
var ValidatePlatformTask = require('../tasks/validate-platform');
89
var validateLocationType = require('../utils/validate-location-type');
@@ -31,8 +32,13 @@ module.exports = {
3132
var ui = this.ui;
3233
var project = this.project;
3334

35+
var platform = getPlatform(project.config(), options);
36+
project.targetIsCordova = true;
37+
38+
//Confirm location type is hash
3439
validateLocationType(this.project.config());
3540

41+
//Warn the user if allow-navigation is still on
3642
validateCordovaConfig = getCordovaConfig(this.project)
3743
.then(function(cordovaConfig) {
3844
return validateAllowNavigation(
@@ -41,9 +47,6 @@ module.exports = {
4147
);
4248
});
4349

44-
project.targetIsCordova = true;
45-
var platform = project.CORDOVA_PLATFORM = options.platform;
46-
4750
validatePlatform = new ValidatePlatformTask({
4851
project: this.project,
4952
ui: this.ui,

lib/commands/open.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
var OpenAppTask = require('../tasks/open-app');
3+
var OpenAppTask = require('../tasks/open-app');
4+
var getPlatform = require('../utils/get-platform');
45

56
module.exports = {
67
name: 'cordova:open',
@@ -15,9 +16,11 @@ module.exports = {
1516
],
1617

1718
run: function(options) {
19+
var platform = getPlatform(this.project.config(), options);
20+
1821
var open = new OpenAppTask({
1922
application: options.application,
20-
platform: options.platform,
23+
platform: platform,
2124
project: this.project,
2225
ui: this.ui
2326
});

lib/commands/serve.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var CdvBuildTask = require('../tasks/cordova-build');
44
var HookTask = require('../tasks/run-hook');
55
var ServeTask = require('../tasks/ember-build-serve');
6+
var getPlatform = require('../utils/get-platform');
67

78
var Promise = require('ember-cli/lib/ext/promise');
89
var PortFinder = require('portfinder');
@@ -55,12 +56,16 @@ module.exports = {
5556
var hook, serve, cordovaBuild, validateCordovaConfig, validatePlugin,
5657
validatePlatform;
5758

58-
validateLocationType(this.project.config());
59+
var platform = getPlatform(this.project.config(), options);
5960

61+
//Vars for live reload addon service
6062
this.project.targetIsCordova = true;
61-
var platform = this.project.CORDOVA_PLATFORM = options.platform;
6263
this.project.RELOAD_PORT = options.port;
6364

65+
//Confirm location type is hash
66+
validateLocationType(this.project.config());
67+
68+
//Warn user we require allow-navigation on
6469
validateCordovaConfig = getCordovaConfig(this.project)
6570
.then(function(cordovaConfig) {
6671
return validateAllowNavigation(

lib/utils/get-platform.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function getPlatform(config, options) {
2+
var platform, defaultPlatform;
3+
defaultPlatform = config && config.cordova && config.cordova.platform;
4+
defaultPlatform ? platform = defaultPlatform : platform = options.platform;
5+
6+
return platform;
7+
}

node-tests/fixtures/ember-cordova-mock/project.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ module.exports = {
77
env: 'development',
88
id: 'ember-cordova-mock',
99
name: 'ember-cordova-mock',
10-
platform: 'ios',
10+
cordova: {
11+
platform: 'ios'
12+
},
1113

1214
project: {
1315
root: path.resolve(__dirname, '..', '..', 'fixtures', 'ember-cordova-mock')
1416
},
17+
18+
config: function() {},
19+
1520
ui: new MockUI()
1621
}

node-tests/unit/commands/build-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ describe('Build Command', () => {
8989
it('passes platform to cordova build task', () => {
9090
let passedPlatform = 'ios';
9191

92-
runBuild({
92+
return runBuild({
9393
platform: passedPlatform
94+
}).then(function() {
95+
expect(cordovaPlatform).to.equal(passedPlatform);
9496
});
95-
96-
expect(cordovaPlatform).to.equal(passedPlatform);
9797
});
9898
});
9999

node-tests/unit/tasks/open-app-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const OpenAppTask = require('../../../lib/tasks/open-app');
77
const expect = require('../../helpers/expect');
88
const openCommand = require('../../../lib/utils/open-app-command');
99

10-
1110
const mockProject = require('../../fixtures/ember-cordova-mock/project');
11+
const _merge = require('lodash').merge;
1212
const isObject = td.matchers.isA(Object);
1313

1414
describe('Open App Task', () => {
@@ -22,7 +22,7 @@ describe('Open App Task', () => {
2222
'ember-cordova-mock/ember-cordova/cordova'
2323
);
2424

25-
openApp = new OpenAppTask(mockProject);
25+
openApp = new OpenAppTask(_merge(mockProject, { platform: 'ios' }));
2626
});
2727

2828
afterEach(() => {
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const expect = require('../../helpers/expect');
4+
const getPlatform = require('../../../lib/utils/get-platform');
5+
const mockProject = require('../../fixtures/ember-cordova-mock/project');
6+
7+
describe('Get Platform Util', () => {
8+
it('returns the default platform if one is set', function() {
9+
expect(
10+
getPlatform(mockProject)
11+
).to.equal('ios');
12+
});
13+
14+
it('returns the cflag platform is there is no default', function() {
15+
expect(
16+
getPlatform({}, {platform: 'android'})
17+
).to.equal('android');
18+
});
19+
});
20+

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cordova",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Tooling for cordova and crosswalk hybrid applications built with Ember",
55
"homepage": "https://github.com/isleofcode/ember-cordova",
66
"repository": {

0 commit comments

Comments
 (0)