-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
66 lines (55 loc) · 1.45 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
const path = require('path');
const gulp = require('gulp');
const util = require('gulp-util');
const plumber = require('gulp-plumber');
const replaces = require('gulp-replaces');
const typescript = require('gulp-typescript');
const rename = require('gulp-rename');
const shell = require('gulp-shell');
const envify = require('process-envify');
const runSequence = require('run-sequence');
const env = require('./env');
const DIST_ROOT = path.join(__dirname, 'build');
gulp.task('build', () => {
const tsProject = typescript.createProject('tsconfig.api.json');
return gulp
.src([
'src/**/*',
])
.pipe(plumber())
.pipe(replaces(envify(env)))
.pipe(tsProject())
.pipe(gulp.dest(DIST_ROOT));
});
gulp.task('copy', () => {
return gulp
.src([
'package.json',
'yarn.lock',
'Procfile',
])
.pipe(gulp.dest(DIST_ROOT));
});
gulp.task('rename', () => {
return gulp.src('build/server.js')
.pipe(shell('rimraf build/server.js'))
.pipe(rename('index.js'))
.pipe(gulp.dest(DIST_ROOT));
});
gulp.task('rebuild', (done) => {
return runSequence('build', 'rename', done);
});
gulp.task('watch', () => {
gulp.watch([
'src/server.ts',
'src/api/**/*',
'!src/api/**/__tests__/**/*',
], ['rebuild']);
});
gulp.task('serve', shell.task(`node build/index.js`));
gulp.task('default', (done) => {
if (util.env.prod) {
return runSequence('build', ['copy', 'rename'], done);
}
return runSequence('build', 'copy', 'rename', 'watch', 'serve', done);
});