forked from dwyl/hapi-typescript-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
83 lines (72 loc) · 1.96 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
'use strict'
let gulp = require('gulp')
let rimraf = require('gulp-rimraf')
let tsc = require('gulp-typescript')
let sourcemaps = require('gulp-sourcemaps')
let tslint = require('gulp-tslint')
let nodemon = require('gulp-nodemon')
var mocha = require('gulp-mocha')
var istanbul = require('gulp-istanbul')
// /* Variables */
let tsProject = tsc.createProject('tsconfig.json')
let sourceFiles = 'src/**/*.ts'
let testFiles = 'test/**/*.ts'
let outDir = require('./tsconfig.json').compilerOptions.outDir
let entryPoint = './build/src/server.js'
/**
* Remove build directory.
*/
gulp.task('clean', function() {
return gulp.src(outDir, { read: false })
.pipe(rimraf())
})
/**
* Lint all custom TypeScript files.
*/
gulp.task('tslint', () => {
return gulp.src(sourceFiles)
.pipe(tslint())
.pipe(tslint.report('verbose'))
})
/**
* Compile TypeScript sources and create sourcemaps in build directory.
*/
gulp.task('compile', ['clean'], () => {
let tsResult = gulp.src([sourceFiles, testFiles])
.pipe(sourcemaps.init())
.pipe(tsc(tsProject))
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(outDir))
})
/**
* Watch for changes in TypeScript, HTML and CSS files.
*/
gulp.task('watch', function() {
gulp.watch([sourceFiles], ['compile']).on('change', (e) => {
console.log('TypeScript file ' + e.path + ' has been changed. Compiling.')
})
})
/**
* Build the project.
*/
gulp.task('build', ['compile'], () => {
console.log('Building the project ...')
})
gulp.task('test', ['build'], () => {
return gulp.src(['build/test/**/*.js'], { read: false })
.pipe(mocha({ reporter: 'list' }))
.once('error', () => {
process.exit(1);
})
.once('end', () => {
process.exit();
});
})
gulp.task('nodemon', ['build'], () => {
nodemon({
script: entryPoint,
env: { 'NODE_ENV': 'development' },
tasks: []
})
})