Files
notifications-admin/gulpfile.js

180 lines
5.2 KiB
JavaScript
Raw Normal View History

2024-08-08 14:32:33 -06:00
const { src, dest, series } = require('gulp');
const rollup = require('@rollup/stream');
const rollupPluginCommonjs = require('@rollup/plugin-commonjs');
const rollupPluginNodeResolve = require('@rollup/plugin-node-resolve');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
2024-08-08 14:01:05 -06:00
const gulpMerge = require('gulp-merge');
2024-09-18 13:59:16 -04:00
const uswds = require('@uswds/compile');
2024-09-26 15:01:34 -04:00
const { exec } = require('child_process');
const plugins = {};
plugins.addSrc = require('gulp-add-src');
plugins.babel = require('gulp-babel');
plugins.cleanCSS = require('gulp-clean-css');
plugins.concat = require('gulp-concat');
plugins.jshint = require('gulp-jshint');
plugins.prettyerror = require('gulp-prettyerror');
plugins.uglify = require('gulp-uglify');
const paths = {
src: 'app/assets/',
dist: 'app/static/',
npm: 'node_modules/',
toolkit: 'node_modules/govuk_frontend_toolkit/',
2024-09-18 13:59:16 -04:00
govuk_frontend: 'node_modules/govuk-frontend/',
};
const javascripts = () => {
2024-08-08 14:32:33 -06:00
const vendored = rollup({
input: paths.src + 'javascripts/modules/all.mjs',
plugins: [
rollupPluginNodeResolve({
2024-09-18 13:59:16 -04:00
mainFields: ['module', 'main'],
2024-08-08 14:32:33 -06:00
}),
rollupPluginCommonjs({
2024-09-18 13:59:16 -04:00
include: 'node_modules/**',
}),
2024-08-08 14:32:33 -06:00
],
output: {
format: 'iife',
2024-09-18 13:59:16 -04:00
name: 'GOVUK',
},
2024-08-08 14:32:33 -06:00
})
.pipe(source('all.mjs'))
.pipe(buffer())
2024-09-18 13:59:16 -04: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 + 'timeago/jquery.timeago.js',
paths.npm + 'textarea-caret/index.js',
paths.npm + 'cbor-js/cbor.js',
paths.npm + 'd3/dist/d3.min.js',
])
);
const local = src([
paths.toolkit + 'javascripts/govuk/modules.js',
paths.toolkit + 'javascripts/govuk/show-hide-content.js',
paths.src + 'javascripts/copyToClipboard.js',
paths.src + 'javascripts/autofocus.js',
paths.src + 'javascripts/enhancedTextbox.js',
paths.src + 'javascripts/fileUpload.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/templateFolderForm.js',
paths.src + 'javascripts/collapsibleCheckboxes.js',
paths.src + 'javascripts/radioSlider.js',
paths.src + 'javascripts/updateStatus.js',
paths.src + 'javascripts/errorBanner.js',
paths.src + 'javascripts/homepage.js',
paths.src + 'javascripts/timeoutPopup.js',
paths.src + 'javascripts/date.js',
2024-02-27 11:53:51 -05:00
paths.src + 'javascripts/loginAlert.js',
paths.src + 'javascripts/main.js',
paths.src + 'javascripts/totalMessagesChart.js',
paths.src + 'javascripts/activityChart.js',
paths.src + 'javascripts/sidenav.js',
2025-02-24 12:29:58 -05:00
paths.src + 'javascripts/validation.js',
])
2022-07-21 18:25:23 -07:00
.pipe(plugins.prettyerror())
2024-09-18 13:59:16 -04:00
.pipe(
plugins.babel({
presets: ['@babel/preset-env'],
})
);
2024-08-08 14:01:05 -06:00
return gulpMerge(vendored, local)
.pipe(plugins.uglify())
.pipe(plugins.concat('all.js'))
2024-08-08 14:32:33 -06:00
.pipe(dest(paths.dist + 'javascripts/'));
};
2024-08-09 09:41:13 -06:00
// Task to copy `gtm_head.js`
2024-08-09 09:18:50 -06:00
const copyGtmHead = () => {
2024-09-18 13:59:16 -04:00
return src(paths.src + 'js/gtm_head.js').pipe(dest(paths.dist + 'js/'));
};
2024-08-23 14:01:51 -07:00
// Task to copy `setTimezone.js`
const copySetTimezone = () => {
2024-09-18 13:59:16 -04:00
return src(paths.src + 'js/setTimezone.js').pipe(dest(paths.dist + 'js/'));
2024-08-23 14:01:51 -07:00
};
2024-08-09 09:41:13 -06:00
// Task to copy images
const copyImages = () => {
2024-09-18 13:59:16 -04:00
return src(paths.src + 'images/**/*', { encoding: false }).pipe(
dest(paths.dist + 'images/')
);
};
2024-10-25 11:00:51 -07:00
// Task to pdf files
2024-10-25 10:59:55 -07:00
const copyPDF = () => {
return src(paths.src + 'pdf/**/*', { encoding: false }).pipe(
dest(paths.dist + 'pdf/')
);
};
2024-08-09 09:41:13 -06:00
// Configure USWDS paths
2023-04-24 14:57:35 -04:00
uswds.settings.version = 3;
2024-08-09 07:40:58 -06:00
uswds.paths.dist.css = paths.dist + 'css';
uswds.paths.dist.js = paths.dist + 'js';
uswds.paths.dist.img = paths.dist + 'img';
2024-10-25 10:59:55 -07:00
uswds.paths.dist.pdf = paths.dist + 'pdf';
2024-08-09 07:40:58 -06:00
uswds.paths.dist.fonts = paths.dist + 'fonts';
uswds.paths.dist.theme = paths.src + 'sass/uswds';
2024-08-09 09:41:13 -06:00
// Task to compile USWDS styles
2024-08-09 07:40:58 -06:00
const styles = async () => {
await uswds.compile();
};
2023-04-24 14:57:35 -04:00
2024-08-09 09:41:13 -06:00
// Task to copy USWDS assets
2024-08-09 07:40:58 -06:00
const copyAssets = async () => {
await uswds.copyAssets();
};
2023-04-24 14:57:35 -04:00
2024-09-18 13:59:16 -04:00
// Optional backstopJS task
// Install gulp globally and run `gulp backstopTest`
const backstopTest = (done) => {
exec(
'npx backstop test --configPath=backstop.config.js',
(err, stdout, stderr) => {
console.log(stdout);
console.error(stderr);
done(err);
}
);
};
// Optional backstopJS reference task
// Install gulp globally and run `gulp backstopReference`
const backstopReference = (done) => {
exec(
'npx backstop reference --configPath=backstop.config.js',
(err, stdout, stderr) => {
console.log(stdout);
console.error(stderr);
done(err);
}
);
};
// Export tasks
exports.default = series(
styles,
javascripts,
copyGtmHead,
copySetTimezone,
copyImages,
2024-10-25 10:59:55 -07:00
copyPDF,
2024-09-18 13:59:16 -04:00
copyAssets
);
exports.backstopTest = backstopTest;
exports.backstopReference = backstopReference;