This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
forked from alphagov/notifications-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
164 lines (142 loc) · 4.57 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
// GULPFILE
// - - - - - - - - - - - - - - -
// This file processes all of the assets in the "src" folder
// and outputs the finished files in the "dist" folder.
// 1. LIBRARIES
// - - - - - - - - - - - - - - -
import gulp from 'gulp';
import loadPlugins from 'gulp-load-plugins';
import stylish from 'jshint-stylish';
const plugins = loadPlugins(),
// 2. CONFIGURATION
// - - - - - - - - - - - - - - -
paths = {
src: 'app/assets/',
dist: 'app/static/',
templates: 'app/templates/',
npm: 'node_modules/',
template: 'node_modules/govuk_template_jinja/',
toolkit: 'node_modules/govuk_frontend_toolkit/'
};
// 3. TASKS
// - - - - - - - - - - - - - - -
// Move GOV.UK template resources
gulp.task('copy:govuk_template:template', () => gulp.src(paths.template + 'views/layouts/govuk_template.html')
.pipe(gulp.dest(paths.templates))
);
gulp.task('copy:govuk_template:css', () => gulp.src(paths.template + 'assets/stylesheets/**/*.css')
.pipe(plugins.sass({
outputStyle: 'compressed'
}))
.on('error', plugins.sass.logError)
.pipe(plugins.cssUrlAdjuster({
prependRelative: '/static/',
}))
.pipe(gulp.dest(paths.dist + 'stylesheets/'))
);
gulp.task('copy:govuk_template:js', () => gulp.src(paths.template + 'assets/javascripts/**/*.js')
.pipe(plugins.uglify())
.pipe(gulp.dest(paths.dist + 'javascripts/'))
);
gulp.task('copy:govuk_template:images', () => gulp.src(paths.template + 'assets/stylesheets/images/**/*')
.pipe(gulp.dest(paths.dist + 'images/'))
);
gulp.task('javascripts', () => gulp
.src([
paths.toolkit + 'javascripts/govuk/modules.js',
paths.toolkit + 'javascripts/govuk/selection-buttons.js',
paths.src + 'javascripts/detailsPolyfill.js',
paths.src + 'javascripts/apiKey.js',
paths.src + 'javascripts/autofocus.js',
paths.src + 'javascripts/highlightTags.js',
paths.src + 'javascripts/fileUpload.js',
paths.src + 'javascripts/expandCollapse.js',
paths.src + 'javascripts/radioSelect.js',
paths.src + 'javascripts/updateContent.js',
paths.src + 'javascripts/listEntry.js',
paths.src + 'javascripts/liveSearch.js',
paths.src + 'javascripts/main.js'
])
.pipe(plugins.prettyerror())
.pipe(plugins.babel({
presets: ['es2015']
}))
.pipe(plugins.addSrc.prepend([
paths.npm + 'hogan.js/dist/hogan-3.0.2.js',
paths.npm + 'jquery/dist/jquery.min.js',
paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js',
paths.npm + 'diff-dom/diffDOM.js',
paths.npm + 'timeago/jquery.timeago.js'
]))
.pipe(plugins.uglify())
.pipe(plugins.concat('all.js'))
.pipe(gulp.dest(paths.dist + 'javascripts/'))
);
gulp.task('sass', () => gulp
.src(paths.src + '/stylesheets/main*.scss')
.pipe(plugins.prettyerror())
.pipe(plugins.sass({
outputStyle: 'compressed',
includePaths: [
paths.npm + 'govuk-elements-sass/public/sass/',
paths.toolkit + 'stylesheets/'
]
}))
.pipe(plugins.base64({baseDir: 'app'}))
.pipe(gulp.dest(paths.dist + 'stylesheets/'))
);
// Copy images
gulp.task('images', () => gulp
.src([
paths.src + 'images/**/*',
paths.toolkit + 'images/**/*',
paths.template + 'assets/images/**/*'
])
.pipe(gulp.dest(paths.dist + 'images/'))
);
gulp.task('copy:govuk_template:error_page', () => gulp.src(paths.src + 'error_pages/**/*')
.pipe(gulp.dest(paths.dist + 'error_pages/'))
);
// Watch for changes and re-run tasks
gulp.task('watchForChanges', function() {
gulp.watch(paths.src + 'javascripts/**/*', ['javascripts']);
gulp.watch(paths.src + 'stylesheets/**/*', ['sass']);
gulp.watch(paths.src + 'images/**/*', ['images']);
gulp.watch('gulpfile.babel.js', ['default']);
});
gulp.task('lint:sass', () => gulp
.src([
paths.src + 'stylesheets/*.scss',
paths.src + 'stylesheets/components/*.scss',
paths.src + 'stylesheets/views/*.scss',
])
.pipe(plugins.sassLint())
.pipe(plugins.sassLint.format(stylish))
.pipe(plugins.sassLint.failOnError())
);
gulp.task('lint:js', () => gulp
.src(paths.src + 'javascripts/**/*.js')
.pipe(plugins.jshint({'esversion': 6, 'esnext': false}))
.pipe(plugins.jshint.reporter(stylish))
.pipe(plugins.jshint.reporter('fail'))
);
gulp.task('lint',
['lint:sass', 'lint:js']
);
// Default: compile everything
gulp.task('default',
[
'copy:govuk_template:template',
'copy:govuk_template:images',
'copy:govuk_template:css',
'copy:govuk_template:js',
'copy:govuk_template:error_page',
'javascripts',
'sass',
'images'
]
);
// Optional: recompile on changes
gulp.task('watch',
['default', 'watchForChanges']
);