@videinfra/static-website-builder 2.0.2 → 2.0.4

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 (122) hide show
  1. package/.prettierrc +11 -11
  2. package/CHANGELOG.md +214 -210
  3. package/README.md +102 -102
  4. package/bin/builder.js +40 -40
  5. package/eslint.config.js +39 -39
  6. package/gulpfile.js +63 -63
  7. package/init/default/config/config.js +44 -44
  8. package/init/default/src/html/data/global.js +9 -9
  9. package/init/default/src/javascripts/_entries.js +14 -14
  10. package/init/index.js +63 -63
  11. package/init/test/.env +6 -6
  12. package/init/test/.env.local +3 -2
  13. package/init/test/config/config.js +71 -67
  14. package/init/test/src/html/404.twig +12 -12
  15. package/init/test/src/html/data/global.js +10 -10
  16. package/init/test/src/html/env.twig +21 -21
  17. package/init/test/src/html/layouts/base.twig +1 -1
  18. package/init/test/src/html/other.twig +9 -9
  19. package/init/test/src/html/preposition.twig +4 -4
  20. package/init/test/src/javascripts/_entries-alt.js +10 -10
  21. package/init/test/src/javascripts/_entries.js +19 -19
  22. package/init/test/src/javascripts/common.js +13 -13
  23. package/init/test/src/javascripts/main.js +8 -8
  24. package/init/test/src/javascripts/something.ts +9 -9
  25. package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
  26. package/init/test/src/stylesheets/env-test.scss +28 -28
  27. package/init/test/src/stylesheets/ignore-test.scss +4 -4
  28. package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
  29. package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
  30. package/lib/camelize-file-name.js +21 -21
  31. package/lib/generate-gulp-tasks.js +85 -85
  32. package/lib/get-config.js +203 -204
  33. package/lib/get-file-names.js +23 -23
  34. package/lib/get-path.js +102 -102
  35. package/lib/globs-helper.js +243 -243
  36. package/lib/gulp/dynamic-task.js +8 -8
  37. package/lib/gulp/resolve-dynamic-task.js +11 -11
  38. package/lib/gulp/task-before-dest.js +8 -8
  39. package/lib/gulp/task-end.js +10 -10
  40. package/lib/gulp/task-start.js +12 -12
  41. package/lib/gulp/task-watch.js +66 -66
  42. package/lib/init/copy-folder.js +50 -50
  43. package/lib/init/folder-exists.js +10 -10
  44. package/lib/init/get-folder-list.js +16 -16
  45. package/lib/init/merge-package.js +17 -17
  46. package/lib/init/read-package.js +17 -17
  47. package/lib/log-error.js +15 -15
  48. package/lib/merge.js +27 -27
  49. package/lib/run-preprocess.js +32 -32
  50. package/lib/task-order.js +19 -19
  51. package/package.json +68 -68
  52. package/plugins/example/preprocess-config.js +17 -17
  53. package/plugins/example/task.js +55 -55
  54. package/plugins/example.js +38 -38
  55. package/plugins/sass-engine/preprocess-config.js +59 -59
  56. package/plugins/sass.js +41 -41
  57. package/plugins/twig/lodash-filters/filters.js +91 -91
  58. package/plugins/twig/lodash-filters.js +14 -14
  59. package/plugins/twig/symfony-filters/filters.js +102 -102
  60. package/plugins/twig/symfony-filters/preposition_nbsp.js +77 -77
  61. package/plugins/twig/symfony-filters.js +14 -14
  62. package/plugins/twig/symfony-functions/functions.js +31 -31
  63. package/plugins/twig/symfony-functions.js +14 -14
  64. package/plugins/twig-engine/preprocess-config.js +53 -53
  65. package/plugins/twig.js +74 -74
  66. package/tasks/browser-sync/config.js +39 -39
  67. package/tasks/browser-sync/preprocess-config.js +32 -32
  68. package/tasks/browser-sync/task.js +9 -9
  69. package/tasks/clean/config.js +20 -20
  70. package/tasks/clean/preprocess-config.js +19 -19
  71. package/tasks/clean/task.js +7 -7
  72. package/tasks/data/config.js +34 -34
  73. package/tasks/data/data-loader-js.js +14 -14
  74. package/tasks/data/data-loader-json.js +5 -5
  75. package/tasks/data/get-data.js +96 -96
  76. package/tasks/env/config.js +26 -23
  77. package/tasks/env/get-env.js +113 -81
  78. package/tasks/fonts/config.js +24 -24
  79. package/tasks/fonts/task.js +47 -47
  80. package/tasks/global/config.js +7 -7
  81. package/tasks/html/config.js +42 -42
  82. package/tasks/html/task.js +91 -91
  83. package/tasks/icons/config.js +47 -47
  84. package/tasks/icons/preprocess-config.js +60 -60
  85. package/tasks/icons/task.js +56 -56
  86. package/tasks/images/config.js +27 -27
  87. package/tasks/images/task.js +46 -46
  88. package/tasks/javascripts/config.js +69 -69
  89. package/tasks/javascripts/preprocess-config.js +109 -109
  90. package/tasks/javascripts/task.js +86 -86
  91. package/tasks/sitemap/config.js +48 -48
  92. package/tasks/sitemap/preprocess-config.js +18 -18
  93. package/tasks/sitemap/task.js +69 -69
  94. package/tasks/sizereport/config.js +23 -23
  95. package/tasks/sizereport/task.js +16 -16
  96. package/tasks/static/config.js +27 -27
  97. package/tasks/static/task.js +46 -46
  98. package/tasks/stylesheets/config.js +85 -85
  99. package/tasks/stylesheets/preprocess-config.js +41 -41
  100. package/tasks/stylesheets/task.js +73 -73
  101. package/tests/build/build.test.js +153 -153
  102. package/tests/camelize-file-name.test.js +11 -11
  103. package/tests/generate-gulp-tasks.test.js +78 -78
  104. package/tests/glob-helper.test.js +99 -99
  105. package/tests/merge.test.js +10 -10
  106. package/tests/preposition_nbsp.test.js +50 -50
  107. package/tests/run-preprocess.test.js +90 -90
  108. package/tests/sass-stringify.test.js +24 -24
  109. package/tests/sitemap.test.js +12 -12
  110. package/vendor/gulp-rolldown/index.js +151 -151
  111. package/vendor/gulp-rolldown/plugin-raw.js +17 -17
  112. package/vendor/gulp-rolldown/plugin-virtual-entry.js +30 -30
  113. package/vendor/gulp-sass/CHANGELOG.md +168 -168
  114. package/vendor/gulp-sass/LICENSE +20 -20
  115. package/vendor/gulp-sass/README.md +187 -187
  116. package/vendor/gulp-sass/index.js +208 -208
  117. package/vendor/gulp-sass/package.json +61 -61
  118. package/vendor/gulp-sass/sass-stringify.js +32 -32
  119. package/vendor/gulp-twig/LICENSE +20 -20
  120. package/vendor/gulp-twig/README.md +167 -167
  121. package/vendor/gulp-twig/index.js +138 -138
  122. package/vendor/gulp-twig/package.json +44 -44
@@ -1,56 +1,56 @@
1
- import gulp from 'gulp';
2
- import gulpif from 'gulp-if';
3
- import svgstore from 'gulp-svgstore';
4
- import svgmin from 'gulp-svgmin';
5
- import nanomemoize from 'nano-memoize';
6
-
7
- import globs from './../../lib/globs-helper.js';
8
- import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
9
- import { getTaskConfig } from './../../lib/get-config.js';
10
-
11
- import taskStart from '../../lib/gulp/task-start.js';
12
- import taskEnd from '../../lib/gulp/task-end.js';
13
- import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
14
- import taskWatch from '../../lib/gulp/task-watch.js';
15
-
16
- const getWatchGlobPaths = function (forChokidar = false) {
17
- const sourcePaths = getSourcePaths('icons');
18
- const extensions = getTaskConfig('icons', 'extensions');
19
- const ignore = getTaskConfig('icons', 'ignore');
20
-
21
- return globs.generate(
22
- globs.paths(sourcePaths).filesWithExtensions(extensions), // Files to watch
23
- globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
24
- forChokidar,
25
- );
26
- };
27
- const getGlobPaths = nanomemoize.nanomemoize(function () {
28
- return getWatchGlobPaths(false);
29
- });
30
-
31
- function icons() {
32
- return (
33
- gulp
34
- .src(getGlobPaths())
35
- .pipe(taskStart())
36
-
37
- // Minify SVG
38
- .pipe(gulpif(!!getTaskConfig('icons', 'svgmin'), svgmin(getTaskConfig('icons', 'svgmin'))))
39
-
40
- // Create sprite
41
- .pipe(svgstore(getTaskConfig('icons', 'svgstore')))
42
-
43
- .pipe(taskBeforeDest())
44
- .pipe(gulp.dest(getDestPath('icons')))
45
-
46
- // Reload on change
47
- .pipe(taskEnd())
48
- );
49
- }
50
-
51
- function iconsWatch() {
52
- return taskWatch(getWatchGlobPaths(true), icons);
53
- }
54
-
55
- export const build = icons;
56
- export const watch = iconsWatch;
1
+ import gulp from 'gulp';
2
+ import gulpif from 'gulp-if';
3
+ import svgstore from 'gulp-svgstore';
4
+ import svgmin from 'gulp-svgmin';
5
+ import nanomemoize from 'nano-memoize';
6
+
7
+ import globs from './../../lib/globs-helper.js';
8
+ import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
9
+ import { getTaskConfig } from './../../lib/get-config.js';
10
+
11
+ import taskStart from '../../lib/gulp/task-start.js';
12
+ import taskEnd from '../../lib/gulp/task-end.js';
13
+ import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
14
+ import taskWatch from '../../lib/gulp/task-watch.js';
15
+
16
+ const getWatchGlobPaths = function (forChokidar = false) {
17
+ const sourcePaths = getSourcePaths('icons');
18
+ const extensions = getTaskConfig('icons', 'extensions');
19
+ const ignore = getTaskConfig('icons', 'ignore');
20
+
21
+ return globs.generate(
22
+ globs.paths(sourcePaths).filesWithExtensions(extensions), // Files to watch
23
+ globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
24
+ forChokidar,
25
+ );
26
+ };
27
+ const getGlobPaths = nanomemoize.nanomemoize(function () {
28
+ return getWatchGlobPaths(false);
29
+ });
30
+
31
+ function icons() {
32
+ return (
33
+ gulp
34
+ .src(getGlobPaths())
35
+ .pipe(taskStart())
36
+
37
+ // Minify SVG
38
+ .pipe(gulpif(!!getTaskConfig('icons', 'svgmin'), svgmin(getTaskConfig('icons', 'svgmin'))))
39
+
40
+ // Create sprite
41
+ .pipe(svgstore(getTaskConfig('icons', 'svgstore')))
42
+
43
+ .pipe(taskBeforeDest())
44
+ .pipe(gulp.dest(getDestPath('icons')))
45
+
46
+ // Reload on change
47
+ .pipe(taskEnd())
48
+ );
49
+ }
50
+
51
+ function iconsWatch() {
52
+ return taskWatch(getWatchGlobPaths(true), icons);
53
+ }
54
+
55
+ export const build = icons;
56
+ export const watch = iconsWatch;
@@ -1,27 +1,27 @@
1
- import * as imageTask from './task.js';
2
-
3
- export const images = {
4
- // Glob list of files, which to ignore, relative to the image source folder
5
- // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
6
- ignore: [],
7
-
8
- // Production only settings, overwrites default settings
9
- production: {},
10
-
11
- // Development only settings, overwrites default settings
12
- development: {},
13
- };
14
-
15
- export const tasks = {
16
- images: [imageTask],
17
- };
18
-
19
- /**
20
- * Paths relative to the global src and dest folders
21
- */
22
- export const paths = {
23
- images: {
24
- src: 'images',
25
- dest: 'assets/images',
26
- },
27
- };
1
+ import * as imageTask from './task.js';
2
+
3
+ export const images = {
4
+ // Glob list of files, which to ignore, relative to the image source folder
5
+ // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
6
+ ignore: [],
7
+
8
+ // Production only settings, overwrites default settings
9
+ production: {},
10
+
11
+ // Development only settings, overwrites default settings
12
+ development: {},
13
+ };
14
+
15
+ export const tasks = {
16
+ images: [imageTask],
17
+ };
18
+
19
+ /**
20
+ * Paths relative to the global src and dest folders
21
+ */
22
+ export const paths = {
23
+ images: {
24
+ src: 'images',
25
+ dest: 'assets/images',
26
+ },
27
+ };
@@ -1,46 +1,46 @@
1
- import gulp from 'gulp';
2
- import nanomemoize from 'nano-memoize';
3
-
4
- import globs from './../../lib/globs-helper.js';
5
- import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
6
- import { getTaskConfig } from './../../lib/get-config.js';
7
-
8
- import taskStart from '../../lib/gulp/task-start.js';
9
- import taskEnd from '../../lib/gulp/task-end.js';
10
- import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
11
- import taskWatch from '../../lib/gulp/task-watch.js';
12
-
13
- const getWatchGlobPaths = function (forChokidar = false) {
14
- const sourcePaths = getSourcePaths('images');
15
- const ignore = getTaskConfig('images', 'ignore');
16
-
17
- return globs.generate(
18
- globs.paths(sourcePaths).allFiles(), // Files to watch
19
- globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
20
- forChokidar,
21
- );
22
- };
23
- const getGlobPaths = nanomemoize.nanomemoize(function () {
24
- return getWatchGlobPaths(false);
25
- });
26
-
27
- function images() {
28
- return (
29
- gulp
30
- .src(getGlobPaths(), { since: gulp.lastRun(images) })
31
- .pipe(taskStart())
32
-
33
- .pipe(taskBeforeDest())
34
- .pipe(gulp.dest(getDestPath('images')))
35
-
36
- // Reload on change
37
- .pipe(taskEnd())
38
- );
39
- }
40
-
41
- function imagesWatch() {
42
- return taskWatch(getWatchGlobPaths(true), images);
43
- }
44
-
45
- export const build = images;
46
- export const watch = imagesWatch;
1
+ import gulp from 'gulp';
2
+ import nanomemoize from 'nano-memoize';
3
+
4
+ import globs from './../../lib/globs-helper.js';
5
+ import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
6
+ import { getTaskConfig } from './../../lib/get-config.js';
7
+
8
+ import taskStart from '../../lib/gulp/task-start.js';
9
+ import taskEnd from '../../lib/gulp/task-end.js';
10
+ import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
11
+ import taskWatch from '../../lib/gulp/task-watch.js';
12
+
13
+ const getWatchGlobPaths = function (forChokidar = false) {
14
+ const sourcePaths = getSourcePaths('images');
15
+ const ignore = getTaskConfig('images', 'ignore');
16
+
17
+ return globs.generate(
18
+ globs.paths(sourcePaths).allFiles(), // Files to watch
19
+ globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
20
+ forChokidar,
21
+ );
22
+ };
23
+ const getGlobPaths = nanomemoize.nanomemoize(function () {
24
+ return getWatchGlobPaths(false);
25
+ });
26
+
27
+ function images() {
28
+ return (
29
+ gulp
30
+ .src(getGlobPaths(), { since: gulp.lastRun(images) })
31
+ .pipe(taskStart())
32
+
33
+ .pipe(taskBeforeDest())
34
+ .pipe(gulp.dest(getDestPath('images')))
35
+
36
+ // Reload on change
37
+ .pipe(taskEnd())
38
+ );
39
+ }
40
+
41
+ function imagesWatch() {
42
+ return taskWatch(getWatchGlobPaths(true), images);
43
+ }
44
+
45
+ export const build = images;
46
+ export const watch = imagesWatch;
@@ -1,69 +1,69 @@
1
- import * as preprocessJavascriptsConfig from './preprocess-config.js';
2
- import * as javascriptsTask from './task.js';
3
-
4
- export const javascripts = {
5
- // JS file extensions
6
- extensions: ['js', 'ts', 'tsx', 'jsx', 'json'],
7
-
8
- // Instead of 'entry' we provide filename which list all entries
9
- // Can be either an object or array of object to have multiple rolldown
10
- // builds, one for each of the entry list files
11
- entryList: {
12
- // Path to the entry list file
13
- name: '_entries.js',
14
-
15
- // Entry shared chunk name, creates a share chunk if needed
16
- shared: 'shared',
17
- },
18
-
19
- rolldown: {
20
- // Sets the target environment for the generated JavaScript
21
- // transform: '...',
22
-
23
- // Input files, set from entries in preprocess-config.js
24
- // input: {},
25
-
26
- output: {
27
- // format: 'esm',
28
- dir: './[folder]',
29
- },
30
- },
31
-
32
- // Production only settings, overwrites default settings
33
- production: {
34
- rolldown: {
35
- output: {
36
- sourcemap: 'hidden',
37
- minify: true,
38
- },
39
- },
40
- },
41
-
42
- // Development only settings, overwrites default settings
43
- development: {
44
- rolldown: {
45
- output: {
46
- sourcemap: true,
47
- minify: 'dce-only',
48
- },
49
- },
50
- },
51
- };
52
-
53
- export const preprocess = {
54
- javascripts: [preprocessJavascriptsConfig],
55
- };
56
-
57
- export const tasks = {
58
- javascripts: [javascriptsTask],
59
- };
60
-
61
- /**
62
- * Paths relative to the global src and dest folders
63
- */
64
- export const paths = {
65
- javascripts: {
66
- src: 'javascripts',
67
- dest: 'assets/javascripts',
68
- },
69
- };
1
+ import * as preprocessJavascriptsConfig from './preprocess-config.js';
2
+ import * as javascriptsTask from './task.js';
3
+
4
+ export const javascripts = {
5
+ // JS file extensions
6
+ extensions: ['js', 'ts', 'tsx', 'jsx', 'json'],
7
+
8
+ // Instead of 'entry' we provide filename which list all entries
9
+ // Can be either an object or array of object to have multiple rolldown
10
+ // builds, one for each of the entry list files
11
+ entryList: {
12
+ // Path to the entry list file
13
+ name: '_entries.js',
14
+
15
+ // Entry shared chunk name, creates a share chunk if needed
16
+ shared: 'shared',
17
+ },
18
+
19
+ rolldown: {
20
+ // Sets the target environment for the generated JavaScript
21
+ // transform: '...',
22
+
23
+ // Input files, set from entries in preprocess-config.js
24
+ // input: {},
25
+
26
+ output: {
27
+ // format: 'esm',
28
+ dir: './[folder]',
29
+ },
30
+ },
31
+
32
+ // Production only settings, overwrites default settings
33
+ production: {
34
+ rolldown: {
35
+ output: {
36
+ sourcemap: 'hidden',
37
+ minify: true,
38
+ },
39
+ },
40
+ },
41
+
42
+ // Development only settings, overwrites default settings
43
+ development: {
44
+ rolldown: {
45
+ output: {
46
+ sourcemap: true,
47
+ minify: 'dce-only',
48
+ },
49
+ },
50
+ },
51
+ };
52
+
53
+ export const preprocess = {
54
+ javascripts: [preprocessJavascriptsConfig],
55
+ };
56
+
57
+ export const tasks = {
58
+ javascripts: [javascriptsTask],
59
+ };
60
+
61
+ /**
62
+ * Paths relative to the global src and dest folders
63
+ */
64
+ export const paths = {
65
+ javascripts: {
66
+ src: 'javascripts',
67
+ dest: 'assets/javascripts',
68
+ },
69
+ };
@@ -1,109 +1,109 @@
1
- import { getDestPath, getBuilderPath, getProjectPath, getSourcePath } from '../../lib/get-path.js';
2
- import merge from '../../lib/merge.js';
3
- import getEnvData, { loadEnvData } from '../env/get-env.js';
4
- import get from 'lodash/get.js';
5
- import cloneDeep from 'lodash/cloneDeep.js';
6
- import replace from '@rollup/plugin-replace';
7
-
8
- /**
9
- * Modify configuration
10
- *
11
- * @param {object} config Javascript configuration
12
- * @param {object} fullConfig Full configuration
13
- * @returns {object} Transformed javascript configuration
14
- */
15
- export default function preprocessJavascriptsConfig(config, fullConfig) {
16
- let entryList = config.entryList;
17
-
18
- // User may specify a function, execute it to get object / array
19
- if (typeof entryList === 'function') {
20
- entryList = entryList(config);
21
- }
22
-
23
- // User may specify multiple entry list files, convert to array
24
- if (!Array.isArray(entryList)) {
25
- entryList = [entryList];
26
- }
27
-
28
- // User may specify only a name of the entry file
29
- // Set shared chunk name for each of the entry files
30
- // Each entryList item is { name: '...', shared?: '...', outpuSubFolder?: '...' }
31
- entryList = entryList.map((entry, index) => {
32
- return {
33
- name: typeof entry === 'string' ? entry : entry.name,
34
- shared: typeof entry !== 'string' && entry && entry.shared ? entry.shared : index === 0 ? 'shared' : '',
35
- outpuSubFolder: typeof entry !== 'string' && entry && entry.outpuSubFolder ? entry.outpuSubFolder : '',
36
- };
37
- });
38
-
39
- return entryList.map((entry) => {
40
- const entryConfig = cloneDeep(config);
41
- entryConfig.rolldown = Object.assign({}, entryConfig.rolldown);
42
-
43
- // Output paths
44
- const output = merge({}, get(entryConfig, ['rolldown', 'output'], null));
45
-
46
- output.dir = output.dir.replace('[folder]/', entry.outpuSubFolder ? entry.outpuSubFolder + '/' : '').replace('[folder]', entry.outpuSubFolder ? entry.outpuSubFolder : '');
47
-
48
- output.dir = getDestPath('javascripts', output.dir);
49
-
50
- // Use process.env... variables from .env files
51
- const envVariables = merge(getEnvData().js, {
52
- 'process.env.NODE_ENV': JSON.stringify(global.production ? 'production' : 'development'),
53
- });
54
-
55
- // Rewrite shared.js and rolldown-runtime.js to include cache busting asset version so that we could
56
- // preload those assets using <link rel="preload" as="script" href="{{ asset(...) }}" />
57
- const envData = loadEnvData();
58
- const assetVersion = envData['ASSETS_VERSION'];
59
- const replacements = {};
60
-
61
- if (assetVersion) {
62
- replacements['/rolldown-runtime.js'] = `/rolldown-runtime.js?v=${assetVersion}`;
63
-
64
- if (entry.shared) {
65
- replacements[`/${entry.shared}.js`] = `/${entry.shared}.js?v=${assetVersion}`;
66
- }
67
- }
68
-
69
- const buildConfig = merge(entryConfig, {
70
- rolldown: {
71
- // Entries, this file is resolved by gulp-rolldown and converted into
72
- // `inputs` option
73
- entries: entry,
74
-
75
- plugins: [
76
- replace({
77
- preventAssignment: true,
78
- ...envVariables,
79
- ...replacements,
80
- }),
81
- ],
82
-
83
- // Output folder
84
- output: output,
85
-
86
- // Imports
87
- resolve: merge(
88
- {
89
- // File extensions
90
- extensions: entryConfig.extensions.map((extension) => `.${extension}`),
91
-
92
- // Import folders
93
- modules: [
94
- // Allow imports from node_modules
95
- getBuilderPath('node_modules'),
96
- getProjectPath('node_modules'),
97
-
98
- // Allow imports from source folder
99
- getSourcePath('javascripts'),
100
- ],
101
- },
102
- get(entryConfig, ['rolldown', 'resolve'], {}),
103
- ),
104
- },
105
- });
106
-
107
- return buildConfig;
108
- });
109
- }
1
+ import { getDestPath, getBuilderPath, getProjectPath, getSourcePath } from '../../lib/get-path.js';
2
+ import merge from '../../lib/merge.js';
3
+ import getEnvData, { loadEnvData } from '../env/get-env.js';
4
+ import get from 'lodash/get.js';
5
+ import cloneDeep from 'lodash/cloneDeep.js';
6
+ import replace from '@rollup/plugin-replace';
7
+
8
+ /**
9
+ * Modify configuration
10
+ *
11
+ * @param {object} config Javascript configuration
12
+ * @param {object} fullConfig Full configuration
13
+ * @returns {object} Transformed javascript configuration
14
+ */
15
+ export default function preprocessJavascriptsConfig(config, fullConfig) {
16
+ let entryList = config.entryList;
17
+
18
+ // User may specify a function, execute it to get object / array
19
+ if (typeof entryList === 'function') {
20
+ entryList = entryList(config);
21
+ }
22
+
23
+ // User may specify multiple entry list files, convert to array
24
+ if (!Array.isArray(entryList)) {
25
+ entryList = [entryList];
26
+ }
27
+
28
+ // User may specify only a name of the entry file
29
+ // Set shared chunk name for each of the entry files
30
+ // Each entryList item is { name: '...', shared?: '...', outpuSubFolder?: '...' }
31
+ entryList = entryList.map((entry, index) => {
32
+ return {
33
+ name: typeof entry === 'string' ? entry : entry.name,
34
+ shared: typeof entry !== 'string' && entry && entry.shared ? entry.shared : index === 0 ? 'shared' : '',
35
+ outpuSubFolder: typeof entry !== 'string' && entry && entry.outpuSubFolder ? entry.outpuSubFolder : '',
36
+ };
37
+ });
38
+
39
+ return entryList.map((entry) => {
40
+ const entryConfig = cloneDeep(config);
41
+ entryConfig.rolldown = Object.assign({}, entryConfig.rolldown);
42
+
43
+ // Output paths
44
+ const output = merge({}, get(entryConfig, ['rolldown', 'output'], null));
45
+
46
+ output.dir = output.dir.replace('[folder]/', entry.outpuSubFolder ? entry.outpuSubFolder + '/' : '').replace('[folder]', entry.outpuSubFolder ? entry.outpuSubFolder : '');
47
+
48
+ output.dir = getDestPath('javascripts', output.dir);
49
+
50
+ // Use process.env... variables from .env files
51
+ const envVariables = merge(getEnvData().js, {
52
+ 'process.env.NODE_ENV': JSON.stringify(global.production ? 'production' : 'development'),
53
+ });
54
+
55
+ // Rewrite shared.js and rolldown-runtime.js to include cache busting asset version so that we could
56
+ // preload those assets using <link rel="preload" as="script" href="{{ asset(...) }}" />
57
+ const envData = loadEnvData();
58
+ const assetVersion = envData['ASSETS_VERSION'];
59
+ const replacements = {};
60
+
61
+ if (assetVersion) {
62
+ replacements['/rolldown-runtime.js'] = `/rolldown-runtime.js?v=${assetVersion}`;
63
+
64
+ if (entry.shared) {
65
+ replacements[`/${entry.shared}.js`] = `/${entry.shared}.js?v=${assetVersion}`;
66
+ }
67
+ }
68
+
69
+ const buildConfig = merge(entryConfig, {
70
+ rolldown: {
71
+ // Entries, this file is resolved by gulp-rolldown and converted into
72
+ // `inputs` option
73
+ entries: entry,
74
+
75
+ plugins: [
76
+ replace({
77
+ preventAssignment: true,
78
+ ...envVariables,
79
+ ...replacements,
80
+ }),
81
+ ],
82
+
83
+ // Output folder
84
+ output: output,
85
+
86
+ // Imports
87
+ resolve: merge(
88
+ {
89
+ // File extensions
90
+ extensions: entryConfig.extensions.map((extension) => `.${extension}`),
91
+
92
+ // Import folders
93
+ modules: [
94
+ // Allow imports from node_modules
95
+ getBuilderPath('node_modules'),
96
+ getProjectPath('node_modules'),
97
+
98
+ // Allow imports from source folder
99
+ getSourcePath('javascripts'),
100
+ ],
101
+ },
102
+ get(entryConfig, ['rolldown', 'resolve'], {}),
103
+ ),
104
+ },
105
+ });
106
+
107
+ return buildConfig;
108
+ });
109
+ }