-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jakefile.js
79 lines (62 loc) · 1.83 KB
/
Jakefile.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
71
72
73
74
75
76
77
78
const dir = {
src: 'src',
out: 'dist',
gen: 'gen'
};
const protos = [
'payload'
];
const protobufJs = 'protobuf.js';
const protobufDts = 'protobuf.d.ts';
//
const _ = require('lodash');
const path = require('path');
desc('Creates the output directory.');
directory(dir.out);
desc('Creates the generated code directory.');
directory(dir.gen);
(() => {
const pb = require('protobufjs/cli');
const protoSrcs = _.map(protos, name => path.join(dir.src, name + '.proto'));
const outJs = path.join(dir.out, protobufJs);
const genDts = path.join(dir.gen, protobufDts);
desc('Generates static protobuf code.');
file(outJs, [dir.out, ...protoSrcs], {async: true}, () => {
jake.logger.log('Generating static protobuf code...');
pb.pbjs.main([
'-t', 'static-module', '-w', 'commonjs',
...protoSrcs, '-o', outJs
], function(err) {
if (err) throw err;
complete();
});
});
desc('Generates protobuf declarations.');
file(genDts, [dir.gen, outJs], {async: true}, () => {
jake.logger.log('Generating protobuf declarations...');
pb.pbts.main([outJs, '-o', genDts], function(err) {
if (err) throw err;
complete();
});
});
task('protobuf', [outJs, genDts], () => {
jake.cpR(genDts, dir.out);
});
})();
desc('Compiles typescript.');
task('compile', [dir.out, 'protobuf'], {async: true}, () => {
jake.logger.log('Compiling typescript...');
jake.exec('tsc', complete, {printStdout: true, printStderr: true});
});
desc('Creates a browser bundle.');
task('bundle', ['compile'], {async: true}, () => {
jake.logger.log('Bundling...');
jake.exec('webpack', complete, {printStdout: true, printStderr: true});
});
desc('Builds everything.');
task('default', ['compile']);
desc('Cleans the build tree.');
task('clean', () => {
jake.rmRf(dir.out);
jake.rmRf(dir.gen);
});