Skip to content

Commit e21a8fe

Browse files
committed
ember fastboot --watch
1 parent 831afb8 commit e21a8fe

2 files changed

Lines changed: 44 additions & 23 deletions

File tree

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ module.exports = {
106106
});
107107

108108
return fastbootBuild.toTree();
109-
}
109+
},
110+
111+
outputReady: function() {
112+
process.emit('SIGUSR1');
113+
},
110114

111115
};

lib/commands/fastboot.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77

88
availableOptions: [
99
{ name: 'build', type: Boolean, default: true },
10+
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
1011
{ name: 'environment', type: String, default: 'development', aliases: ['e',{'dev' : 'development'}, {'prod' : 'production'}] },
1112
{ name: 'serve-assets', type: Boolean, default: false },
1213
{ name: 'host', type: String, default: '::' },
@@ -15,27 +16,29 @@ module.exports = {
1516
{ name: 'assets-path', type: String, default: 'dist' }
1617
],
1718

18-
runCommand: function(appName, options) {
19-
var commandOptions = this.commandOptions;
20-
var outputPath = commandOptions.outputPath;
21-
var assetsPath = commandOptions.assetsPath;
19+
startServer: function(options) {
2220
var ui = this.ui;
21+
var self = this;
2322

24-
ui.writeLine("Installing FastBoot npm dependencies");
23+
if (this._fastBootListener) {
24+
this._fastBootListener.close();
25+
}
26+
27+
ui.writeLine('Installing FastBoot npm dependencies');
2528

26-
return exec('npm install', { cwd: outputPath })
29+
return exec('npm install', { cwd: options.outputPath })
2730
.then(function() {
2831
var fastbootMiddleware = require('fastboot-express-middleware');
2932
var RSVP = require('rsvp');
3033
var express = require('express');
3134

32-
var middleware = fastbootMiddleware(outputPath);
35+
var middleware = fastbootMiddleware(options.outputPath);
3336

3437
var app = express();
3538

36-
if (commandOptions.serveAssets) {
39+
if (options.serveAssets) {
3740
app.get('/', middleware);
38-
app.use(express.static(assetsPath));
41+
app.use(express.static(options.assetsPath));
3942
}
4043

4144
app.get('/*', middleware);
@@ -52,38 +55,52 @@ module.exports = {
5255
if (family === 'IPv6') { host = '[' + host + ']'; }
5356

5457
ui.writeLine('Ember FastBoot running at http://' + host + ":" + port);
58+
self._fastBootListener = listener;
5559
});
56-
57-
// Block forever
58-
return new RSVP.Promise(function() { });
5960
});
6061
},
6162

62-
triggerBuild: function(commandOptions) {
63-
var BuildTask = this.tasks.Build;
63+
triggerBuild: function(options) {
64+
var BuildTask = this.buildTaskFor(options);
6465
var buildTask = new BuildTask({
6566
ui: this.ui,
6667
analytics: this.analytics,
6768
project: this.project
6869
});
6970

70-
return buildTask.run(commandOptions);
71+
return buildTask.run(options);
72+
},
73+
74+
buildTaskFor: function(options) {
75+
if (options.watch) {
76+
return this.tasks.BuildWatch;
77+
} else {
78+
return this.tasks.Build;
79+
}
7180
},
7281

7382
run: function(options) {
74-
this.commandOptions = options;
83+
var startServer = function() {
84+
this.startServer(options);
85+
}.bind(this);
7586

76-
var runCommand = function() {
77-
var appName = process.env.EMBER_CLI_FASTBOOT_APP_NAME || this.project.name();
87+
var blockForever = function() {
88+
return new RSVP.Promise(function() { });
89+
};
7890

79-
return this.runCommand(appName, options);
80-
}.bind(this);
91+
process.on('SIGUSR1', startServer);
8192

8293
if (options.build) {
8394
return this.triggerBuild(options)
84-
.then(runCommand);
95+
.then(startServer)
96+
.then(blockForever);
97+
}
98+
99+
if (options.watch) {
100+
this.ui.writeWarnLine('The `watch` option is not supported when `build` is disabled.');
85101
}
86102

87-
return runCommand();
103+
return startServer()
104+
.then(blockForever);
88105
}
89106
};

0 commit comments

Comments
 (0)