forked from jdiaz5513/capnp-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
172 lines (151 loc) · 5.57 KB
/
gulpfile.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
* @author ishitatsuyuki
*/
var gulp = require('gulp');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var realTslint = require('tslint');
var mergeStream = require('merge-stream');
var spawnSync = require('child_process').spawnSync;
var path = require('path');
// FIXME: Not yet able to compile all the schema files, so this whitelist is needed.
const CAPNP_WHITELIST = [
'capnp-ts/src/std/schema.capnp',
'capnp-ts/test/integration/foo.capnp',
'capnp-ts/test/integration/foo-new.capnp',
'capnp-ts/test/integration/list-mania.capnp',
'capnp-ts/test/integration/upgrade-v1.capnp',
'capnpc-ts/test/integration/import-bar.capnp',
'capnpc-ts/test/integration/import-foo.capnp'
];
function build(src, dest, test) {
var tsProject = ts.createProject('configs/tsconfig-base.json', { declaration: !test });
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write('.', { includeContent: false, destPath: dest }))
.pipe(gulp.dest(dest));
}
function compileCapnp() {
return gutil.buffer(function (err, files) {
files.filter(function (file) {
return file.path.endsWith('.capnp') && CAPNP_WHITELIST.some((p) => file.path.endsWith(p));
}).forEach(function (file) {
var options = ['-o./packages/capnpc-ts/bin/capnpc-ts.js', '-I', path.join(__dirname, 'src', 'std'), file.path];
var result = spawnSync('capnpc', options, { stdio: 'inherit' });
if (result.status !== 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});
});
}
/** Compile any capnp schema files. */
gulp.task('build:capnp', ['build:capnp-ts', 'build:capnpc-ts'], function() {
return gulp.src('./packages/**/*.capnp')
.pipe(compileCapnp());
});
/** Build the main capnp-ts library. */
gulp.task('build:capnp-ts', function () {
return build('./packages/capnp-ts/src/**/*.ts', 'packages/capnp-ts/lib', false);
});
/** Build the capnpc-ts schema compiler. */
gulp.task('build:capnpc-ts', ['build:capnp-ts'], function () {
return build('./packages/capnpc-ts/src/**/*.ts', 'packages/capnpc-ts/lib', false);
});
/** Build the capnpc-js schema compiler. */
gulp.task('build:capnpc-js', ['build:capnp-ts', 'build:capnpc-ts'], function () {
return build('./packages/capnpc-js/src/**/*.ts', 'packages/capnpc-js/lib', false);
});
/** Main build task (does not build tests). */
gulp.task('build', ['build:capnp-ts', 'build:capnpc-ts', 'build:capnpc-js', 'build:capnp']);
function test(coverage) {
return gutil.buffer(function (err, files) {
var options = ['-J', '-R', 'spec'];
if (coverage) {
options.push('--cov', '--nyc-arg=-x=**/lib-test/**/*');
}
var result = spawnSync('./node_modules/.bin/tap', options.concat(files.map(function (file) {
return file.path;
}).filter(function (path) {
// This filters not only unrelated files, but also sourcemaps
return path.endsWith('.spec.js');
})), { stdio: 'inherit' });
if (result.status !== 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});
}
/** Run tests for the main capnp-ts library. */
gulp.task('test:capnp-ts', ['build:capnp', 'build:capnp-ts'], function () {
return build(
'./packages/capnp-ts/test/**/*.ts',
'packages/capnp-ts/lib-test',
true
).pipe(test(false));
});
/** Run tests for the capnpc-ts schema compiler. */
gulp.task('test:capnpc-ts', ['build:capnp', 'build:capnpc-ts'], function () {
return build(
'./packages/capnpc-ts/test/**/*.ts',
'packages/capnpc-ts/lib-test',
true
).pipe(test(false));
});
/** Run tests for the capnpc-js schema compiler. */
gulp.task('test:capnpc-js', ['build:capnp', 'build:capnpc-js'], function () {
return build(
'./packages/capnpc-js/test/**/*.ts',
'packages/capnpc-js/lib-test',
true
).pipe(test(false));
});
/** Run all tests. */
gulp.task('test', ['test:capnp-ts', 'test:capnpc-ts', 'test:capnpc-js']);
/** Run all tests with test coverage. */
gulp.task('test-cov', ['build:capnp', 'build:capnp-ts', 'build:capnpc-ts', 'build:capnpc-js'], function () {
return mergeStream(build(
'./packages/capnp-ts/test/**/*.ts',
'packages/capnp-ts/lib-test',
true
), build(
'./packages/capnpc-ts/test/**/*.ts',
'packages/capnpc-ts/lib-test',
true
), build(
'./packages/capnpc-js/test/**/*.ts',
'packages/capnpc-js/lib-test',
true
)).pipe(test(true));
});
gulp.task('coverage', ['test-cov'], function () {
var result = spawnSync('./node_modules/.bin/tap', ['--coverage-report=lcov'], { stdio: 'inherit' });
if (result.status != 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});
gulp.task('benchmark:capnp-ts', ['build:capnp', 'build:capnp-ts'], function () {
var tsProject = ts.createProject('configs/tsconfig-base.json');
return build(
'./packages/capnpc-ts/test/benchmark/**/*.ts',
'packages/capnpc-ts/lib-test',
true
).on('finish', function () {
var result = spawnSync(process.execPath,
['packages/capnp-ts/lib-test/benchmark/index.js'],
{ stdio: 'inherit' });
if (result.status != 0) {
throw new Error('Process exited with non-zero status: ' + result.status);
}
});
});
gulp.task('benchmark', ['benchmark:capnp-ts']);
gulp.task('lint', function () {
var program = realTslint.Linter.createProgram('tsconfig.json');
return gulp.src('packages/*/src/**/*.ts')
.pipe(tslint({ program }));
});
gulp.task('watch', function () {
return gulp.watch('packages/*/{src,test}/**/*', ['test']);
});