-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathcmd.js
executable file
·57 lines (48 loc) · 1.29 KB
/
cmd.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
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require("commander");
var fs = require("fs");
var path = require("path");
var pkg = JSON.parse(
fs.readFileSync(path.join(__dirname, "..", "package.json"))
);
var build = require("../lib/build");
var serve = require("../lib/serve");
program.version(pkg.version);
program
.option("-c --config <webpack-config>", "additional webpack configuration")
program
.command("serve <dir>")
.description("serve and watch functions")
.action(function(cmd, options) {
console.log("Starting server");
var server = serve.listen(9000);
build.watch(cmd, program.config, function(err, stats) {
if (err) {
console.error(err);
return;
}
stats.compilation.chunks.forEach(function(chunk) {
server.clearCache(chunk.name);
});
console.log(stats.toString({ color: true }));
});
});
program
.command("build <dir>")
.description("build functions")
.action(function(cmd, options) {
console.log("Building functions");
build
.run(cmd, program.config)
.then(function(stats) {
console.log(stats.toString({ color: true }));
})
.catch(function(err) {
console.error(err);
process.exit(1);
});
});
program.parse(process.argv);