-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
100 lines (89 loc) · 2.48 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
const sassjs = require('sass')
const mkdirp = require('mkdirp')
const fs = require('fs')
const gulp = require('gulp')
// const jest = require('gulp-jest').default
function nodeChanges () {
const nodemon = require('nodemon')
return nodemon({
script: 'app/index.js',
ext: 'js,html,njk,json',
env: { 'NODE_ENV': 'development', 'SURVEY': 'NO', 'AVAILABLE': 'TRUE' },
cwd: __dirname,
ignore: ['node_modules/**'],
watch: ['app/*.js', 'app/templates/**/*.njk', 'app/decisionTree/*.js', 'app/*.json', 'app/dbTree/*.js', 'app/dbTree/templates/*.njk']
})
}
function watch () {
gulp.watch('sass/**/*.scss', gulp.series(['sass']))
gulp.watch('app/assets', gulp.series(['assets']))
return nodeChanges()
}
function sass () {
return new Promise((resolve, reject) => {
sassjs.render({
file: 'sass/main.scss',
includePaths: ['node_modules/govuk-elements-sass/public/sass',
'node_modules/govuk_frontend_toolkit/stylesheets'
],
// outFile: 'app/assets/styles',
outputStyle: 'compressed'
}, function (err, result) {
if (!err) {
// No errors during the compilation, write this result on the disk
mkdirp.sync('public/assets/styles')
fs.writeFile('public/assets/styles/main.css', result.css, function (err) {
if (err) {
return reject(err)
}
return resolve()
})
} else {
console.log('ERROR', err)
}
})
})
}
function assets () {
// /node_modules/govuk-frontend/dist/govuk/assets
return gulp
.src([
'node_modules/govuk-frontend/dist/govuk/assets/**/*.*',
'node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js',
'app/assets/**/*.*'
])
.pipe(gulp.dest('public/assets'))
}
function jestTest () {
const jest = require('gulp-jest').default
return gulp
.src('app/**/*.test.js')
.pipe(jest({
"preprocessorIgnorePatterns": [
"<rootDir>/public/", "<rootDir>/node_modules/"
],
"automock": false,
"coverage": true
}))
}
function build (done) {
return gulp.series(assets, sass)(done)
}
function cucumber(done) {
const exec = require('child_process').exec
exec('./node_modules/.bin/cucumber-js --format node_modules/cucumber-pretty', { maxBuffer: 1024 * 500 }, (err, stdout, stderr) => {
console.log(stdout)
console.log(stderr)
console.log(!!err)
done(err)
})
}
module.exports = {
watch,
sass,
assets,
nodeChanges,
default: build,
cucumber,
jest: jestTest
}