-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
107 lines (88 loc) · 2.89 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
var gulp = require('gulp')
var tsc = require('gulp-typescript')
var uglify = require('gulp-uglify')
var nodemon = require('gulp-nodemon')
var tsfmt = require('gulp-tsfmt')
var changedInPlace = require('gulp-changed-in-place')
var changed = require('gulp-changed')
var sourcemaps = require('gulp-sourcemaps')
var browserSync = require('browser-sync').create()
var path = require('path')
var rm = require('del')
// projects config
var project = {
"project": tsc.createProject('./tsconfig.json', {
"module": "commonjs",
"watch": false
}),
"tsfmt": {
"IndentSize": 4,
"TabSize": 4,
"NewLineCharacter": "\n",
"ConvertTabsToSpaces": true,
"InsertSpaceAfterCommaDelimiter": true,
"InsertSpaceAfterSemicolonInForStatements": true,
"InsertSpaceBeforeAndAfterBinaryOperators": true,
"InsertSpaceAfterKeywordsInControlFlowStatements": true,
"InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"PlaceOpenBraceOnNewLineForFunctions": false,
"PlaceOpenBraceOnNewLineForControlBlocks": false
},
"src": "./server/**/*.ts",
"build": "./build/server",
"dist": "./dist/server",
"static": "./public/**"
}
gulp.task('tsc', () => {
gulp.src(path.normalize(project.src))
.pipe(sourcemaps.init())
.pipe(tsc(project.project))
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.normalize(project.build)))
})
gulp.task('tsformat', () => {
gulp.src('./server')
.pipe(changedInPlace({firstPass: true}))
.pipe(tsfmt({options: project.tsfmt}))
.pipe(gulp.dest(project.src))
})
gulp.task('build', ['tsc', 'copy-static'], () => {})
gulp.task('dist', ['tsc', 'copy-static'], () => {
// Sourcemaps are included
gulp.src(path.normalize(project.build + '/**/*.js'))
.pipe(uglify())
.pipe(gulp.dest(path.normalize(project.dist)))
})
gulp.task('watch:server', ['serve'], () => {
gulp.watch(path.normalize(project.src), ['tsformat', 'tsc'])
})
gulp.task('watch:public', ['serve'], () => {
browserSync.init({
port: 9000,
open: false,
server: { baseDir:'./public' },
ui: {port: 9001}
})
gulp.watch(path.normalize(project.static))
.on('change', browserSync.reload)
})
gulp.task('copy-static', () => {
gulp.src(path.normalize(project.static))
.pipe(changed(path.normalize(path.join(project.build, 'public'))))
.pipe(gulp.dest(path.normalize(path.join(project.build, 'public'))))
// .pipe(gulp.dest(path.normalize(path.join(project.dist, 'public'))))
})
gulp.task('serve', ['build'], () => {
nodemon({script: './build/server/go.js'})
})
gulp.task('clean:build', () => {
rm('./build/**')
.then((cleaned) => {console.log('Cleaned build\n', cleaned)})
})
gulp.task('clean:dist', () => {
rm('./dist/**')
.then((cleaned) => {console.log('Cleaned dist\n', cleaned)})
})
gulp.task('clean', ['clean:build', 'clean:dist'], () => {})
gulp.task('default', ['clean', 'dist'], () => {})