2024-08-08 14:32:33 -06:00
|
|
|
const { src, dest, series } = require('gulp');
|
2025-10-06 09:38:54 -04:00
|
|
|
const mergeStream = require('merge-stream');
|
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');
|
2019-04-05 13:31:13 +01:00
|
|
|
const plugins = {};
|
|
|
|
|
plugins.addSrc = require('gulp-add-src');
|
|
|
|
|
plugins.babel = require('gulp-babel');
|
2019-11-26 14:18:57 +00:00
|
|
|
plugins.cleanCSS = require('gulp-clean-css');
|
2019-04-05 13:31:13 +01:00
|
|
|
plugins.concat = require('gulp-concat');
|
|
|
|
|
plugins.prettyerror = require('gulp-prettyerror');
|
|
|
|
|
plugins.uglify = require('gulp-uglify');
|
2015-12-20 00:00:01 +00:00
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
const paths = {
|
|
|
|
|
src: 'app/assets/',
|
|
|
|
|
dist: 'app/static/',
|
2025-10-06 09:38:54 -04:00
|
|
|
npm: 'node_modules/'
|
2019-04-01 09:58:13 +01:00
|
|
|
};
|
2019-10-11 10:26:25 +01:00
|
|
|
|
2019-04-01 09:58:13 +01:00
|
|
|
const javascripts = () => {
|
2025-10-06 09:38:54 -04:00
|
|
|
// Files that don't use NotifyModules and can be uglified
|
2025-10-09 14:21:12 -04:00
|
|
|
const localUglified = src([
|
2025-10-06 09:38:54 -04:00
|
|
|
paths.src + 'javascripts/modules/init.js',
|
|
|
|
|
paths.src + 'javascripts/modules/uswds-modules.js',
|
|
|
|
|
paths.src + 'javascripts/modules/show-hide-content.js',
|
2019-11-20 13:43:07 +00:00
|
|
|
paths.src + 'javascripts/radioSelect.js',
|
|
|
|
|
paths.src + 'javascripts/liveSearch.js',
|
|
|
|
|
paths.src + 'javascripts/preventDuplicateFormSubmissions.js',
|
2021-07-20 12:14:10 +01:00
|
|
|
paths.src + 'javascripts/errorBanner.js',
|
2025-05-07 11:08:03 -04:00
|
|
|
paths.src + 'javascripts/notifyModal.js',
|
2023-11-16 12:02:59 -05:00
|
|
|
paths.src + 'javascripts/date.js',
|
2025-01-09 12:00:50 -04:00
|
|
|
paths.src + 'javascripts/sidenav.js',
|
2025-02-24 12:29:58 -05:00
|
|
|
paths.src + 'javascripts/validation.js',
|
2025-08-06 13:24:28 -07:00
|
|
|
paths.src + 'javascripts/scrollPosition.js',
|
2019-11-20 13:43:07 +00:00
|
|
|
])
|
2025-10-09 14:21:12 -04:00
|
|
|
.pipe(plugins.prettyerror())
|
|
|
|
|
.pipe(
|
|
|
|
|
plugins.babel({
|
|
|
|
|
presets: ['@babel/preset-env'],
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.pipe(plugins.uglify());
|
2025-10-06 09:38:54 -04:00
|
|
|
|
|
|
|
|
// Files that use NotifyModules - split into two groups to avoid stream issues
|
|
|
|
|
const notifyModules1 = src([
|
|
|
|
|
paths.src + 'javascripts/copyToClipboard.js',
|
|
|
|
|
paths.src + 'javascripts/enhancedTextbox.js',
|
|
|
|
|
paths.src + 'javascripts/fileUpload.js',
|
|
|
|
|
paths.src + 'javascripts/errorTracking.js',
|
|
|
|
|
paths.src + 'javascripts/fullscreenTable.js',
|
|
|
|
|
paths.src + 'javascripts/templateFolderForm.js',
|
|
|
|
|
])
|
|
|
|
|
.pipe(plugins.prettyerror())
|
|
|
|
|
.pipe(
|
|
|
|
|
plugins.babel({
|
|
|
|
|
presets: ['@babel/preset-env'],
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const notifyModules2 = src([
|
|
|
|
|
paths.src + 'javascripts/collapsibleCheckboxes.js',
|
|
|
|
|
paths.src + 'javascripts/radioSlider.js',
|
|
|
|
|
paths.src + 'javascripts/updateStatus.js',
|
2025-10-09 14:21:12 -04:00
|
|
|
paths.src + 'javascripts/timeoutPopup.js',
|
2025-10-06 09:38:54 -04:00
|
|
|
paths.src + 'javascripts/main.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'],
|
|
|
|
|
})
|
|
|
|
|
);
|
2019-11-20 13:43:07 +00:00
|
|
|
|
2025-10-06 09:38:54 -04:00
|
|
|
// First create vendored with jquery-expose immediately after jQuery
|
|
|
|
|
const vendoredWithExpose = src([
|
|
|
|
|
paths.npm + 'jquery/dist/jquery.min.js',
|
|
|
|
|
paths.src + 'javascripts/jquery-expose.js',
|
|
|
|
|
paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js',
|
|
|
|
|
paths.npm + 'textarea-caret/index.js',
|
|
|
|
|
paths.npm + 'cbor-js/cbor.js',
|
2025-10-07 10:44:45 -07:00
|
|
|
paths.npm + 'd3/dist/d3.min.js'
|
2025-10-06 09:38:54 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Concatenate all streams
|
|
|
|
|
const mainBundle = mergeStream(vendoredWithExpose, localUglified, notifyModules1, notifyModules2);
|
|
|
|
|
|
|
|
|
|
// Use the mainBundle as the base and append remaining non-transpiled files at the end
|
|
|
|
|
return mainBundle
|
|
|
|
|
.pipe(plugins.addSrc.append(paths.src + 'javascripts/listEntry.js'))
|
|
|
|
|
.pipe(plugins.addSrc.append(paths.src + 'javascripts/stick-to-window-when-scrolling.js'))
|
|
|
|
|
.pipe(plugins.addSrc.append(paths.src + 'javascripts/totalMessagesChart.js'))
|
|
|
|
|
.pipe(plugins.addSrc.append(paths.src + 'javascripts/activityChart.js'))
|
|
|
|
|
.pipe(plugins.addSrc.append(paths.src + 'javascripts/job-polling.js'))
|
2019-04-01 09:58:13 +01:00
|
|
|
.pipe(plugins.concat('all.js'))
|
2024-08-08 14:32:33 -06:00
|
|
|
.pipe(dest(paths.dist + 'javascripts/'));
|
2019-04-01 09:58:13 +01:00
|
|
|
};
|
2016-09-12 16:11:34 +01:00
|
|
|
|
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/'));
|
2019-04-01 09:58:13 +01:00
|
|
|
};
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2025-09-26 16:21:50 -04: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/')
|
|
|
|
|
);
|
2019-04-01 09:58:13 +01:00
|
|
|
};
|
2016-02-08 11:05:07 +00:00
|
|
|
|
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/')
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-07 11:08:03 -04:00
|
|
|
const copyUSWDSJS = () => {
|
|
|
|
|
return src('node_modules/@uswds/uswds/dist/js/uswds.min.js')
|
|
|
|
|
.pipe(dest(paths.dist + 'js/'));
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-09 09:41:13 -06:00
|
|
|
// Configure USWDS paths
|
2023-04-24 14:57:35 -04:00
|
|
|
uswds.settings.version = 3;
|
2025-06-10 20:24:08 -04:00
|
|
|
uswds.settings.compile = {
|
|
|
|
|
sass: true,
|
|
|
|
|
javascript: true,
|
|
|
|
|
sprites: false
|
|
|
|
|
};
|
|
|
|
|
|
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 () => {
|
2025-06-10 20:42:55 -04:00
|
|
|
await uswds.compileSass();
|
2024-08-09 07:40:58 -06:00
|
|
|
};
|
2023-04-24 14:57:35 -04:00
|
|
|
|
2025-10-07 12:29:08 -04:00
|
|
|
// Task to copy USWDS assets
|
2025-06-10 20:17:57 -04:00
|
|
|
const copyUSWDSAssets = () => {
|
|
|
|
|
return src([
|
|
|
|
|
'node_modules/@uswds/uswds/dist/img/**/*',
|
|
|
|
|
'node_modules/@uswds/uswds/dist/fonts/**/*'
|
|
|
|
|
], { encoding: false })
|
2025-06-10 20:24:08 -04:00
|
|
|
.pipe(dest((file) => {
|
|
|
|
|
if (file.path.includes('/img/')) {
|
|
|
|
|
return paths.dist + 'img/';
|
|
|
|
|
} else if (file.path.includes('/fonts/')) {
|
|
|
|
|
return paths.dist + 'fonts/';
|
|
|
|
|
}
|
|
|
|
|
return paths.dist;
|
|
|
|
|
}));
|
2024-08-09 07:40:58 -06:00
|
|
|
};
|
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,
|
2025-06-10 20:17:57 -04:00
|
|
|
copyUSWDSAssets,
|
2025-05-07 11:08:03 -04:00
|
|
|
copyUSWDSJS
|
2024-09-18 13:59:16 -04:00
|
|
|
);
|
|
|
|
|
exports.backstopTest = backstopTest;
|
|
|
|
|
exports.backstopReference = backstopReference;
|