forked from ONSdigital/eq-survey-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
executable file
·194 lines (167 loc) · 3.94 KB
/
gulpfile.babel.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import gulp from 'gulp'
import gutil from 'gulp-util'
import del from 'del'
import yargs from 'yargs'
import prettify from 'gulp-jsbeautifier'
import diff from 'gulp-diff'
import { paths } from './gulp/paths'
import { copyScripts, bundle, lint as lintScripts, lintFunctionalTests } from './gulp/scripts'
import { unitTests } from './gulp/tests'
import { sprite, images } from './gulp/images'
import { styles, lint as lintStyles } from './gulp/styles'
import browserSync from './gulp/bs'
import a11ym from './gulp/a11ym'
import { fonts } from './gulp/fonts'
import { favicons } from './gulp/favicons'
const getEnv = () => {
let env = yargs.argv.env
if (env && env.startsWith('http')) {
return env
}
const envs = {
local: 'http://localhost:5000',
docker: 'http://localhost',
preprod: 'https://eq.onsdigital.uk'
}
return envs[env] || envs['local']
}
gulp.task('test:a11ym', done => {
a11ym(done)
})
// Process, lint, and minify Sass files
gulp.task('build:styles', () => {
gutil.log('build:styles')
styles()
})
// Lint scripts
gulp.task('lint:styles', () => {
lintStyles()
})
// Remove pre-existing content from output and test folders
gulp.task('clean:dist', () => {
del.sync([paths.output], { force: true })
})
// Remove pre-existing content from text folders
gulp.task('clean:test', () => {
del.sync([paths.test.coverage, paths.test.results], { force: true })
})
gulp.task('test:scripts', [
'test:scripts:unit'
])
gulp.task('test:scripts:unit', done => {
unitTests(done, false)
})
gulp.task('test:scripts:unit:watch', done => {
unitTests(done, true)
})
gulp.task('test:a11ym', done => {
a11ym(done)
})
// Spin up livereload server and listen for file changes
gulp.task('listen', () => {
browserSync.init({
proxy: process.env.EQ_SURVEY_RUNNER_URL,
open: false,
port: 5075,
ui: {
port: 5076
}
})
gulp.watch(paths.images.input, ['build:images'])
gulp.watch(paths.styles.input_all, ['build:styles'])
gulp.watch(
[paths.scripts.input, `!${paths.scripts.dir}app/**/*`],
['copy:scripts']
)
gulp.watch(paths.templates.input).on('change', browserSync.reload)
})
gulp.task('bundle:scripts', () => {
bundle()
})
gulp.task('copy:scripts', () => {
copyScripts()
})
gulp.task('watch:scripts', () => {
bundle(true)
})
// Lint scripts
gulp.task('lint:scripts', () => {
lintScripts()
})
gulp.task('lint:tests', () => {
lintFunctionalTests()
})
// Generate SVG sprites
gulp.task('build:sprite', () => {
sprite()
})
// Copy image files into output folder
gulp.task('build:images', () => {
images()
})
// Copy font files into output folder
gulp.task('build:fonts', () => {
fonts()
})
// Copy favicons files into output folder
gulp.task('build:favicons', () => {
favicons()
})
/**
* Task Runners
*/
// Compile files
gulp.task('compile', [
'clean:dist',
'lint:scripts',
'lint:styles',
'lint:tests',
'build:sprite',
'bundle:scripts',
'copy:scripts',
'build:styles',
'build:images',
'build:fonts',
'build:favicons'
])
/**
* First bundle, then serve from the ./app directory
*/
gulp.task('default', ['compile'])
// Compile files and generate docs when something changes
gulp.task('watch', [
'clean:dist',
'build:sprite',
'build:styles',
'build:images',
'watch:scripts',
'build:fonts',
'build:favicons',
'listen'
])
// Run unit tests
gulp.task('test', ['default', 'test:scripts'])
// Run unit tests
gulp.task('lint', ['lint:styles', 'lint:scripts', 'lint:json', 'lint:tests'])
gulp.task('lint:json', () => {
return gulp
.src(['./data/*/*.json'])
.pipe(prettify({end_with_newline: true}))
.pipe(diff())
.pipe(
diff.reporter({
quiet: false,
fail: true
})
)
.on('error', err => {
gutil.log('Linting failed try running `yarn format`')
throw err
})
})
gulp.task('format:json', () => {
return gulp
.src(['./data/*/*.json'])
.pipe(prettify({end_with_newline: true}))
.pipe(gulp.dest('./data/'))
})