Skip to content

Commit

Permalink
fix(): ensure run and emulate are delegating livereload and serve to …
Browse files Browse the repository at this point in the history
…app-scripts when applicable.
  • Loading branch information
jthoms1 committed Nov 15, 2016
1 parent 8a6b554 commit c34b3c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
21 changes: 10 additions & 11 deletions lib/ionic/emulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,24 @@ function run(ionic, argv, rawCliArguments) {
hasBuildCommand = results[2];
hasServeCommand = results[3];

if (hasBuildCommand) {
if (hasBuildCommand && !(isLiveReload && hasServeCommand)) {
return npmScripts.runIonicScript('build');
}
return Q();
})
.then(function() {

if (isLiveReload && hasServeCommand && false) {
// If we are running livereload and are using "ionic:serve" app-script
// then configure devServer manually
if (isLiveReload && hasServeCommand) {

// using app-scripts and livereload is requested
return ConfigXml.setConfigXml(process.cwd(), {
devServer: serveUtil.getUrl(address, port)
});
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address, '--nobrowser'])
.then(function() {
return ConfigXml.setConfigXml(process.cwd(), {
devServer: serveUtil.getUrl(address, port)
});
});
} else if (isLiveReload) {

// not an app-scripts project but the user wants livereload
Expand All @@ -109,12 +114,6 @@ function run(ionic, argv, rawCliArguments) {
var optionList = cordovaUtils.filterArgumentsForCordova(cmdName, argv, rawArgs);
return cordovaUtils.execCordovaCommand(optionList, isLiveReload, serveOptions);
})
.then(function() {
if (isLiveReload && hasServeCommand && false) {
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address]);
}
return Q();
})
.catch(function(ex) {
if (ex instanceof Error) {
log.error(ex);
Expand Down
21 changes: 10 additions & 11 deletions lib/ionic/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,24 @@ function run(ionic, argv, rawCliArguments) {
hasBuildCommand = results[2];
hasServeCommand = results[3];

if (hasBuildCommand) {
if (hasBuildCommand && !(isLiveReload && hasServeCommand)) {
return npmScripts.runIonicScript('build');
}
return Q();
})
.then(function() {

if (isLiveReload && hasServeCommand && false) {
// If we are running livereload and are using "ionic:serve" app-script
// then configure devServer manually
if (isLiveReload && hasServeCommand) {

// using app-scripts and livereload is requested
return ConfigXml.setConfigXml(process.cwd(), {
devServer: serveUtil.getUrl(address, port)
});
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address, '--nobrowser'])
.then(function() {
return ConfigXml.setConfigXml(process.cwd(), {
devServer: serveUtil.getUrl(address, port)
});
});
} else if (isLiveReload) {

// not an app-scripts project but the user wants livereload
Expand All @@ -109,12 +114,6 @@ function run(ionic, argv, rawCliArguments) {
var optionList = cordovaUtils.filterArgumentsForCordova(cmdName, argv, rawArgs);
return cordovaUtils.execCordovaCommand(optionList, isLiveReload, serveOptions);
})
.then(function() {
if (isLiveReload && hasServeCommand && false) {
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address]);
}
return Q();
})
.catch(function(ex) {
if (ex instanceof Error) {
log.error(ex);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ function execCordovaCommand(optionList, isLiveReload, serveOptions) {
if (isLiveReload) {
cordovaProcess.on('exit', function() {

Serve.printCommandTips(serveOptions);
setTimeout(function() {

// set it back to the original src after a few seconds
Expand Down Expand Up @@ -206,6 +205,7 @@ function filterArgumentsForCordova(cmdName, argv, rawCliArguments) {
*
* @param {Array} argv List of arguments
* @param {String} baseDir The projects base directory
* @param {Obj} options options for live reload function
* @return {Promise} Promise upon completion
*/
function setupLiveReload(argv, baseDir) {
Expand Down
14 changes: 13 additions & 1 deletion lib/utils/npmScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var fs = require('fs');
var IonicAppLib = require('ionic-app-lib');
var log = IonicAppLib.logging.logger;
var DEV_SERVER_COMPLETION_STRING = 'dev server running';

function getScriptName(name) {
return 'ionic:' + name;
Expand All @@ -23,12 +24,23 @@ function runIonicScript(name, argv) {
var scriptName = getScriptName(name);
var q = Q.defer();

var scriptSpawn = spawn('npm', ['run', scriptName, '--'].concat(argv || []), { stdio: 'inherit' })
var scriptSpawn = spawn('npm', ['run', scriptName, '--', '--colors'].concat(argv || []), [process.stdin, 'pipe', process.stderr])
.on('error', function(err) {
log.debug('Spawn command', scriptName, 'failed');
q.reject('Unable to run spawn command ' + err);
});

scriptSpawn.stdout.pipe(process.stdout);

scriptSpawn.stdout.on('data', function(data) {
var dataLines = data.toString().split('\n').find(function(line) {
return line.indexOf(DEV_SERVER_COMPLETION_STRING) > -1;
});
if (dataLines && dataLines.length > 0) {
return q.resolve();
}
});

scriptSpawn.on('exit', function(code) {
log.debug('Spawn command', scriptName, 'completed');
if (code !== 0) {
Expand Down

0 comments on commit c34b3c0

Please sign in to comment.