-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
50 lines (39 loc) · 1.07 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
'use strict';
var fs = require('fs');
var http = require('http');
var util = require('util');
var del = require('del');
var logger = require('gulplog');
var st = require('st');
var DefaultRegistry = require('undertaker-registry');
function CommonRegistry(opts) {
DefaultRegistry.call(this);
opts = opts || {};
this.config = {
port: opts.port || 8080,
buildDir: opts.buildDir || './build',
};
}
util.inherits(CommonRegistry, DefaultRegistry);
CommonRegistry.prototype.init = function init(taker) {
var port = this.config.port;
var buildDir = this.config.buildDir;
var exists = fs.existsSync(buildDir);
if (exists) {
throw new Error(
'Cannot initialize undertaker-common-tasks registry. `' +
buildDir +
'` directory exists.'
);
}
taker.task('clean', function () {
return del([buildDir]);
});
taker.task('serve', function (cb) {
http.createServer(st(buildDir)).listen(port, function () {
logger.info('Server started at http://0.0.0.0:' + port);
cb();
});
});
};
module.exports = CommonRegistry;