Skip to content

Commit

Permalink
Remove proxy requirement for live reload and extra plugins in starter…
Browse files Browse the repository at this point in the history
… kit not needed
  • Loading branch information
jakecraige committed Oct 20, 2014
1 parent 35b93a9 commit 48009fc
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 53 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ enable the rebuild option in the configuration as described below.
### Running in the simulator

#### With starter kit live reload
Livereload disabled by default. To enable it, set it to true in the your app's
config. After the starter kit generator has run, simply run `ember serve --proxy
http://your-device-ip:4300` and then `ember cordova emulate platform`(in another
tab/split) to start up the app in the emulator.
Livereload disabled by default. To enable it, set it up in your app's
config. After the starter kit generator has run, simply run `ember serve` and
then `ember cordova emulate platform`(in another tab/split) to start up the
app in the emulator.

When it is enabled, your app will not start up in the real browser. This is
because cordova hijacks the browser events and the app is never told to start.
If you need it to start, just call `AppName.advanceReadiness()` in the browser
once it's loaded. (We will try and get a fix for this soon)

#### Without starter kit live reload

Expand Down Expand Up @@ -113,10 +118,14 @@ ENV.cordova = {
emberUrl: 'http://10.0.1.12:4200',

// Whether or not to use liveReload on the device simulator. Requires a few
// plugins to be installed that come with the starter-kit
// plugins to be installed that come with the starter-kit. It will cause your
// app to not boot up in the browser
//
// default: false
liveReload: true
// default: false and iOS
liveReload: {
enabled: false,
platform: 'ios'
}
};
```

Expand Down
10 changes: 2 additions & 8 deletions addon/initializers/in-app-livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import redirect from '../utils/redirect';
import startProxy from '../utils/start-proxy-server';

export var initialize = function(container, app, config) {
return deferReadiness(app).then(function() {
return startProxy('').then(function(url) {
return config.cordova.emberUrl || url.replace('4300', '4200');
}).then(redirect);

}).finally(function() {
app.advanceReadiness();
});
var url = config.cordova.emberUrl || 'http://localhost:4200';
return redirect(url);
};

export default {
Expand Down
3 changes: 2 additions & 1 deletion app/initializers/in-app-livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var inAppReload = reloadInitializer.initialize;
export var initialize = function(container, app) {
if(typeof cordova === 'undefined' ||
config.environment !== 'development' ||
(config.cordova && !config.cordova.liveReload)) {
(config.cordova &&
(!config.cordova.liveReload || !config.cordova.liveReload.enabled))) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion blueprints/cordova-init/files/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(environment) {
},

cordova: {
rebuildOnChange: true,
rebuildOnChange: false,
emulate: false
}
};
Expand Down
7 changes: 5 additions & 2 deletions blueprints/cordova-starter-kit/files/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ module.exports = function(environment) {
},

cordova: {
rebuildOnChange: true,
rebuildOnChange: false,
emulate: false,
emberUrl: 'http://' + addresses[0] + ':4200',
liveReload: false
liveReload: {
enabled: false,
platform: 'ios'
}
}
};

Expand Down
14 changes: 1 addition & 13 deletions blueprints/cordova-starter-kit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,10 @@ module.exports = {
});
},

// TODO: this should be cleaned up. I needs to run in series though
addPlugins: function() {
return this.addPluginToProject('org.apache.cordova.file-transfer').then(function() {
this.addPluginToProject('org.apache.cordova.file');
}.bind(this)).then(function() {
this.addPluginToProject('https://github.com/MobileChromeApps/zip.git');
}.bind(this)).then(function() {
this.addPluginToProject('https://github.com/floatinghotpot/cordova-httpd.git');
}.bind(this));
},

afterInstall: function() {
return Promise.all([
this.addPackageToProject('broccoli-sass'),
this.addPackageToProject('liquid-fire'),
this.addPlugins()
this.addPackageToProject('liquid-fire')
]);
}
};
63 changes: 42 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,67 @@
var path = require('path');
var commands = require('./lib/commands');
var postBuild = require('./lib/tasks/post-build');
var defaults = require('lodash').defaults;
var chalk = require('chalk');

module.exports = {
name: 'ember-cli-cordova',

treePaths: {
app: 'app',
styles: 'app/styles',
templates: 'app/templates',
addon: 'addon',
'addon-styles': 'addon/styles',
'addon-templates': 'addon/templates',
vendor: 'vendor',
'test-support': 'test-support',
'public': 'public'
},

contentFor: function(type) {
if(type === 'body') {
return '<script src="cordova.js"></script>';
}
},

blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},

includedCommands: function() {
return commands;
},

cdvConfig: function() {
var config = this.project.config('development');
if (config.cordova) {
return config.cordova
}
var cdvConfig = defaults(this.project.config('development').cordova || {}, {
liveReload: {
enabled: false,
platform: 'ios'
}
});

return {};
return cdvConfig;
},

postBuild: function() {
return postBuild(this.project, this.cdvConfig())();
},

treeForPublic: function(tree) {
var config = this.cdvConfig();

if(config.liveReload.enabled) {
if(!config.liveReload.platform) {
throw new Error('ember-cli-cordova: You must specify a liveReload.platform in your environment.js');
}

var platformsPath = path.join(this.project.root, 'cordova', 'platforms');
var pluginsPath;

if (config.liveReload.platform === 'ios') {
pluginsPath = path.join(platformsPath, 'ios', 'www');
} else if (config.liveReload.platform === 'android') {
pluginsPath = path.join(platformsPath, 'android', 'assets', 'www');
} else {
pluginsPath = path.join(platformsPath, config.liveReload.platform);
}

var pluginsTree = this.pickFiles(this.treeGenerator(pluginsPath), {
srcDir: '/',
files: ['cordova.js', 'cordova_plugins.js', 'plugins/*'],
destDir: '/'
});

console.log(chalk.green('Device LiveReload is enabled'));
console.log(chalk.yellow('Your app will only boot in the simulator or on a device - https://github.com/poetic/ember-cli-cordova#configuration'));
return this.mergeTrees([tree, pluginsTree]);
}

return tree;
}
};
Empty file added public/.gitkeep
Empty file.

0 comments on commit 48009fc

Please sign in to comment.