forked from bakape/shamichan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
85 lines (73 loc) · 1.98 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
// Builds client JS, CSS and JSON
'use strict'
const gulp = require('gulp'),
gutil = require('gulp-util'),
less = require('gulp-less'),
cssmin = require('gulp-clean-css'),
sourcemaps = require('gulp-sourcemaps'),
ts = require('gulp-typescript'),
uglify = require('gulp-uglify')
// Keep script alive and rebuild on file changes
// Triggered with the `-w` flag
const watch = gutil.env.w
// Dependency tasks for the default tasks
const tasks = []
// Client JS files
createTask("client", `client/**/*.ts`, src =>
src.pipe(sourcemaps.init())
.pipe(ts.createProject("client/tsconfig.json", {
typescript: require("typescript"),
})())
.on('error', handleError)
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('www/js'))
)
// Various little scripts
createTask('scripts', 'clientScripts/*.js', src =>
src.pipe(sourcemaps.init())
.pipe(uglify())
.on('error', handleError)
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('www/js/scripts'))
)
// Compile Less to CSS
{
const name = "css"
tasks.push(name)
gulp.task(name, () =>
gulp.src(['less/*.less', '!less/*.mix.less'])
.pipe(sourcemaps.init())
.pipe(less())
.on('error', handleError)
.pipe(cssmin())
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('www/css'))
)
// Recompile on source update, if running with the `-w` flag
if (watch) {
gulp.watch('less/*.less', () =>
gulp.start('css'))
}
}
gulp.task('default', tasks)
// Simply log the error on continuos builds, but fail the build and exit with
// an error status, if failing a one-time build. This way we can use failure to
// build the client to not pass Travis CL tests.
function handleError(err) {
if (!watch) {
throw err
} else {
console.error(err.message)
}
}
// Create a new gulp task and set it to execute on default and incrementally
function createTask(name, path, task) {
tasks.push(name)
gulp.task(name, () =>
task(gulp.src(path))
)
// Recompile on source update, if running with the `-w` flag
if (watch) {
gulp.watch(path, [name])
}
}