forked from vmware-archive/react-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·70 lines (62 loc) · 1.45 KB
/
server.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
66
67
68
69
70
#!/usr/bin/env node
"use strict";
const PORT=8080;
const webpack = require('webpack');
const karma = require('karma');
const express = require('express');
const colors = require('colors');
const os = require('os');
// Status logging
function serverStatus() {
console.log("Server listening on:")
console.log(colors.cyan(`http://localhost:${PORT}`));
let ifaces = os.networkInterfaces();
Object.keys(ifaces).forEach(function (ifname) {
ifaces[ifname].forEach(function (iface) {
if ('IPv4' === iface.family && iface.internal === false) {
console.log(colors.cyan(`http://${iface.address}:${PORT}`));
}
});
});
}
let logSemaphore = 0;
function logStart() {
logSemaphore++;
}
function logEnd() {
setTimeout(function() {
logSemaphore--;
if(logSemaphore == 0) {
console.log();
serverStatus();
console.log();
}
},100);
}
// Express web server
let app = express();
app.use('/', express.static(`${__dirname}/dev`));
app.listen(PORT, function() {
serverStatus();
});
// Webpack build server
let compiler = webpack(require('./webpack.config.js'));
compiler.watch({},function(err,stats) {
console.log(stats.toString({colors:true,chunks:false,children:false}));
logStart();
logEnd();
});
// Karma test server
/*
let karmaServer = new karma.Server({
configFile: `${__dirname}/karma.conf.js`,
singleRun: false,
});
karmaServer.on('run_start', function() {
logStart();
});
karmaServer.on('run_complete', function() {
logEnd();
});
karmaServer.start();
*/