4
4
5
5
const PORT = 8080 ;
6
6
7
+ const webpack = require ( 'webpack' ) ;
8
+ const karma = require ( 'karma' ) ;
9
+ const express = require ( 'express' ) ;
10
+ const colors = require ( 'colors' ) ;
11
+ const os = require ( 'os' ) ;
7
12
8
- // Webpack build server
9
- var webpack = require ( 'webpack' ) ;
10
- var config = require ( './webpack.config.js' ) ;
11
- var compiler = webpack ( config ) ;
12
- var colors = require ( 'colors' ) ;
13
+ // Status logging
14
+ function serverStatus ( ) {
15
+ console . log ( "Server listening on:" )
16
+ console . log ( colors . cyan ( `http://localhost:${ PORT } ` ) ) ;
13
17
14
- var logSemaphore = 0 ;
15
- compiler . watch ( { } , function ( err , stats ) {
16
- console . log ( stats . toString ( { colors :true , chunks :false , children :false } ) ) ;
18
+ let ifaces = os . networkInterfaces ( ) ;
19
+ Object . keys ( ifaces ) . forEach ( function ( ifname ) {
20
+ ifaces [ ifname ] . forEach ( function ( iface ) {
21
+ if ( 'IPv4' === iface . family && iface . internal === false ) {
22
+ console . log ( colors . cyan ( `http://${ iface . address } :${ PORT } ` ) ) ;
23
+ }
24
+ } ) ;
25
+ } ) ;
26
+ }
27
+ let logSemaphore = 0 ;
28
+ function logStart ( ) {
17
29
logSemaphore ++ ;
30
+ }
31
+ function logEnd ( ) {
18
32
setTimeout ( function ( ) {
19
33
logSemaphore -- ;
20
34
if ( logSemaphore == 0 ) {
@@ -23,32 +37,37 @@ compiler.watch({},function(err,stats) {
23
37
console . log ( ) ;
24
38
}
25
39
} , 100 ) ;
40
+ }
41
+
42
+ // Webpack build server
43
+ let compiler = webpack ( require ( './webpack.config.js' ) ) ;
44
+ compiler . watch ( { } , function ( err , stats ) {
45
+ console . log ( stats . toString ( { colors :true , chunks :false , children :false } ) ) ;
46
+ logStart ( ) ;
47
+ logEnd ( ) ;
48
+ } ) ;
49
+
50
+ // Karma test server
51
+ let karmaServer = new karma . Server ( {
52
+ configFile : `${ __dirname } /karma.conf.js` ,
53
+ singleRun : false ,
54
+ } ) ;
55
+ karmaServer . on ( 'run_start' , function ( ) {
56
+ logStart ( ) ;
26
57
} ) ;
58
+ karmaServer . on ( 'run_complete' , function ( ) {
59
+ logEnd ( ) ;
60
+ } ) ;
61
+ karmaServer . start ( ) ;
27
62
28
63
// Express web server
29
- var express = require ( 'express' ) ;
30
- var app = express ( ) ;
31
- var os = require ( 'os' ) ;
32
- var ifaces = os . networkInterfaces ( ) ;
64
+ let app = express ( ) ;
33
65
34
- app . use ( '/dist' , express . static ( __dirname + ' /dev/dist' ) ) ;
66
+ app . use ( '/dist' , express . static ( ` ${ __dirname } /dev/dist` ) ) ;
35
67
app . get ( '/' , function ( req , res ) {
36
- res . sendFile ( __dirname + ' /dev/index.html' ) ;
68
+ res . sendFile ( ` ${ dirname } /dev/index.html` ) ;
37
69
} ) ;
38
70
39
71
app . listen ( PORT , function ( ) {
40
72
serverStatus ( ) ;
41
73
} ) ;
42
-
43
- function serverStatus ( ) {
44
- console . log ( "Server listening on:" )
45
- console . log ( colors . cyan ( "http://localhost:%s" ) , PORT ) ;
46
-
47
- Object . keys ( ifaces ) . forEach ( function ( ifname ) {
48
- ifaces [ ifname ] . forEach ( function ( iface ) {
49
- if ( 'IPv4' === iface . family && iface . internal === false ) {
50
- console . log ( colors . cyan ( "http://%s:%s" ) , iface . address , PORT ) ;
51
- }
52
- } ) ;
53
- } ) ;
54
- }
0 commit comments