2015-12-20 00:00:01 +00:00
|
|
|
// GULPFILE
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
|
|
|
|
// This file processes all of the assets in the "src" folder
|
|
|
|
|
// and outputs the finished files in the "dist" folder.
|
|
|
|
|
|
|
|
|
|
// 1. LIBRARIES
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
2019-04-01 09:58:13 +01:00
|
|
|
const { src, pipe, dest, series, parallel } = require('gulp');
|
|
|
|
|
const loadPlugins = require('gulp-load-plugins');
|
|
|
|
|
const stylish = require('jshint-stylish');
|
2016-07-19 15:13:23 +01:00
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
const plugins = loadPlugins();
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// 2. CONFIGURATION
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
2019-04-01 09:58:13 +01:00
|
|
|
const 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/'
|
|
|
|
|
};
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// 3. TASKS
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
|
|
|
|
|
|
|
|
|
// Move GOV.UK template resources
|
|
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
const copy = {
|
|
|
|
|
govuk_template: {
|
|
|
|
|
template: () => {
|
|
|
|
|
return src(paths.template + 'views/layouts/govuk_template.html')
|
|
|
|
|
.pipe(dest(paths.templates));
|
|
|
|
|
},
|
|
|
|
|
css: () => {
|
|
|
|
|
return src(paths.template + 'assets/stylesheets/**/*.css')
|
|
|
|
|
.pipe(plugins.sass({
|
|
|
|
|
outputStyle: 'compressed'
|
|
|
|
|
}))
|
|
|
|
|
.on('error', plugins.sass.logError)
|
|
|
|
|
.pipe(plugins.cssUrlAdjuster({
|
|
|
|
|
prependRelative: process.env.NOTIFY_ENVIRONMENT == 'development' ? '/static/' : '/',
|
|
|
|
|
}))
|
|
|
|
|
.pipe(dest(paths.dist + 'stylesheets/'));
|
|
|
|
|
},
|
|
|
|
|
js: () => {
|
|
|
|
|
return src(paths.template + 'assets/javascripts/**/*.js')
|
|
|
|
|
.pipe(plugins.uglify())
|
|
|
|
|
.pipe(dest(paths.dist + 'javascripts/'));
|
|
|
|
|
},
|
|
|
|
|
images: () => {
|
|
|
|
|
return src(paths.template + 'assets/stylesheets/images/**/*')
|
|
|
|
|
.pipe(dest(paths.dist + 'images/'));
|
|
|
|
|
},
|
|
|
|
|
fonts: () => {
|
|
|
|
|
return src(paths.template + 'assets/stylesheets/fonts/**/*')
|
|
|
|
|
.pipe(dest(paths.dist + 'fonts/'));
|
|
|
|
|
},
|
|
|
|
|
error_page: () => {
|
|
|
|
|
return src(paths.src + 'error_pages/**/*')
|
|
|
|
|
.pipe(dest(paths.dist + 'error_pages/'))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const javascripts = () => {
|
|
|
|
|
return src([
|
|
|
|
|
paths.toolkit + 'javascripts/govuk/modules.js',
|
|
|
|
|
paths.toolkit + 'javascripts/govuk/show-hide-content.js',
|
|
|
|
|
paths.src + 'javascripts/stick-to-window-when-scrolling.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/errorTracking.js',
|
|
|
|
|
paths.src + 'javascripts/preventDuplicateFormSubmissions.js',
|
|
|
|
|
paths.src + 'javascripts/fullscreenTable.js',
|
|
|
|
|
paths.src + 'javascripts/previewPane.js',
|
|
|
|
|
paths.src + 'javascripts/colourPreview.js',
|
|
|
|
|
paths.src + 'javascripts/templateFolderForm.js',
|
|
|
|
|
paths.src + 'javascripts/main.js'
|
|
|
|
|
])
|
|
|
|
|
.pipe(plugins.prettyerror())
|
|
|
|
|
.pipe(plugins.babel({
|
2019-04-01 12:09:38 +01:00
|
|
|
presets: ['@babel/preset-env']
|
2019-04-01 09:58:13 +01:00
|
|
|
}))
|
|
|
|
|
.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',
|
|
|
|
|
paths.npm + 'textarea-caret/index.js'
|
|
|
|
|
]))
|
|
|
|
|
.pipe(plugins.uglify())
|
|
|
|
|
.pipe(plugins.concat('all.js'))
|
|
|
|
|
.pipe(dest(paths.dist + 'javascripts/'))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sass = () => {
|
|
|
|
|
return 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(dest(paths.dist + 'stylesheets/'))
|
|
|
|
|
};
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy images
|
|
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
const images = () => {
|
|
|
|
|
return src([
|
|
|
|
|
paths.src + 'images/**/*',
|
|
|
|
|
paths.toolkit + 'images/**/*',
|
|
|
|
|
paths.template + 'assets/images/**/*'
|
|
|
|
|
])
|
|
|
|
|
.pipe(dest(paths.dist + 'images/'))
|
|
|
|
|
};
|
2016-09-12 16:11:34 +01:00
|
|
|
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// Watch for changes and re-run tasks
|
2019-04-01 09:58:13 +01:00
|
|
|
const watchForChanges = () => {
|
|
|
|
|
return watch(paths.src + 'javascripts/**/*', ['javascripts'])
|
|
|
|
|
.watch(paths.src + 'stylesheets/**/*', ['sass'])
|
|
|
|
|
.watch(paths.src + 'images/**/*', ['images'])
|
2019-04-01 10:06:50 +01:00
|
|
|
.watch('gulpfile.js', ['default']);
|
2019-04-01 09:58:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const lint = {
|
|
|
|
|
'sass': () => {
|
|
|
|
|
return src([
|
|
|
|
|
paths.src + 'stylesheets/*.scss',
|
|
|
|
|
paths.src + 'stylesheets/components/*.scss',
|
|
|
|
|
paths.src + 'stylesheets/views/*.scss',
|
|
|
|
|
])
|
2019-04-04 14:44:46 +01:00
|
|
|
.pipe(plugins.sassLint({
|
|
|
|
|
'options': { 'formatter': 'stylish' }
|
|
|
|
|
}))
|
|
|
|
|
.pipe(plugins.sassLint.format())
|
2019-04-01 09:58:13 +01:00
|
|
|
.pipe(plugins.sassLint.failOnError());
|
|
|
|
|
},
|
|
|
|
|
'js': (cb) => {
|
|
|
|
|
return src(paths.src + 'javascripts/**/*.js')
|
|
|
|
|
.pipe(plugins.jshint())
|
|
|
|
|
.pipe(plugins.jshint.reporter(stylish))
|
|
|
|
|
.pipe(plugins.jshint.reporter('fail'))
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-08 11:05:07 +00:00
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
// Default: compile everything
|
|
|
|
|
const defaultTask = parallel(
|
|
|
|
|
series(
|
|
|
|
|
copy.govuk_template.template,
|
|
|
|
|
copy.govuk_template.images,
|
|
|
|
|
copy.govuk_template.fonts,
|
|
|
|
|
copy.govuk_template.css,
|
|
|
|
|
copy.govuk_template.js,
|
|
|
|
|
images
|
|
|
|
|
),
|
|
|
|
|
series(
|
|
|
|
|
copy.govuk_template.error_page,
|
|
|
|
|
javascripts,
|
|
|
|
|
sass
|
|
|
|
|
)
|
2016-02-08 11:05:07 +00:00
|
|
|
);
|
|
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
exports.default = defaultTask;
|
2016-02-08 11:05:07 +00:00
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
exports.lint = series(lint.sass, lint.js);
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// Optional: recompile on changes
|
2019-04-01 09:58:13 +01:00
|
|
|
exports.watch = series(defaultTask, watchForChanges);
|