Skip to content

Commit f4c53b4

Browse files
authored
Merge pull request #76 from isleofcode/feat/live-reload-automation
feat(live-reload): automates and eases onboarding for live-reload
2 parents 574abb6 + e865b0c commit f4c53b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+650
-485
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ trim_trailing_whitespace = true
1212
insert_final_newline = true
1313
indent_style = space
1414
indent_size = 2
15+
max_line_length = 80;
1516

1617
[*.js]
1718
indent_style = space

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070
/*** Strict Mode ***/
7171

7272
// JSHint "strict"
73-
'strict': [2, 'global'],
73+
'strict': [0, 'global'],
7474

7575

7676
/*** Variables ***/

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Ember Cordova (beta)
1+
# Ember Cordova
22

33
[![Build Status](https://travis-ci.org/isleofcode/ember-cordova.svg?branch=feat%2Ftravis)](https://travis-ci.org/isleofcode/ember-cordova)
44

@@ -36,7 +36,7 @@ If you are migrating from ember-cli-cordova, read the [migration
3636
guide](docs/migration-from-ember-cli.md).
3737

3838

39-
```
39+
```cli
4040
ember install ember-cordova
4141
```
4242

@@ -46,11 +46,11 @@ name will be used.
4646

4747
If you already have a Cordova project here it will not be overwritten.
4848

49-
1. ####Set your config.locationType to 'hash'.
49+
1. #### Set your config.locationType to 'hash'.
5050

5151
2. As a final step, add your desired platforms, e.g.:
5252

53-
```
53+
```cli
5454
ember cdv platform add ios
5555
ember cdv platform add android
5656
ember cdv platform add browser #experimental
@@ -62,7 +62,8 @@ Cordova working relies on the cordova.js script being injected. By default, this
6262

6363
Some cordova/phonegap plugins have browser fallbacks. For example [phonegap-plugin-barcodescanner](https://github.com/phonegap/phonegap-plugin-barcodescanner) will ask you to manually type the barcode value. Using the browser platform, you'll be able to develop your cordova app as it was a regular ember app.
6464

65-
##Features and Documentation
65+
## Features and Documentation
66+
6667
* [CLI](docs/cli.md)
6768
* [Cordova Service & Event Bindings](docs/services/cordova.md)
6869
* Device:
@@ -74,24 +75,23 @@ Some cordova/phonegap plugins have browser fallbacks. For example [phonegap-plug
7475
* [Live reload](docs/livereload.md)
7576
* [Available Plugins](docs/plugins.md)
7677

77-
##Upcoming Extensions
78+
## Upcoming Extensions
7879

7980
We are working on four major items right now:
8081

8182
1. Improving test coverage;
82-
2. Livereload improvements;
83-
3. Bindings to Cordova Plugins [see plugins](docs/plugins.md); and
84-
4. Either having ember install ember-cordova-plugin-foo install both the
83+
2. Bindings to Cordova Plugins [see plugins](docs/plugins.md); and
84+
3. Either having ember install ember-cordova-plugin-foo install both the
8585
ember addon & cordova plugin, or achieving the same through ember
8686
cdv:install foo.
8787

88-
##Contributing
88+
## Contributing
8989

9090
PRs are very welcome. You can read our style guides [here](https://github.com/isleofcode/style-guide).
9191

9292
If you are unsure about your contribution idea, please feel free to
9393
open an Issue for feedback.
9494

95-
##Credits
95+
## Credits
9696

9797
ember-cordova is maintained by [Isle of Code](https://isleofcode.com), and started as a fork of [ember-cli-cordova](https://github.com/poetic/ember-cli-cordova).

docs/livereload.md

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,69 @@
1-
##Live reload
1+
# Device Live Reload
2+
3+
Live reload works for device & simulator builds. It is automatically enabled and configured for `ember-cordova`
4+
`>= 0.2.0`. Instructions for advanced configuration are below.
5+
6+
**Caveats**
7+
8+
- Live reload will not run in production or test environments.
9+
Your computer and phone must be on the same network.
10+
11+
- Live reload is for assistance in developing your application (just like
12+
ember-cli's live-reload in the browser). It is not a solution for delivering
13+
updates to a production application.
14+
15+
- If you are on Android >4.0, you will need to also install the whitelist plugin:
16+
` ember cdv plugin add cordova-plugin-whitelist `
17+
18+
For help troubleshooting earlier versions, see the [old version guide](#old-version-guide).
19+
20+
## Basic usage
21+
22+
```
23+
ember cdv:serve
24+
```
25+
26+
You can use s as a shorthand. Serve takes a platform option (e.g. android
27+
or ios) and any options accepted by Ember serve.
28+
29+
## Advanced Configuration
30+
31+
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.
33+
34+
## Customize the device live-reload url
35+
36+
In all cases below, `<url>` refers to the full url including protocol,
37+
host, and port.
38+
39+
*via commandline arg*
40+
41+
```cli
42+
ember cdv:serve --reload-url="<url>"
43+
```
44+
45+
or
46+
47+
```cli
48+
ember cdv:s -r "<url>"
49+
```
50+
51+
*via .ember-cli*
52+
53+
```json
54+
{
55+
deviceLiveReloadUrl: "<url>"
56+
}
57+
```
58+
59+
---------------------------------------------------------------------
60+
61+
# Old Version Guide
262

363
There are a few manual steps to getting live reload working right now.
464
We hope to eventually automate them.
565

6-
live reload will not run in production or test environments. Your computer and phone must be on the same network.
7-
8-
* Modify Cordovas config.xml to allow-navigation to http based urls. You can either specify localhost:4200, your local IP,
66+
* Modify Cordova's config.xml to allow-navigation to http based urls. You can either specify localhost:4200, your local IP,
967
or a wildcard. Wildcards are generally unsafe, and you should comment them out before production builds.
1068

1169
```
@@ -43,7 +101,7 @@ You can run the app on an emulator or any device connected to your local network
43101
* Because cordova:serve creates a new build, you should re-build when
44102
you are finished.
45103

46-
###Troubleshooting / Finding your Network IP
104+
#### Troubleshooting / Finding your Network IP
47105

48106
* If the defaults don't work, you will need to find your computers network ip and use
49107
the reload-url param. For Mac Users, you can find your Network IP at System Preferences -> Network.

index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
var commands = require('./lib/commands');
44
var cordovaPath = require('./lib/utils/cordova-path');
5-
var isTargetCordova = require('./lib/utils/is-target-cordova');
6-
var isCordovaLiveReload = require('./lib/utils/is-cordova-live-reload');
5+
var getNetworkIp = require('./lib/utils/get-network-ip');
76

87
var chalk = require('chalk');
98
var mergeTrees = require('broccoli-merge-trees');
@@ -14,31 +13,34 @@ var fs = require('fs');
1413
module.exports = {
1514
name: 'ember-cordova',
1615

17-
config: function (env, baseConfig) {
18-
if (isCordovaLiveReload()) {
19-
var conf = {};
20-
//If cordova live reload, set the reload url
21-
var reloadUrl = process.env.CORDOVA_RELOAD_ADDRESS;
22-
conf.cordova = {};
23-
conf.cordova.reloadUrl = reloadUrl;
16+
config: function(/* env, baseConfig */) {
17+
if (this.project.targetIsCordova) {
18+
var conf = { cordova: {} };
19+
if (!!this.project.RELOAD_PORT) {
20+
//If cordova live reload, set the reload url
21+
var networkAddress = getNetworkIp();
22+
var deviceServerUrl = 'http://' + networkAddress + ':' + this.project.RELOAD_PORT;
23+
24+
conf.cordova.reloadUrl = deviceServerUrl;
25+
}
2426

2527
return conf;
2628
}
2729
},
2830

29-
contentFor: function (type) {
30-
if (isTargetCordova() && type === 'body') {
31+
contentFor: function(type) {
32+
if (this.project.targetIsCordova && type === 'body') {
3133
return '<script src="cordova.js"></script>';
3234
}
3335
},
3436

35-
includedCommands: function () {
37+
includedCommands: function() {
3638
return commands;
3739
},
3840

39-
treeForPublic: function (tree) {
40-
if (isCordovaLiveReload()) {
41-
var platform = process.env.CORDOVA_PLATFORM;
41+
treeForPublic: function(tree) {
42+
if (this.project.targetIsCordova) {
43+
var platform = this.project.CORDOVA_PLATFORM;
4244

4345
var platformsPath = path.join(cordovaPath(this.project), 'platforms');
4446
var pluginsPath;
@@ -51,7 +53,7 @@ module.exports = {
5153
pluginsPath = path.join(platformsPath, 'browser', 'www');
5254
}
5355

54-
var files = ['cordova.js', 'cordova_plugins.js'];
56+
var files = ['cordova_plugins.js'];
5557

5658
files.forEach(function (file) {
5759
var filePath = path.join(pluginsPath, file);
@@ -72,8 +74,6 @@ module.exports = {
7274
destDir: '/'
7375
});
7476

75-
this.ui.writeLine(chalk.green('ember-cordova: Device LiveReload is enabled'));
76-
7777
return mergeTrees([tree, pluginsTree]);
7878
}
7979

lib/commands/build.js

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,77 @@
11
'use strict';
22

3-
var EmberBuildTask = require('../tasks/ember-build');
43
var CdvBuildTask = require('../tasks/cordova-build');
5-
var LinkTask = require('../tasks/link-environment');
64
var HookTask = require('../tasks/run-hook');
5+
var BuildTask = require('../tasks/ember-build');
76

8-
var defaultPlatform = require('../utils/default-platform');
7+
var validateLocationType = require('../utils/validate-location-type');
8+
var getCordovaConfig = require('../utils/get-cordova-config');
9+
var validateAllowNavigation = require('../utils/validate-allow-navigation');
910

10-
var validateLocationType = require('../utils/validate-location-type');
11+
var chalk = require('chalk');
1112

1213
module.exports = {
1314
name: 'cordova:build',
14-
aliases: ['cdv:build'],
15-
description: 'Build ember & cordova applications',
15+
aliases: ['cdv:build', 'cdv:b'],
16+
description: 'Build the ember application for cordova',
1617
works: 'insideProject',
1718

18-
availableOptions: [{
19-
name: 'environment',
20-
type: String,
21-
default: 'development',
22-
aliases: ['env']
23-
}, {
24-
name: 'platform',
25-
type: String
26-
}],
19+
/* eslint-disable max-len */
20+
availableOptions: [
21+
{ name: 'platform', type: String, default: 'ios' },
22+
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
23+
{ name: 'environment', type: String, default: 'development', aliases: ['e', 'env', { 'dev': 'development' }, { 'prod': 'production' }] },
24+
{ name: 'output-path', type: 'Path', default: 'ember-cordova/cordova/www', aliases: ['op', 'out'] },
25+
],
26+
/* eslint-enable max-len */
2727

2828
run: function(options) {
29+
var hook, build, cordovaBuild, validateCordovaConfig;
30+
var ui = this.ui;
31+
var project = this.project;
32+
2933
validateLocationType(this.project.config());
3034

31-
var platform = options.platform || defaultPlatform(this.project);
35+
validateCordovaConfig = getCordovaConfig(this.project)
36+
.then(function(cordovaConfig) {
37+
return validateAllowNavigation(
38+
cordovaConfig,
39+
false
40+
);
41+
});
3242

33-
var hook = new HookTask({
34-
project: this.project,
35-
ui: this.ui
36-
});
43+
project.targetIsCordova = true;
44+
var platform = project.CORDOVA_PLATFORM = options.platform;
3745

38-
var emberBuild = new EmberBuildTask({
39-
project: this.project,
40-
ui: this.ui,
41-
buildOptions: options.buildOptions
46+
hook = new HookTask({
47+
project: project,
48+
ui: ui
4249
});
4350

44-
var link = new LinkTask({
45-
project: this.project,
46-
ui: this.ui
51+
build = new BuildTask({
52+
ui: ui,
53+
project: project,
54+
environment: options.environment,
55+
outputPath: options.outputPath
4756
});
4857

49-
var cordovaBuild = new CdvBuildTask({
50-
project: this.project,
51-
ui: this.ui
58+
cordovaBuild = new CdvBuildTask({
59+
project: project,
60+
ui: ui
5261
});
5362

54-
return hook.run('beforeBuild')
55-
.then(emberBuild.run(options.environment))
56-
.then(link.run())
57-
.then(cordovaBuild.run(platform, options.environment))
58-
.then(hook.run('afterBuild'));
63+
ui.writeLine(chalk.green('Building'));
64+
65+
return validateCordovaConfig
66+
.then(hook.prepare('beforeBuild'))
67+
.then(build.prepare())
68+
.then(cordovaBuild.prepare(platform))
69+
.then(hook.prepare('afterBuild'))
70+
.then(function() {
71+
ui.writeLine(chalk.green('Cordova Project Built.'));
72+
})
73+
.catch(function(e) {
74+
throw e;
75+
});
5976
}
6077
};

lib/commands/link.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
'use strict';
22

3-
var LinkTask = require('../tasks/link-environment');
3+
var easyError = require('../utils/easy-error');
4+
var chalk = require('chalk');
5+
var LINK_DEPRECATION = chalk.yellow(
6+
'\n\tDEPRECATED\n\t--------------\n' +
7+
'\t`cordova:link` and alias `cdv:link` have been deprecated because\n' +
8+
'\ttheir behavior is no longer utilized by `ember-cordova` since assets\n' +
9+
'\tare now built directly into the cordova/www folder.\n'
10+
);
411

512
module.exports = {
613
name: 'cordova:link',
714
aliases: ['cdv:link'],
8-
description: 'symlink dist to cordova/www',
15+
description: '[DEPRECATED] symlink dist to cordova/www',
916
works: 'insideProject',
1017

11-
run: function(options) {
12-
var link = new LinkTask({
13-
project: this.project,
14-
ui: this.ui
15-
});
16-
17-
return link.run();
18+
run: function() {
19+
easyError(LINK_DEPRECATION);
1820
}
1921
};

0 commit comments

Comments
 (0)