Skip to content

Commit c34b3c0

Browse files
committed
fix(): ensure run and emulate are delegating livereload and serve to app-scripts when applicable.
1 parent 8a6b554 commit c34b3c0

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

lib/ionic/emulate.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,24 @@ function run(ionic, argv, rawCliArguments) {
8080
hasBuildCommand = results[2];
8181
hasServeCommand = results[3];
8282

83-
if (hasBuildCommand) {
83+
if (hasBuildCommand && !(isLiveReload && hasServeCommand)) {
8484
return npmScripts.runIonicScript('build');
8585
}
8686
return Q();
8787
})
8888
.then(function() {
8989

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

9294
// using app-scripts and livereload is requested
93-
return ConfigXml.setConfigXml(process.cwd(), {
94-
devServer: serveUtil.getUrl(address, port)
95-
});
95+
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address, '--nobrowser'])
96+
.then(function() {
97+
return ConfigXml.setConfigXml(process.cwd(), {
98+
devServer: serveUtil.getUrl(address, port)
99+
});
100+
});
96101
} else if (isLiveReload) {
97102

98103
// not an app-scripts project but the user wants livereload
@@ -109,12 +114,6 @@ function run(ionic, argv, rawCliArguments) {
109114
var optionList = cordovaUtils.filterArgumentsForCordova(cmdName, argv, rawArgs);
110115
return cordovaUtils.execCordovaCommand(optionList, isLiveReload, serveOptions);
111116
})
112-
.then(function() {
113-
if (isLiveReload && hasServeCommand && false) {
114-
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address]);
115-
}
116-
return Q();
117-
})
118117
.catch(function(ex) {
119118
if (ex instanceof Error) {
120119
log.error(ex);

lib/ionic/run.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,24 @@ function run(ionic, argv, rawCliArguments) {
8080
hasBuildCommand = results[2];
8181
hasServeCommand = results[3];
8282

83-
if (hasBuildCommand) {
83+
if (hasBuildCommand && !(isLiveReload && hasServeCommand)) {
8484
return npmScripts.runIonicScript('build');
8585
}
8686
return Q();
8787
})
8888
.then(function() {
8989

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

9294
// using app-scripts and livereload is requested
93-
return ConfigXml.setConfigXml(process.cwd(), {
94-
devServer: serveUtil.getUrl(address, port)
95-
});
95+
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address, '--nobrowser'])
96+
.then(function() {
97+
return ConfigXml.setConfigXml(process.cwd(), {
98+
devServer: serveUtil.getUrl(address, port)
99+
});
100+
});
96101
} else if (isLiveReload) {
97102

98103
// not an app-scripts project but the user wants livereload
@@ -109,12 +114,6 @@ function run(ionic, argv, rawCliArguments) {
109114
var optionList = cordovaUtils.filterArgumentsForCordova(cmdName, argv, rawArgs);
110115
return cordovaUtils.execCordovaCommand(optionList, isLiveReload, serveOptions);
111116
})
112-
.then(function() {
113-
if (isLiveReload && hasServeCommand && false) {
114-
return npmScripts.runIonicScript('serve', ['-p', port, '--address', address]);
115-
}
116-
return Q();
117-
})
118117
.catch(function(ex) {
119118
if (ex instanceof Error) {
120119
log.error(ex);

lib/utils/cordova.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ function execCordovaCommand(optionList, isLiveReload, serveOptions) {
9393
if (isLiveReload) {
9494
cordovaProcess.on('exit', function() {
9595

96-
Serve.printCommandTips(serveOptions);
9796
setTimeout(function() {
9897

9998
// set it back to the original src after a few seconds
@@ -206,6 +205,7 @@ function filterArgumentsForCordova(cmdName, argv, rawCliArguments) {
206205
*
207206
* @param {Array} argv List of arguments
208207
* @param {String} baseDir The projects base directory
208+
* @param {Obj} options options for live reload function
209209
* @return {Promise} Promise upon completion
210210
*/
211211
function setupLiveReload(argv, baseDir) {

lib/utils/npmScripts.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var path = require('path');
55
var fs = require('fs');
66
var IonicAppLib = require('ionic-app-lib');
77
var log = IonicAppLib.logging.logger;
8+
var DEV_SERVER_COMPLETION_STRING = 'dev server running';
89

910
function getScriptName(name) {
1011
return 'ionic:' + name;
@@ -23,12 +24,23 @@ function runIonicScript(name, argv) {
2324
var scriptName = getScriptName(name);
2425
var q = Q.defer();
2526

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

33+
scriptSpawn.stdout.pipe(process.stdout);
34+
35+
scriptSpawn.stdout.on('data', function(data) {
36+
var dataLines = data.toString().split('\n').find(function(line) {
37+
return line.indexOf(DEV_SERVER_COMPLETION_STRING) > -1;
38+
});
39+
if (dataLines && dataLines.length > 0) {
40+
return q.resolve();
41+
}
42+
});
43+
3244
scriptSpawn.on('exit', function(code) {
3345
log.debug('Spawn command', scriptName, 'completed');
3446
if (code !== 0) {

0 commit comments

Comments
 (0)