mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-09 14:45:00 -05:00
…or how to move a bunch of things from a bunch of different places into `app/static`. There are three main reasons not to use Flask Assets: - It had some strange behaviour like only - It was based on Ruby SASS, which is slower to get new features than libsass, and meant depending on Ruby, and having the SASS Gem globally installed—so you’re already out of being a ‘pure’ Python app - Martyn and I have experience of doing it this way on Marketplace, and we’ve ironed out the initial rough patches The specific technologies this introduces, all of which are Node-based: - Gulp – like a Makefile written in Javascript - NPM – package management, used for managing Gulp and its related dependencies - Bower – also package management, and the only way I can think to have GOV.UK template as a proper dependency …speaking of which, GOV.UK template is now a dependency. This means it can’t be modified at all (eg to add a global `#content` wrapper), so every page now inherits from a template that has this wrapper. But it also means that we have a clean upgrade path when the template is modified. Everything else (toolkit, elements) I’ve kept as submodules but moved them to a more logical place (`app/assets` not `app/assets/stylesheets`, because they contain more than just SASS/CSS).
78 lines
2.1 KiB
JavaScript
78 lines
2.1 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', function() {
|
|
return gulp.src('bower_components/govuk_template/views/layouts/govuk_template.html')
|
|
.pipe(gulp.dest(paths.templates));
|
|
});
|
|
|
|
gulp.task('copy:govuk_template:assets', function() {
|
|
return gulp.src('bower_components/govuk_template/assets/**/*')
|
|
.pipe(gulp.dest(paths.dist));
|
|
});
|
|
|
|
|
|
// Concatenate and minify
|
|
|
|
gulp.task('javascripts', function() {
|
|
return gulp.src(paths.src + 'javascripts/main.js')
|
|
.pipe(plugins.include())
|
|
.pipe(gulp.dest(paths.dist + 'javascripts/'))
|
|
.pipe(plugins.uglify())
|
|
.on('error', function(e) { console.log("Uglify did not complete."); })
|
|
.pipe(gulp.dest(paths.dist + 'javascripts/'));
|
|
|
|
});
|
|
|
|
gulp.task('sass', function () {
|
|
return gulp.src(paths.src + '/stylesheets/main*.scss')
|
|
.pipe(plugins.sass({outputStyle: 'compressed'}))
|
|
.pipe(gulp.dest(paths.dist + '/stylesheets'));
|
|
});
|
|
|
|
|
|
// Copy images
|
|
|
|
gulp.task('images', function() {
|
|
return 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']
|
|
);
|