mod-build 4.0.102 → 4.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/package.json +1 -1
  3. package/src/scripts/globals.js +1 -3
  4. package/src/scripts/plugins.js +0 -3
  5. package/tasks/templates.js +2 -4
  6. package/gulp-tasks/add-path-subdirectories.js +0 -34
  7. package/gulp-tasks/build-stat.js +0 -9
  8. package/gulp-tasks/build.js +0 -28
  9. package/gulp-tasks/cache-bust.js +0 -19
  10. package/gulp-tasks/check-seasonal-variations.js +0 -21
  11. package/gulp-tasks/clean.js +0 -10
  12. package/gulp-tasks/combine-files.js +0 -7
  13. package/gulp-tasks/compile.js +0 -44
  14. package/gulp-tasks/copy-files-to-build-path.js +0 -8
  15. package/gulp-tasks/copy-fonts.js +0 -6
  16. package/gulp-tasks/copy-json.js +0 -6
  17. package/gulp-tasks/copy-resources-to-dist.js +0 -6
  18. package/gulp-tasks/copy-videos.js +0 -6
  19. package/gulp-tasks/extras.js +0 -22
  20. package/gulp-tasks/grab-cdn.js +0 -74
  21. package/gulp-tasks/grab-form-helpers.js +0 -55
  22. package/gulp-tasks/grab-global-images.js +0 -121
  23. package/gulp-tasks/grab-images.js +0 -79
  24. package/gulp-tasks/grab-shared-components.js +0 -46
  25. package/gulp-tasks/grab-shared-scripts.js +0 -275
  26. package/gulp-tasks/grab-theme-json.js +0 -24
  27. package/gulp-tasks/grab-tooltips-json.js +0 -33
  28. package/gulp-tasks/js-lint-husky.js +0 -35
  29. package/gulp-tasks/js-lint.js +0 -24
  30. package/gulp-tasks/minify.js +0 -131
  31. package/gulp-tasks/sass-lint.js +0 -15
  32. package/gulp-tasks/serve.js +0 -74
  33. package/gulp-tasks/settings.js +0 -22
  34. package/gulp-tasks/styles.js +0 -42
  35. package/gulp-tasks/tasks.js +0 -475
  36. package/gulp-tasks/templates.js +0 -288
  37. package/src/data/footer.js +0 -119
  38. package/src/resources/data/tcpa.json +0 -4
  39. package/src/resources/templates/modals/about/index.hbs +0 -9
  40. package/src/resources/templates/modals/about/index.html +0 -9
  41. package/src/resources/templates/modals/contact-us/index.hbs +0 -348
  42. package/src/resources/templates/modals/contact-us/index.html +0 -348
  43. package/src/resources/templates/modals/e-sign-consent/index.hbs +0 -35
  44. package/src/resources/templates/modals/e-sign-consent/index.html +0 -35
  45. package/src/resources/templates/modals/faq/index.hbs +0 -9
  46. package/src/resources/templates/modals/faq/index.html +0 -9
  47. package/src/resources/templates/modals/privacy/index.hbs +0 -238
  48. package/src/resources/templates/modals/privacy/index.html +0 -238
  49. package/src/resources/templates/modals/terms/index.hbs +0 -166
  50. package/src/resources/templates/modals/terms/index.html +0 -166
  51. package/src/scripts/default/additional-assets.js +0 -60
  52. package/src/scripts/default/rage-clicking.js +0 -54
  53. package/src/scripts/default/show-utility-providers.js +0 -28
  54. package/src/scripts/url-cleaner.js +0 -8
  55. package/src/scripts/vendor/google-tag-manager-head.js +0 -6
  56. package/src/scripts/vendor/heap-addeventproperties-identify.js +0 -262
  57. package/src/scripts/vendor/heap-tracking.js +0 -9
  58. package/src/styles/partials/_contact-us.scss +0 -196
  59. package/src/styles/partials/_google-address-autocomplete.scss +0 -52
  60. package/src/styles/partials/_mixins.scss +0 -39
  61. package/src/styles/partials/_modal-pages.scss +0 -125
  62. package/src/styles/partials/_modernize-colors.scss +0 -128
  63. package/src/styles/partials/_qs-footer.scss +0 -68
  64. package/src/styles/partials/_quote-footer-v1.scss +0 -79
  65. package/src/styles/partials/_quote-footer-v2.scss +0 -64
  66. package/src/styles/partials/_quote-footer-v3.scss +0 -65
  67. package/src/templates/_partials/scripts/deferred-styles.html +0 -16
  68. package/src/templates/_partials/scripts/heap-bundle.html +0 -5
  69. package/src/templates/_partials/scripts/heap.html +0 -4
  70. package/src/templates/_partials/scripts/utm-params.html +0 -9
  71. package/src/templates/components/qs-footer.html +0 -55
  72. package/src/templates/components/quote-footer-v1.html +0 -148
  73. package/src/templates/components/quote-footer-v2.html +0 -169
  74. /package/tasks/{addSeasonalchanges.js → add-seasonal-changes.js} +0 -0
  75. /package/tasks/{setupDevOpsTrackingId.js → setup-dev-ops-tracking-id.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Changelog
2
+ ## 4.0.104
3
+ - Migrating vite to master.
4
+
5
+ ## 4.0.103
6
+ - Removing unused files.
2
7
 
3
8
  ## 4.0.102
4
9
 
@@ -50,7 +55,7 @@
50
55
 
51
56
  ## 4.0.90
52
57
 
53
- - Expose the site config `domain` on the client as `window.siteDomain` via `globalFunctions()`
58
+ - Expose the site config `domain` on the client as `window.siteDomain` via `globalFunctions()`
54
59
 
55
60
  ## 4.0.89
56
61
 
@@ -62,7 +67,7 @@
62
67
 
63
68
  ## 4.0.87
64
69
 
65
- - Increased `gulpHandlebarsFileInclude` file-include recursion limit (`maxRecursion`) to 1000 for smart-campaign-pages
70
+ - Increased `gulpHandlebarsFileInclude` file-include recursion limit (`maxRecursion`) to 1000 for smart-campaign-pages
66
71
 
67
72
  ## 4.0.86
68
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.102",
3
+ "version": "4.0.104",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,6 +1,4 @@
1
1
  import { updateFooterLinkPaths } from './default/update-link-paths.js';
2
- import { preventRageClicks } from './default/rage-clicking.js';
3
- import { showUtilityProviders } from './default/show-utility-providers.js';
4
2
 
5
3
  function globalFunctions(config) {
6
4
  window.gtm_container_ID = config.gtm_container_ID;
@@ -18,4 +16,4 @@ function globalFunctions(config) {
18
16
  updateFooterLinkPaths(config);
19
17
  }
20
18
 
21
- export { globalFunctions, preventRageClicks, showUtilityProviders };
19
+ export { globalFunctions };
@@ -3,7 +3,6 @@ import path from "node:path";
3
3
  import merge from "lodash.merge";
4
4
  import gulpHandlebarsFileInclude from "gulp-handlebars-file-include";
5
5
  import { defaultSettings } from "../data/config.js";
6
- import footer from '../data/footer.js';
7
6
  import { handlebarsHelpers } from "./utils.js";
8
7
 
9
8
  /**
@@ -102,7 +101,6 @@ export const updateConfig = async (config) => {
102
101
 
103
102
  let mergedConfig = {
104
103
  ...config,
105
- ...footer(config),
106
104
  ...{ isLocal, nodeEnv, buildPath }
107
105
  };
108
106
 
@@ -151,7 +149,6 @@ export const updateHandlebarsOnWatch = async (config) => {
151
149
 
152
150
  let mergedConfig = {
153
151
  ...config,
154
- ...footer(config),
155
152
  ...{ isLocal, nodeEnv, buildPath }
156
153
  };
157
154
 
@@ -1,4 +1,3 @@
1
- import footer from '../src/data/footer.js';
2
1
  import fs from 'node:fs';
3
2
  import merge from 'lodash.merge';
4
3
  import cloneDeep from 'lodash.clonedeep';
@@ -6,8 +5,8 @@ import { createRetryFetch } from '../src/scripts/retry-fetch.js';
6
5
 
7
6
  import { defaultSettings } from '../src/data/config.js';
8
7
 
9
- import setupDevOpsTrackingId from './setupDevOpsTrackingId.js';
10
- import addSeasonalchanges from './addSeasonalchanges.js';
8
+ import setupDevOpsTrackingId from './setup-dev-ops-tracking-id.js';
9
+ import addSeasonalchanges from './add-seasonal-changes.js';
11
10
 
12
11
  const fetchWithRetryDefault = createRetryFetch();
13
12
  const fetchWithRetryTcpa = createRetryFetch();
@@ -272,7 +271,6 @@ export default async function(config) {
272
271
 
273
272
  let tempConfig = {
274
273
  ...config,
275
- ...footer(config),
276
274
  ...{ isLocal, nodeEnv, assetsPath, buildPath },
277
275
  };
278
276
 
@@ -1,34 +0,0 @@
1
- var replace = require('gulp-replace');
2
-
3
- module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
4
- return function() {
5
- const isPathSubdirectory = siteData.siteData && siteData.siteData.pathSubdirectory || siteData && siteData.pathSubdirectory;
6
- if (isPathSubdirectory) {
7
- const pathSubdirectory = isPathSubdirectory;
8
-
9
- return gulp.src(siteSettings.distFolder + '/**/*.html')
10
- .pipe(replace(/(href="favicon.ico")/g, function(match, path) {
11
- return `href="${pathSubdirectory}favicon.ico"`;
12
- }))
13
- .pipe(replace(/((src=")(images|scripts|shared-components)\/[^"]+")/g, function(match, path) {
14
- if (path.startsWith('src="images') || path.startsWith('src="scripts') || path.startsWith('src="shared-components') || path.startsWith('src="accessible-components')) {
15
- return `src="${pathSubdirectory}${path.slice(5)}`;
16
- }
17
- return match;
18
- }))
19
- .pipe(replace(/((srcset="images)\/[^"]+")/g, function(match, path) {
20
- if (path.startsWith('srcset="images')) {
21
- return `srcset="${pathSubdirectory}${path.slice(8)}`;
22
- }
23
- return match;
24
- }))
25
- .pipe(replace(/((href=")(images|styles|shared-components)\/[^"]+")/g, function(match, path) {
26
- if (path.startsWith('href="images') || path.startsWith('href="styles') || path.startsWith('href="shared-components') || path.startsWith('src="accessible-components')) {
27
- return `href="${pathSubdirectory}${path.slice(6)}`;
28
- }
29
- return match;
30
- }))
31
- .pipe(gulp.dest(siteSettings.distFolder));
32
- }
33
- }
34
- };
@@ -1,9 +0,0 @@
1
- module.exports = function(gulp, gulpPlugins, gulpSettings) {
2
- return function() {
3
- return gulp.src(gulpSettings.distFolder + '/**/*')
4
- .pipe(gulpPlugins.size({
5
- title: 'build',
6
- gzip: true
7
- }));
8
- };
9
- };
@@ -1,28 +0,0 @@
1
- module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
2
- var runSequence = require('run-sequence');
3
-
4
- return function() {
5
- var sequenceOpts;
6
-
7
- if (siteData.useTypescript) {
8
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'grab-form-helpers', 'templates', 'styles', 'compile-prod', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'copy-resources-to-dist', 'build-stat'];
9
- } else if (siteData.isWhiteLabel) {
10
- if (siteData.isQSPage) {
11
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'grab-theme-json', 'combine-files', 'grab-images', 'copy-json', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'copy-files-to-build-path', 'cache-bust', 'add-path-subdirectories', 'grab-tooltips-json', 'copy-resources-to-dist', 'build-stat'];
12
- } else {
13
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'combine-files', 'grab-images', 'js-lint', 'html-min','grab-global-images', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'grab-tooltips-json', 'copy-resources-to-dist', 'build-stat'];
14
- }
15
- } else {
16
- sequenceOpts = ['clean', 'grab-cdn', 'grab-shared-components', 'grab-shared-scripts', 'grab-form-helpers', 'templates', 'styles', 'copy-videos', 'js-lint', 'html-min', 'css-min', 'js-min', 'img-min', 'extras', 'cache-bust', 'add-path-subdirectories', 'copy-resources-to-dist', 'build-stat'];
17
- }
18
-
19
- if (siteData.copyLocalFontFile) {
20
- sequenceOpts.push('copy-fonts');
21
- }
22
-
23
- runSequence(...sequenceOpts, function() {
24
- console.log('\x1b[42m%s\x1b[0m', '✔ Build completed!');
25
- console.log('You can run \'gulp serve:dist\' to see production version.');
26
- });
27
- };
28
- };
@@ -1,19 +0,0 @@
1
- module.exports = function(gulp, gulpPlugins, siteSettings) {
2
- var path = require('path');
3
- return function() {
4
- return gulp.src(siteSettings.distFolder + '/**')
5
- .pipe(gulpPlugins.revAll.revision({
6
- dontSearchFile: [/(resources)\/.*/, /(scripts\/components)\/.*/, /(fonts)\/.*/],
7
- dontRenameFile: [/^\/favicon.ico$/g, '.html', '.txt', /modlogo([\w|\s|-])*\.(?:svg)/g, /(resources)\/.*/, /(fonts)\/.*/],
8
- dontUpdateReference: [/^\/favicon.ico$/g, '.html', '.txt', /modlogo([\w|\s|-])*\.(?:svg)/g, /(resources)\/.*/, /(fonts)\/.*/],
9
- transformFilename: function (file, hash) {
10
- var ext = path.extname(file.path);
11
- return path.basename(file.path, ext) + '-' + hash.substr(0, 8) + ext;
12
- }
13
- }))
14
- .pipe(gulpPlugins.revDeleteOriginal())
15
- .pipe(gulp.dest(siteSettings.distFolder))
16
- .pipe(gulpPlugins.revAll.versionFile())
17
- .pipe(gulp.dest(siteSettings.distFolder));
18
- };
19
- };
@@ -1,21 +0,0 @@
1
- function getActiveSeasons() {
2
- var seasons = require(`../src/data/seasons.js`);
3
- const today = new Date();
4
- const year = today.getFullYear();
5
- let activeSeason = [];
6
-
7
- for (const key in seasons) {
8
- var seasonName = key;
9
- var dateRanges = seasons[key];
10
- var startDate = new Date(`${Object.values(dateRanges)[0]}-${year}`);
11
- var endDate = new Date(`${Object.values(dateRanges)[1]}-${year}`);
12
-
13
- if (startDate < today && today < endDate) {
14
- activeSeason.push(seasonName)
15
- }
16
- }
17
-
18
- return activeSeason;
19
- }
20
-
21
- module.exports = getActiveSeasons;
@@ -1,10 +0,0 @@
1
- module.exports = function(gulp, gulpPlugins, gulpSettings) {
2
- var del = require('del');
3
-
4
- return function() {
5
- return del.sync([
6
- gulpSettings.tmpFolder,
7
- gulpSettings.distFolder
8
- ]);
9
- };
10
- };
@@ -1,7 +0,0 @@
1
- module.exports = function(gulp, gulpPlugins, siteSettings) {
2
- return function() {
3
- return gulp.src(siteSettings.srcFolder + '/**/*.{html,scss}')
4
- .pipe(gulpPlugins.concat('all.txt'))
5
- .pipe(gulp.dest(siteSettings.tmpFolder));
6
- };
7
- };
@@ -1,44 +0,0 @@
1
- const webpack = require('webpack-stream');
2
- const glob = require('glob');
3
-
4
- const entry = glob.sync('./src/scripts/**.ts').reduce((entry, path) => {
5
- const pathName = path.replace(/(\.\/src\/scripts\/|\.ts)/g, ''); // remove `./src/scripts/`, `.ts`
6
- entry[pathName] = path;
7
- return entry;
8
- }, {});
9
-
10
- module.exports = function(gulp, gulpPlugins, siteSettings, mode) {
11
- let assetUrl = siteSettings.tmpFolder + '/scripts';
12
- if (mode === 'production') {
13
- assetUrl = siteSettings.distFolder + '/scripts';
14
- }
15
-
16
- return function() {
17
- return gulp.src('src/scripts/**.ts')
18
- .on('error', function() {
19
- this.end();
20
- })
21
- .pipe(webpack({
22
- mode: mode,
23
- entry,
24
- output: {
25
- filename: '[name].js'
26
- },
27
- resolve: {
28
- // Add `.ts` and `.tsx` as a resolvable extension.
29
- extensions: ['.ts', '.tsx', '.js']
30
- },
31
- module: {
32
- rules: [
33
- // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
34
- { test: /\.ts?$/, loader: 'ts-loader' }
35
- ]
36
- }
37
- }))
38
- .on('error', function(err) {
39
- console.log('errors:',err);
40
- this.end();
41
- })
42
- .pipe(gulp.dest(assetUrl));
43
- };
44
- };
@@ -1,8 +0,0 @@
1
- module.exports = function(gulp, siteSettings) {
2
- return function() {
3
- if (siteSettings.buildPath) {
4
- return gulp.src(siteSettings.distFolder + '/**')
5
- .pipe(gulp.dest(siteSettings.distFolder + siteSettings.buildPath));
6
- }
7
- };
8
- };
@@ -1,6 +0,0 @@
1
- module.exports = function(gulp, siteSettings) {
2
- return function() {
3
- return gulp.src(siteSettings.srcFolder + '/fonts' + '/*.{otf,woff,woff2,ttf}')
4
- .pipe(gulp.dest(siteSettings.distFolder + '/fonts'));
5
- };
6
- };
@@ -1,6 +0,0 @@
1
- module.exports = function(gulp, siteSettings) {
2
- return function() {
3
- return gulp.src(siteSettings.srcFolder + '/' + siteSettings.dataSubfolder + '/*.json')
4
- .pipe(gulp.dest(siteSettings.distFolder + '/' + siteSettings.dataSubfolder));
5
- };
6
- };
@@ -1,6 +0,0 @@
1
- module.exports = function (gulp, siteSettings) {
2
- return function () {
3
- return gulp.src(siteSettings.srcFolder + '/resources/**/')
4
- .pipe(gulp.dest(siteSettings.distFolder + '/resources/'));
5
- };
6
- };
@@ -1,6 +0,0 @@
1
- module.exports = function(gulp, siteSettings) {
2
- return function() {
3
- return gulp.src(siteSettings.srcFolder + '/videos' + '/*.mp4')
4
- .pipe(gulp.dest(siteSettings.distFolder + '/videos'));
5
- };
6
- };
@@ -1,22 +0,0 @@
1
- module.exports = function(gulp, gulpPlugins, siteSettings) {
2
- var srcPaths = [];
3
-
4
- srcPaths.push(siteSettings.srcFolder + '/*.*');
5
- srcPaths.push('!' + siteSettings.srcFolder + '/**/*.html');
6
-
7
- for (var i = 0; i < siteSettings.browserSyncServeFolders.length; i ++) {
8
- srcPaths.push(siteSettings.browserSyncServeFolders[i] + '/**/*.otf');
9
- srcPaths.push(siteSettings.browserSyncServeFolders[i] + '/**/*.eot');
10
- srcPaths.push(siteSettings.browserSyncServeFolders[i] + '/**/*.svg');
11
- srcPaths.push(siteSettings.browserSyncServeFolders[i] + '/**/*.ttf');
12
- srcPaths.push(siteSettings.browserSyncServeFolders[i] + '/**/*.woff');
13
- srcPaths.push(siteSettings.browserSyncServeFolders[i] + '/**/*.woff2');
14
- }
15
-
16
- return function() {
17
- return gulp.src(srcPaths, {
18
- dot: true
19
- })
20
- .pipe(gulp.dest(siteSettings.distFolder));
21
- };
22
- };
@@ -1,74 +0,0 @@
1
- var request = require('request');
2
- var source = require('vinyl-source-stream');
3
-
4
- // helper to allow us to define an "end" event to multiple streams
5
- function streamToDestination(gulp, siteSettings, inputPath, destPath, fileName) {
6
- var url = `https://${siteSettings.nodeEnv}${inputPath}`;
7
-
8
- return new Promise(resolve => { // eslint-disable-line no-undef
9
- request(url)
10
- .on('response', resp => {
11
- if (resp.statusCode !== 200) {
12
- throw new Error(`Error fetching ${url}`);
13
- }
14
- })
15
- .pipe(source(fileName))
16
- .pipe(gulp.dest(`${siteSettings.srcFolder}/${destPath}`))
17
- .on('finish', resolve);
18
- });
19
- }
20
-
21
- module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
22
- return function() {
23
- const { nodeEnv, isLocal } = siteSettings;
24
- const { isQSPage, isWhiteLabel, domain } = siteData;
25
- const isModWhiteLabel = isWhiteLabel && !isQSPage
26
- const domainHasModernize = domain.indexOf('modernize') > -1;
27
-
28
- let externalResources;
29
- // listing of Static Resources sub-path and site destination paths
30
- // key: inputPath, value: destPath
31
-
32
- externalResources = {
33
- '/quote/resources/mod-site/templates/scripts/trusted-form.html': ['/templates/scripts/', 'trusted-form.html']
34
- };
35
-
36
- // grab footer modals and place under the resources
37
- Object.assign(externalResources, {
38
- '/quote/resources/shared-resources/templates/modals/about/': ['/resources/templates/modals/about/', 'index.html'],
39
- '/quote/resources/shared-resources/templates/modals/privacy/': ['/resources/templates/modals/privacy/', 'index.html'],
40
- '/quote/resources/shared-resources/templates/modals/terms/': ['/resources/templates/modals/terms/', 'index.html'],
41
- '/quote/resources/shared-resources/templates/modals/contact-us/': ['/resources/templates/modals/contact-us/', 'index.html'],
42
- '/quote/resources/shared-resources/templates/modals/faq/': ['/resources/templates/modals/faq/', 'index.html']
43
- })
44
-
45
- Object.assign(externalResources, {'/quote/resources/mod-site/templates/scripts/jornaya.html': ['/templates/scripts/', 'jornaya.html']});
46
-
47
- if (isModWhiteLabel || domainHasModernize) {
48
- Object.assign(externalResources, {'/quote/resources/mod-site/templates/scripts/recaptcha.html': ['/templates/scripts/', 'recaptcha.html']});
49
- }
50
-
51
- // local dev files
52
- const remoteFilesForLocalDev = {
53
- '/quote/resources/mod-site/scripts/vendor/maxmind-geoip2.js': ['/temp/scripts/', 'maxmind-geoip2.js']
54
- };
55
-
56
- if (!nodeEnv) {
57
- throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
58
- }
59
-
60
- // only save modform/utils if its local development
61
- if (isLocal) {
62
- externalResources = { ...externalResources, ...remoteFilesForLocalDev };
63
- }
64
-
65
- const filesPromiseMap = Object.keys(externalResources).map(key => {
66
- const destinationPath = externalResources[key][0];
67
- const fileName = externalResources[key][1];
68
- return streamToDestination(gulp, siteSettings, key, destinationPath, fileName);
69
- });
70
-
71
- // when Promise.all resolves, the streams are done and we can go to the next step
72
- return Promise.all(filesPromiseMap); // eslint-disable-line no-undef
73
- };
74
- };
@@ -1,55 +0,0 @@
1
- /* globals Promise */
2
- var request = require('request');
3
- var source = require('vinyl-source-stream');
4
-
5
- // helper to allow us to define an "end" event to multiple streams
6
- function streamToDestination(gulp, siteSettings, destPath, fileName) {
7
- if (!fileName) {
8
- return false;
9
- }
10
-
11
- var url = `https://${siteSettings.nodeEnv}/quote/resources/mod-form/form/${fileName}`;
12
- return new Promise(resolve => { // eslint-disable-line no-undef
13
- request(url)
14
- .on('response', (resp) => {
15
- if (resp.statusCode !== 200) {
16
- throw new Error(`Error fetching ${url}`);
17
- }
18
- })
19
- .pipe(source(fileName))
20
- .pipe(gulp.dest(`${siteSettings.srcFolder}/${destPath}`))
21
- .on('finish', resolve);
22
- });
23
- }
24
-
25
- async function getHelpers(siteSettings) {
26
- let helpers = [];
27
- await new Promise(resolve => {
28
- request(`https://${siteSettings.nodeEnv}/quote/resources/mod-form/form/chunks.txt`, function(err, response, body) {
29
- if (response.statusCode === 200) {
30
- helpers = body.split('\n');
31
- }
32
- resolve();
33
- });
34
- });
35
- return helpers;
36
- }
37
-
38
- module.exports = function(gulp, gulpPlugins, siteSettings, siteData) {
39
- return async function() {
40
- const { nodeEnv } = siteSettings;
41
- const helpers = await getHelpers(siteSettings);
42
-
43
- if (!nodeEnv) {
44
- throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
45
- }
46
- const destinationPath = '/resources/scripts/helpers/';
47
- const filesPromiseMap = helpers.map(helper => {
48
- const fileName = helper;
49
- return streamToDestination(gulp, siteSettings, destinationPath, fileName);
50
- });
51
-
52
- // when Promise.all resolves, the streams are done and we can go to the next step
53
- return Promise.all(filesPromiseMap); // eslint-disable-line no-undef
54
- };
55
- };
@@ -1,121 +0,0 @@
1
- var fs = require('fs');
2
- var request = require('request');
3
- var source = require('vinyl-source-stream');
4
- var replace = require('gulp-replace');
5
- var path = require('path')
6
-
7
- var imagePaths = [];
8
-
9
- function getFilePathFromURL(url) {
10
- let pathName = new URL(url).pathname;
11
- pathName = pathName.substring(0, pathName.lastIndexOf('/'));
12
- pathName = pathName.replace('/quote/resources/', '');
13
-
14
- return pathName;
15
- }
16
-
17
- function streamToDestination(gulp, siteSettings, url) {
18
- let finalDestination;
19
- let fileName = path.basename(url);
20
- const filePath = getFilePathFromURL(url);
21
-
22
- if (!fs.existsSync(siteSettings.distFolder)) {
23
- finalDestination = siteSettings.srcFolder;
24
- } else {
25
- finalDestination = siteSettings.distFolder;
26
- }
27
-
28
- // fix for svg sprites
29
- if (fileName.includes(".svg#")) {
30
- const hashIndex = fileName.indexOf("#");
31
- const strippedFileName = fileName.substring(0, hashIndex);
32
- fileName = strippedFileName;
33
- }
34
-
35
- return new Promise(resolve => { // eslint-disable-line no-undef
36
- request(url)
37
- .on('response', resp => {
38
- if (resp.statusCode !== 200 && resp.statusCode !== 206) {
39
- throw new Error(`${resp.statusCode} Error while fetching ${fileName}`);
40
- } else {
41
- imagePaths.push(url);
42
- }
43
- })
44
- .pipe(source(fileName))
45
- .pipe(gulp.dest(`${finalDestination}/resources/${filePath}`))
46
- .on('finish', resolve);
47
- });
48
- }
49
-
50
- function replaceImagePath(gulp, siteSettings) {
51
- var finalDestination;
52
-
53
- if (!fs.existsSync(siteSettings.distFolder)) {
54
- finalDestination = siteSettings.tmpFolder;
55
- } else {
56
- finalDestination = siteSettings.distFolder;
57
- }
58
-
59
- var stream = gulp.src(`${finalDestination}/index.html`);
60
-
61
- if (imagePaths.length) {
62
- imagePaths.forEach(function(imagePath) {
63
- const fileName = path.basename(imagePath);
64
- const filePath = getFilePathFromURL(imagePath);
65
- stream = stream.pipe(replace(new RegExp(`"${imagePath}"`, 'gm'), `"/resources/${filePath}/${fileName}"`))
66
- });
67
- }
68
- return stream.pipe(gulp.dest(finalDestination))
69
- }
70
-
71
- const getTags = (string) => {
72
- const regExs = [/<img.*?src="(.*?)"[^\>]+>/g, /<use.*?href="(.*?)".*?>/g, /<source.*?srcset="(.*?)".*?>/g, /url\('#{\$path}.*?'\)/g];
73
- let tags = [];
74
-
75
- regExs.forEach((regEx) => {
76
- const match = string.match(regEx);
77
-
78
- if (match) {
79
- tags = [...tags, ...match];
80
- }
81
- });
82
-
83
- return tags;
84
- };
85
-
86
- const getUrls = (tags) => {
87
- const urls = [];
88
-
89
- tags.forEach((tag) => {
90
- if (tag) {
91
- let url = tag;
92
- url = url.match(/(https?:\/\/[^\s]+)/gim);
93
- if (url) {
94
- url = url[0];
95
- url = url.replace(/"/g, "")
96
- urls.push(url)
97
- }
98
- }
99
- });
100
-
101
- return [...new Set(urls)]; // eslint-disable-line no-undef
102
- };
103
-
104
- const parseImageSources = (gulp, siteSettings) => {
105
- const text = fs.readFileSync(`${siteSettings.tmpFolder}/index.html`, 'utf8');
106
- const textMatches = getTags(text);
107
- return getUrls(textMatches);
108
- };
109
-
110
- module.exports = function(gulp, siteSettings, siteData) {
111
- return async function() {
112
- const urls = parseImageSources(gulp, siteSettings);
113
- const urlsPromises = urls.map(async (url) => {
114
- return await streamToDestination(gulp, siteSettings, url);
115
- });
116
-
117
- return await Promise.all(urlsPromises).then(function() { // eslint-disable-line no-undef
118
- replaceImagePath(gulp, siteSettings)
119
- })
120
- };
121
- };