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
|
|
|
|
|
// - - - - - - - - - - - - - - -
|
|
|
|
|
var gulp = require('gulp'),
|
|
|
|
|
plugins = require('gulp-load-plugins')(),
|
2016-02-08 11:05:07 +00:00
|
|
|
stylish = require('jshint-stylish'),
|
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({
|
2016-03-23 14:14:50 +00:00
|
|
|
prependRelative: '/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/'))
|
|
|
|
|
);
|
|
|
|
|
|
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',
|
|
|
|
|
paths.toolkit + 'javascripts/govuk/selection-buttons.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-03-02 17:36:20 +00:00
|
|
|
paths.src + 'javascripts/updateContent.js',
|
2016-04-11 15:16:41 +01:00
|
|
|
paths.src + 'javascripts/expandCollapse.js',
|
2015-12-20 00:00:01 +00:00
|
|
|
paths.src + 'javascripts/main.js'
|
|
|
|
|
])
|
|
|
|
|
.pipe(plugins.babel({
|
|
|
|
|
presets: ['es2015']
|
|
|
|
|
}))
|
2016-01-12 13:37:50 +00:00
|
|
|
.pipe(plugins.uglify())
|
2016-01-15 10:50:10 +00:00
|
|
|
.pipe(plugins.addSrc.prepend([
|
|
|
|
|
paths.npm + 'jquery/dist/jquery.min.js',
|
2016-04-27 09:28:42 +01:00
|
|
|
paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js',
|
|
|
|
|
paths.npm + 'diff-dom/diffDOM.js'
|
2016-01-15 10:50:10 +00:00
|
|
|
]))
|
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')
|
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
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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')
|
|
|
|
|
.pipe(plugins.jshint({'esversion': 6, 'esnext': false}))
|
|
|
|
|
.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
|
|
|
|
|
gulp.task('default',
|
2016-02-20 14:48:23 +00:00
|
|
|
[
|
|
|
|
|
'copy:govuk_template:template',
|
2016-02-23 10:56:48 +00:00
|
|
|
'copy:govuk_template:images',
|
2016-02-20 14:48:23 +00:00
|
|
|
'copy:govuk_template:css',
|
|
|
|
|
'copy:govuk_template:js',
|
|
|
|
|
'javascripts',
|
|
|
|
|
'sass',
|
|
|
|
|
'images'
|
|
|
|
|
]
|
2015-12-20 00:00:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Optional: recompile on changes
|
|
|
|
|
gulp.task('watch',
|
|
|
|
|
['default', 'watchForChanges']
|
|
|
|
|
);
|