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
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
2016-07-19 15:13:23 +01:00
|
|
|
import gulp from 'gulp';
|
|
|
|
|
import loadPlugins from 'gulp-load-plugins';
|
|
|
|
|
import stylish from 'jshint-stylish';
|
2019-02-06 16:09:39 +00:00
|
|
|
import runSequence from 'run-sequence';
|
2016-07-19 15:13:23 +01:00
|
|
|
|
|
|
|
|
const plugins = loadPlugins(),
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// 2. CONFIGURATION
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
|
|
|
|
paths = {
|
|
|
|
|
src: 'app/assets/',
|
|
|
|
|
dist: 'app/static/',
|
2016-01-14 15:53:19 +00:00
|
|
|
templates: 'app/templates/',
|
2016-02-20 14:48:23 +00:00
|
|
|
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
|
|
|
|
|
|
2016-02-20 14:48:23 +00:00
|
|
|
gulp.task('copy:govuk_template:template', () => gulp.src(paths.template + 'views/layouts/govuk_template.html')
|
2015-12-20 00:00:01 +00:00
|
|
|
.pipe(gulp.dest(paths.templates))
|
|
|
|
|
);
|
|
|
|
|
|
2016-02-20 14:48:23 +00:00
|
|
|
gulp.task('copy:govuk_template:css', () => gulp.src(paths.template + 'assets/stylesheets/**/*.css')
|
2016-03-23 10:41:37 +00:00
|
|
|
.pipe(plugins.sass({
|
|
|
|
|
outputStyle: 'compressed'
|
|
|
|
|
}))
|
|
|
|
|
.on('error', plugins.sass.logError)
|
2016-02-23 10:56:48 +00:00
|
|
|
.pipe(plugins.cssUrlAdjuster({
|
2018-11-29 12:18:00 +00:00
|
|
|
prependRelative: process.env.NOTIFY_ENVIRONMENT == 'development' ? '/static/' : '/',
|
2016-02-23 10:56:48 +00:00
|
|
|
}))
|
2016-02-20 14:48:23 +00:00
|
|
|
.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/'))
|
2015-12-20 00:00:01 +00:00
|
|
|
);
|
|
|
|
|
|
2016-02-23 10:56:48 +00:00
|
|
|
gulp.task('copy:govuk_template:images', () => gulp.src(paths.template + 'assets/stylesheets/images/**/*')
|
|
|
|
|
.pipe(gulp.dest(paths.dist + 'images/'))
|
|
|
|
|
);
|
|
|
|
|
|
2018-04-27 14:12:02 +01:00
|
|
|
gulp.task('copy:govuk_template:fonts', () => gulp.src(paths.template + 'assets/stylesheets/fonts/**/*')
|
|
|
|
|
.pipe(gulp.dest(paths.dist + 'fonts/'))
|
|
|
|
|
);
|
|
|
|
|
|
2016-01-12 13:37:50 +00:00
|
|
|
gulp.task('javascripts', () => gulp
|
|
|
|
|
.src([
|
2016-02-20 14:48:23 +00:00
|
|
|
paths.toolkit + 'javascripts/govuk/modules.js',
|
2018-08-09 11:59:05 +01:00
|
|
|
paths.toolkit + 'javascripts/govuk/show-hide-content.js',
|
2018-11-08 12:20:57 +00:00
|
|
|
paths.src + 'javascripts/stick-to-window-when-scrolling.js',
|
2016-05-17 14:46:34 +01:00
|
|
|
paths.src + 'javascripts/detailsPolyfill.js',
|
2016-01-15 10:50:10 +00:00
|
|
|
paths.src + 'javascripts/apiKey.js',
|
2016-02-02 16:16:29 +00:00
|
|
|
paths.src + 'javascripts/autofocus.js',
|
2016-01-15 10:50:10 +00:00
|
|
|
paths.src + 'javascripts/highlightTags.js',
|
2016-02-02 17:28:30 +00:00
|
|
|
paths.src + 'javascripts/fileUpload.js',
|
2016-04-11 15:16:41 +01:00
|
|
|
paths.src + 'javascripts/expandCollapse.js',
|
2016-08-07 09:17:49 +01:00
|
|
|
paths.src + 'javascripts/radioSelect.js',
|
|
|
|
|
paths.src + 'javascripts/updateContent.js',
|
2016-09-20 12:30:00 +01:00
|
|
|
paths.src + 'javascripts/listEntry.js',
|
2017-03-14 10:46:38 +00:00
|
|
|
paths.src + 'javascripts/liveSearch.js',
|
2018-08-08 08:49:16 +01:00
|
|
|
paths.src + 'javascripts/errorTracking.js',
|
2017-09-15 14:10:21 +01:00
|
|
|
paths.src + 'javascripts/preventDuplicateFormSubmissions.js',
|
2017-10-29 22:18:46 +00:00
|
|
|
paths.src + 'javascripts/fullscreenTable.js',
|
2019-02-14 14:06:31 +00:00
|
|
|
paths.src + 'javascripts/previewPane.js',
|
2018-08-20 13:27:50 +01:00
|
|
|
paths.src + 'javascripts/colourPreview.js',
|
2018-11-28 17:40:54 +00:00
|
|
|
paths.src + 'javascripts/templateFolderForm.js',
|
2015-12-20 00:00:01 +00:00
|
|
|
paths.src + 'javascripts/main.js'
|
|
|
|
|
])
|
2017-03-13 13:17:20 +00:00
|
|
|
.pipe(plugins.prettyerror())
|
2015-12-20 00:00:01 +00:00
|
|
|
.pipe(plugins.babel({
|
|
|
|
|
presets: ['es2015']
|
|
|
|
|
}))
|
2016-01-15 10:50:10 +00:00
|
|
|
.pipe(plugins.addSrc.prepend([
|
2016-09-20 12:30:00 +01:00
|
|
|
paths.npm + 'hogan.js/dist/hogan-3.0.2.js',
|
2016-01-15 10:50:10 +00:00
|
|
|
paths.npm + 'jquery/dist/jquery.min.js',
|
2016-04-27 09:28:42 +01:00
|
|
|
paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js',
|
2016-09-28 17:47:40 +01:00
|
|
|
paths.npm + 'diff-dom/diffDOM.js',
|
2019-03-21 16:51:27 +00:00
|
|
|
paths.npm + 'timeago/jquery.timeago.js',
|
|
|
|
|
paths.npm + 'textarea-caret/index.js'
|
2016-01-15 10:50:10 +00:00
|
|
|
]))
|
2016-10-08 13:31:19 +01:00
|
|
|
.pipe(plugins.uglify())
|
2015-12-20 00:00:01 +00:00
|
|
|
.pipe(plugins.concat('all.js'))
|
|
|
|
|
.pipe(gulp.dest(paths.dist + 'javascripts/'))
|
|
|
|
|
);
|
|
|
|
|
|
2016-01-12 13:37:50 +00:00
|
|
|
gulp.task('sass', () => gulp
|
|
|
|
|
.src(paths.src + '/stylesheets/main*.scss')
|
2017-03-13 13:17:20 +00:00
|
|
|
.pipe(plugins.prettyerror())
|
2016-01-14 15:53:19 +00:00
|
|
|
.pipe(plugins.sass({
|
|
|
|
|
outputStyle: 'compressed',
|
|
|
|
|
includePaths: [
|
|
|
|
|
paths.npm + 'govuk-elements-sass/public/sass/',
|
2016-02-20 14:48:23 +00:00
|
|
|
paths.toolkit + 'stylesheets/'
|
2016-01-14 15:53:19 +00:00
|
|
|
]
|
|
|
|
|
}))
|
2016-02-20 14:48:23 +00:00
|
|
|
.pipe(plugins.base64({baseDir: 'app'}))
|
|
|
|
|
.pipe(gulp.dest(paths.dist + 'stylesheets/'))
|
2015-12-20 00:00:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy images
|
|
|
|
|
|
2016-01-12 13:37:50 +00:00
|
|
|
gulp.task('images', () => gulp
|
2016-01-14 15:53:19 +00:00
|
|
|
.src([
|
|
|
|
|
paths.src + 'images/**/*',
|
2016-02-20 14:48:23 +00:00
|
|
|
paths.toolkit + 'images/**/*',
|
|
|
|
|
paths.template + 'assets/images/**/*'
|
2016-01-14 15:53:19 +00:00
|
|
|
])
|
2016-02-20 14:48:23 +00:00
|
|
|
.pipe(gulp.dest(paths.dist + 'images/'))
|
2015-12-20 00:00:01 +00:00
|
|
|
);
|
|
|
|
|
|
2016-09-12 16:11:34 +01:00
|
|
|
gulp.task('copy:govuk_template:error_page', () => gulp.src(paths.src + 'error_pages/**/*')
|
|
|
|
|
.pipe(gulp.dest(paths.dist + 'error_pages/'))
|
|
|
|
|
);
|
|
|
|
|
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// 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']);
|
2016-02-19 15:02:13 +00:00
|
|
|
gulp.watch('gulpfile.babel.js', ['default']);
|
2015-12-20 00:00:01 +00:00
|
|
|
});
|
|
|
|
|
|
2016-02-08 11:05:07 +00:00
|
|
|
gulp.task('lint:sass', () => gulp
|
2016-04-13 12:50:13 +01:00
|
|
|
.src([
|
|
|
|
|
paths.src + 'stylesheets/*.scss',
|
|
|
|
|
paths.src + 'stylesheets/components/*.scss',
|
|
|
|
|
paths.src + 'stylesheets/views/*.scss',
|
|
|
|
|
])
|
2016-02-26 13:19:46 +00:00
|
|
|
.pipe(plugins.sassLint())
|
|
|
|
|
.pipe(plugins.sassLint.format(stylish))
|
|
|
|
|
.pipe(plugins.sassLint.failOnError())
|
2016-02-08 11:05:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
gulp.task('lint:js', () => gulp
|
|
|
|
|
.src(paths.src + 'javascripts/**/*.js')
|
2017-11-06 17:37:15 +00:00
|
|
|
.pipe(plugins.jshint())
|
2016-02-08 11:05:07 +00:00
|
|
|
.pipe(plugins.jshint.reporter(stylish))
|
|
|
|
|
.pipe(plugins.jshint.reporter('fail'))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
gulp.task('lint',
|
|
|
|
|
['lint:sass', 'lint:js']
|
|
|
|
|
);
|
|
|
|
|
|
2015-12-20 00:00:01 +00:00
|
|
|
// Default: compile everything
|
2019-02-06 16:09:39 +00:00
|
|
|
gulp.task('default', function() {
|
|
|
|
|
runSequence(
|
|
|
|
|
[
|
|
|
|
|
'copy:govuk_template:template',
|
|
|
|
|
'copy:govuk_template:images',
|
|
|
|
|
'copy:govuk_template:fonts',
|
|
|
|
|
'copy:govuk_template:css',
|
|
|
|
|
'copy:govuk_template:js',
|
|
|
|
|
'images',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'copy:govuk_template:error_page',
|
|
|
|
|
'javascripts',
|
|
|
|
|
'sass'
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
});
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
// Optional: recompile on changes
|
|
|
|
|
gulp.task('watch',
|
|
|
|
|
['default', 'watchForChanges']
|
|
|
|
|
);
|