-
Notifications
You must be signed in to change notification settings - Fork 0
/
wd.js
executable file
·61 lines (53 loc) · 1.31 KB
/
wd.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
#!/usr/bin/env node
'use strict'
const yargs = require('yargs')
const Dashboard = require('webpack-dashboard/dashboard')
const SocketIO = require('socket.io')
const config = require('./config.json')
const spawn = require('child_process').spawn
const spawnDashboard = (config = {}) => {
const dashboard = new Dashboard({
color: config.color || 'green',
minimal: config.minimal || false,
title: config.title || null
})
const port = config.port
const server = SocketIO(port)
server.on('error', (err) => {
console.error(err)
})
server.on('connection', (socket) => {
socket.on('message', (message) => {
dashboard.setData(message)
})
})
}
const argv = yargs
.usage('Usage: $0 <command>')
.command(
'server',
'start webpack-dashboard for the server bundle',
(yars) => {
spawnDashboard(config.server)
})
.command(
'client',
'start webpack-dashboard for the client bundle',
(yars) => {
spawnDashboard(config.client)
})
.command(
'bundle',
'start the webpack job bundling client and server on changes',
(yars) => {
spawn('node_modules/.bin/webpack', [ '--watch' ], {
env: process.env,
stdio: 'inherit'
})
})
.help('h')
.alias('h', 'help')
.argv
if (argv._.length < 1) {
yargs.showHelp()
}