forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (53 loc) · 1.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable no-console */
/**
* External dependencies.
*/
var boot = require( 'boot' ),
http = require( 'http' ),
chalk = require( 'chalk' );
/**
* Internal dependencies
*/
var pkg = require( './package.json' ),
config = require( 'config' );
var start = Date.now(),
port = process.env.PORT || config( 'port' ),
host = process.env.HOST || config( 'hostname' ),
app = boot(),
server,
compiler,
hotReloader;
function sendBootStatus( status ) {
// don't send anything if we're not running in a fork
if ( ! process.send ) {
return;
}
process.send( { boot: status } );
}
console.log( chalk.yellow( '%s booted in %dms - http://%s:%s' ), pkg.name, ( Date.now() ) - start, host, port );
server = http.createServer( app );
// The desktop app runs Calypso in a fork.
// Let non-forks listen on any host.
if ( ! process.env.CALYPSO_IS_FORK ) {
host = null;
}
server.listen( { port, host }, function() {
// Tell the parent process that Calypso has booted.
sendBootStatus( 'ready' );
} );
// Enable hot reloader in development
if ( process.env.NODE_ENV === 'development' ) {
console.info( chalk.cyan( '\nGetting bundles ready, hold on...' ) );
hotReloader = require( 'bundler/hot-reloader' );
compiler = app.get( 'compiler' );
compiler.plugin( 'compile', function() {
sendBootStatus( 'compiler compiling' );
} );
compiler.plugin( 'invalid', function() {
sendBootStatus( 'compiler invalid' );
} );
compiler.plugin( 'done', function() {
sendBootStatus( 'compiler done' );
} );
hotReloader.listen( server, compiler );
}