-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
168 lines (138 loc) · 4.61 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'use strict'
const paths = require('./config/paths.json')
const gulp = require('gulp')
const gutil = require('gulp-util')
const cssnano = require('gulp-cssnano')
const del = require('del')
const mocha = require('gulp-mocha')
const nodemon = require('gulp-nodemon')
const rename = require('gulp-rename')
const runsequence = require('run-sequence')
const sass = require('gulp-sass')
// Clean task ----------------------------
// Deletes the /public directory
// ---------------------------------------
gulp.task('clean', () => {
return del(paths.public)
})
// Build task ----------------------------
// Runs tasks that copy assets to the public directory.
// ---------------------------------------
gulp.task('build', cb => {
runsequence('clean', ['styles', 'images', 'fonts', 'scripts', 'examplescripts'], cb)
})
// Styles build task ---------------------
// Compiles CSS from Sass
// Output both a minified and non-minified version into /public/stylesheets/
// ---------------------------------------
gulp.task('styles', () => {
return gulp.src(paths.assetsScss + '**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.publicCss))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano())
.pipe(gulp.dest(paths.publicCss))
})
// Images build task ---------------------
// Copies images to /public/images
// ---------------------------------------
gulp.task('images', () => {
return gulp.src(paths.assetsImg + '**/*')
.pipe(gulp.dest(paths.publicImg))
})
// Font build task ---------------------
// Copies images to /public/images
// ---------------------------------------
gulp.task('fonts', () => {
return gulp.src(paths.assetsFnt + '**/*')
.pipe(gulp.dest(paths.publicFnt))
})
// Scripts build task ---------------------
// Copies JavaScript to /public/javascripts
// ---------------------------------------
gulp.task('scripts', () => {
return gulp.src(paths.assetsJs + '**/*.js')
.pipe(gulp.dest(paths.publicJs))
})
// Example scripts build task ---------------------
// Copies JavaScript to /public/javascripts
// ---------------------------------------
gulp.task('examplescripts', () => {
return gulp.src(paths.assetsJs + '**/*.js')
.pipe(gulp.dest(paths.publicJs))
})
// Server task --------------------------
// Configures nodemon
// ---------------------------------------
gulp.task('server', () => {
nodemon({
watch: ['.env', '**/*.js', '**/*.json'],
script: 'server.js',
ignore: [
paths.public + '*',
paths.assets + '*',
paths.nodeModules + '*'
]
})
})
// Test task --------------------------
// Check that the build task copies assets
// to /public and that the app runs.
// ---------------------------------------
gulp.task('test', cb => {
runsequence('build', ['test:app'], cb)
})
gulp.task('test:app', () =>
gulp.src(paths.testSpecs + 'app_spec.js', {read: false})
.pipe(mocha({reporter: 'spec'}))
// https://github.com/sindresorhus/gulp-mocha#test-suite-not-exiting
.once('error', () => {
process.exit(1)
})
.once('end', () => {
process.exit()
})
)
// Watch task ----------------------------
// When a file is changed, re-run the build task.
// ---------------------------------------
gulp.task('watch', ['watch:styles', 'watch:scripts', 'watch:examplescripts', 'watch:images'])
gulp.task('watch:styles', () => {
return gulp.watch(paths.assetsScss + '**/*.scss', ['styles'])
})
gulp.task('watch:scripts', () => {
return gulp.watch(paths.assetsJs + '**/*.js', ['scripts'])
})
gulp.task('watch:examplescripts', () => {
return gulp.watch(paths.assetsJs + '**/*.js', ['examplescripts'])
})
gulp.task('watch:images', () => {
return gulp.watch(paths.assetsImg + '**/*', ['images'])
})
// Develop task --------------------------
// Runs copy-assets task and sets up watches.
// ---------------------------------------
gulp.task('develop', cb => {
runsequence('build',
'watch',
'server', cb)
})
// Default task --------------------------
// Lists out available tasks.
// ---------------------------------------
gulp.task('default', () => {
const cyan = gutil.colors.cyan
const green = gutil.colors.green
gutil.log(green('----------'))
gutil.log(('The following main ') + cyan('tasks') + (' are available:'))
gutil.log(cyan('build'
) + ': copies assets to the public directory.'
)
gutil.log(cyan('develop'
) + ': performs an initial build then sets up watches.'
)
gutil.log(cyan('package'
) + ': prepares the govuk-elements-sass npm package'
)
gutil.log(green('----------'))
})