mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
ES6 has some nice new features. Specifically relevant to this piece of work are: Arrow functions[1], whose `this` context is bound the value of `this` in the current scope and can’t be overidden. The code is cleaner as a result, and doesn’t need the addition of a bind polyfill for older browsers. Template strings[2], which are similar to triple-quoted multi line strings in Python. This means less fiddly and error-prone string concatenation. This commit adds Babel[3] to the Gulp pipeline. This transpiles Javascript written to the ES6 specification into code which is compatible with older browsers that don’t understand ES6 syntax. It also rewrites the gulpfile itself using some ES6 syntax, for the same reasons. 1. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions 2. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings 3. https://babeljs.io
90 lines
2.4 KiB
JavaScript
90 lines
2.4 KiB
JavaScript
// GULPFILE
|
|
// - - - - - - - - - - - - - - -
|
|
// This file processes all of the assets in the "src" folder
|
|
// and outputs the finished files in the "dist" folder.
|
|
|
|
// 1. LIBRARIES
|
|
// - - - - - - - - - - - - - - -
|
|
var gulp = require('gulp'),
|
|
plugins = require('gulp-load-plugins')(),
|
|
|
|
// 2. CONFIGURATION
|
|
// - - - - - - - - - - - - - - -
|
|
paths = {
|
|
src: 'app/assets/',
|
|
dist: 'app/static/',
|
|
templates: 'app/templates/'
|
|
};
|
|
|
|
// 3. TASKS
|
|
// - - - - - - - - - - - - - - -
|
|
|
|
// Move GOV.UK template resources
|
|
|
|
gulp.task('copy:govuk_template:template', () => gulp.src('bower_components/govuk_template/views/layouts/govuk_template.html')
|
|
.pipe(gulp.dest(paths.templates))
|
|
);
|
|
|
|
gulp.task('copy:govuk_template:assets', () => gulp.src('bower_components/govuk_template/assets/**/*')
|
|
.pipe(gulp.dest(paths.dist))
|
|
);
|
|
|
|
|
|
// Concatenate and minify
|
|
|
|
gulp.task('jquery', () => plugins.jquery.src({
|
|
release: 1,
|
|
flags: [
|
|
'-ajax', '-ajax/jsonp', '-ajax/load', '-ajax/parseJSON',
|
|
'-ajax/parseXML', '-ajax/script', '-ajax/var/nonce',
|
|
'-ajax/var/rquery', '-ajax/xhr', '-manipulation/_evalUrl',
|
|
'-deprecated', '-effects', '-effects/Tween',
|
|
'-effects/animatedSelector', '-effects/support', '-event-alias'
|
|
]
|
|
})
|
|
.pipe(gulp.dest(paths.dist + 'javascripts/'))
|
|
);
|
|
|
|
gulp.task('javascripts', () => gulp.src([
|
|
paths.src + 'govuk_frontend_toolkit/javascripts/govuk/modules.js',
|
|
paths.src + 'javascripts/highlightTags.js',
|
|
paths.src + 'javascripts/main.js'
|
|
])
|
|
.pipe(plugins.babel({
|
|
presets: ['es2015']
|
|
}))
|
|
.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.sass({outputStyle: 'compressed'}))
|
|
.pipe(gulp.dest(paths.dist + '/stylesheets'))
|
|
);
|
|
|
|
|
|
// Copy images
|
|
|
|
gulp.task('images', () => gulp.src(paths.src + 'images/**/*')
|
|
.pipe(gulp.dest(paths.dist + '/images'))
|
|
);
|
|
|
|
|
|
// 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']);
|
|
});
|
|
|
|
// Default: compile everything
|
|
gulp.task('default',
|
|
['copy:govuk_template:template', 'copy:govuk_template:assets', 'javascripts', 'sass', 'images']
|
|
);
|
|
|
|
// Optional: recompile on changes
|
|
gulp.task('watch',
|
|
['default', 'watchForChanges']
|
|
);
|