forked from googleapis/google-auth-library-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (73 loc) · 2.39 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
'use strict';
require('source-map-support').install();
const clangFormat = require('clang-format');
const del = require('del');
const format = require('gulp-clang-format');
const gulp = require('gulp');
const merge = require('merge2');
const mocha = require('gulp-mocha');
const sourcemaps = require('gulp-sourcemaps');
const ts = require('gulp-typescript');
const tslint = require('gulp-tslint');
const outDir = 'build';
const sources = ['ts/lib/**/*.ts'];
const tests = ['ts/test/**/*.ts'];
const allFiles = ['*.js'].concat(sources, tests);
let exitOnError = true;
function onError() {
if (exitOnError) {
process.exit(1);
}
}
gulp.task('test.check-format', () => {
return gulp.src(allFiles)
.pipe(format.checkFormat('file', clangFormat))
.on('warning', onError);
});
gulp.task('format', () => {
return gulp.src(allFiles, {base: '.'})
.pipe(format.format('file', clangFormat))
.pipe(gulp.dest('.'));
});
gulp.task('test.check-lint', () => {
return gulp.src(allFiles)
.pipe(tslint({formatter: 'verbose'}))
.pipe(tslint.report())
.on('warning', onError);
});
gulp.task('clean', () => {
return del([`${outDir}`]);
});
gulp.task('compile', () => {
const tsResult = gulp.src(sources)
.pipe(sourcemaps.init())
.pipe(ts.createProject('tsconfig.json')())
.on('error', onError);
return merge([
tsResult.dts.pipe(gulp.dest(`${outDir}/definitions`)),
tsResult.js
.pipe(sourcemaps.write(
'.', {includeContent: false, sourceRoot: '../../src'}))
.pipe(gulp.dest(`${outDir}/src`)),
tsResult.js.pipe(gulp.dest(`${outDir}/src`))
]);
});
gulp.task('test.compile', ['compile'], () => {
return gulp.src(tests, {base: '.'})
.pipe(sourcemaps.init())
.pipe(ts.createProject('tsconfig.json')())
.on('error', onError)
.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '../..'}))
.pipe(gulp.dest(`${outDir}/`));
});
gulp.task('test.unit', ['test.compile'], () => {
return gulp.src([`${outDir}/test/**/*.js`]).pipe(mocha({verbose: true}));
});
gulp.task('watch', () => {
exitOnError = false;
gulp.start(['test.compile']);
// TODO: also run unit tests in a non-fatal way
return gulp.watch(allFiles, ['test.compile']);
});
gulp.task('test', ['test.unit', 'test.check-format', 'test.check-lint']);
gulp.task('default', ['compile']);