@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,85 +1,85 @@
1
- import map from 'lodash/map.js';
2
- import assign from 'lodash/assign.js';
3
- import filter from 'lodash/filter.js';
4
- import { series, parallel } from 'gulp';
5
- import { DEFAULT_TASKS, BUILD_TASKS } from './task-order.js';
6
- import resolveDynamicTask from './gulp/resolve-dynamic-task.js';
7
-
8
- /**
9
- * Sort tasks by .order property
10
- *
11
- * @param {array} tasks Tasks
12
- * @returns {array} Sorted tasks
13
- */
14
- function sortTasks (tasks) {
15
- return tasks.sort((a, b) => (a.order || 0) - (b.order || 0));
16
- }
17
-
18
- /**
19
- * Organize and order tasks
20
- *
21
- * @param {object} taskConfig Task config
22
- * @returns {object} Task list
23
- */
24
- export function generateTaskList (taskConfig) {
25
- const taskList = {
26
- 'default': map(DEFAULT_TASKS, (taskName) => []),
27
- 'build': map(BUILD_TASKS, (taskName) => []),
28
- 'separate': {}
29
- };
30
-
31
- for (let taskName in taskConfig.tasks) {
32
- // Make sure task is not disabled
33
- if (taskConfig[taskName] !== false) {
34
- const functions = taskConfig.tasks[taskName];
35
-
36
- for (let i = 0; i < functions.length; i++) {
37
- const gulpTaskList = functions[i];
38
-
39
- // Create individual tasks, which can be run separatelly
40
- for (let gulpTaskName in gulpTaskList) {
41
- taskList.separate[`${ taskName }-${ gulpTaskName }`] = resolveDynamicTask(gulpTaskList[gulpTaskName]);
42
- }
43
-
44
- for (let t = 0; t < DEFAULT_TASKS.length; t++) {
45
- if (DEFAULT_TASKS[t] in gulpTaskList) {
46
- const gulpTask = resolveDynamicTask(gulpTaskList[DEFAULT_TASKS[t]]);
47
- taskList.default[t].push(gulpTask);
48
- }
49
- if (BUILD_TASKS[t] in gulpTaskList) {
50
- const gulpTask = resolveDynamicTask(gulpTaskList[BUILD_TASKS[t]]);
51
- taskList.build[t].push(gulpTask);
52
- }
53
- }
54
- }
55
- }
56
- }
57
-
58
- taskList.default = filter(taskList.default, taskGroup => taskGroup.length).sort(sortTasks);
59
- taskList.build = filter(taskList.build, taskGroup => taskGroup.length).sort(sortTasks);
60
-
61
- // Alias default to watch
62
- taskList.watch = taskList.default;
63
-
64
- return taskList;
65
- }
66
-
67
- /**
68
- * Generate gulp tasks with parallel and serial
69
- *
70
- * @param {object} taskConfig Task config
71
- * @returns {object} Gulp task list
72
- */
73
- export default function generateGulpTasks (taskConfig) {
74
- const taskList = generateTaskList(taskConfig);
75
-
76
- // Create gulp tasks with parallel and series
77
- const defaultGulpTasks = map(taskList.default, (tasks) => parallel(...tasks));
78
- const buildGulpTasks = map(taskList.build, (tasks) => parallel(...tasks));
79
-
80
- return assign({
81
- 'default': series(...defaultGulpTasks),
82
- 'watch': series(...defaultGulpTasks), // watch and default are aliases
83
- 'build': series(...buildGulpTasks),
84
- }, taskList.separate);
85
- }
1
+ import map from 'lodash/map.js';
2
+ import assign from 'lodash/assign.js';
3
+ import filter from 'lodash/filter.js';
4
+ import { series, parallel } from 'gulp';
5
+ import { DEFAULT_TASKS, BUILD_TASKS } from './task-order.js';
6
+ import resolveDynamicTask from './gulp/resolve-dynamic-task.js';
7
+
8
+ /**
9
+ * Sort tasks by .order property
10
+ *
11
+ * @param {array} tasks Tasks
12
+ * @returns {array} Sorted tasks
13
+ */
14
+ function sortTasks (tasks) {
15
+ return tasks.sort((a, b) => (a.order || 0) - (b.order || 0));
16
+ }
17
+
18
+ /**
19
+ * Organize and order tasks
20
+ *
21
+ * @param {object} taskConfig Task config
22
+ * @returns {object} Task list
23
+ */
24
+ export function generateTaskList (taskConfig) {
25
+ const taskList = {
26
+ 'default': map(DEFAULT_TASKS, (taskName) => []),
27
+ 'build': map(BUILD_TASKS, (taskName) => []),
28
+ 'separate': {}
29
+ };
30
+
31
+ for (let taskName in taskConfig.tasks) {
32
+ // Make sure task is not disabled
33
+ if (taskConfig[taskName] !== false) {
34
+ const functions = taskConfig.tasks[taskName];
35
+
36
+ for (let i = 0; i < functions.length; i++) {
37
+ const gulpTaskList = functions[i];
38
+
39
+ // Create individual tasks, which can be run separatelly
40
+ for (let gulpTaskName in gulpTaskList) {
41
+ taskList.separate[`${ taskName }-${ gulpTaskName }`] = resolveDynamicTask(gulpTaskList[gulpTaskName]);
42
+ }
43
+
44
+ for (let t = 0; t < DEFAULT_TASKS.length; t++) {
45
+ if (DEFAULT_TASKS[t] in gulpTaskList) {
46
+ const gulpTask = resolveDynamicTask(gulpTaskList[DEFAULT_TASKS[t]]);
47
+ taskList.default[t].push(gulpTask);
48
+ }
49
+ if (BUILD_TASKS[t] in gulpTaskList) {
50
+ const gulpTask = resolveDynamicTask(gulpTaskList[BUILD_TASKS[t]]);
51
+ taskList.build[t].push(gulpTask);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ taskList.default = filter(taskList.default, taskGroup => taskGroup.length).sort(sortTasks);
59
+ taskList.build = filter(taskList.build, taskGroup => taskGroup.length).sort(sortTasks);
60
+
61
+ // Alias default to watch
62
+ taskList.watch = taskList.default;
63
+
64
+ return taskList;
65
+ }
66
+
67
+ /**
68
+ * Generate gulp tasks with parallel and serial
69
+ *
70
+ * @param {object} taskConfig Task config
71
+ * @returns {object} Gulp task list
72
+ */
73
+ export default function generateGulpTasks (taskConfig) {
74
+ const taskList = generateTaskList(taskConfig);
75
+
76
+ // Create gulp tasks with parallel and series
77
+ const defaultGulpTasks = map(taskList.default, (tasks) => parallel(...tasks));
78
+ const buildGulpTasks = map(taskList.build, (tasks) => parallel(...tasks));
79
+
80
+ return assign({
81
+ 'default': series(...defaultGulpTasks),
82
+ 'watch': series(...defaultGulpTasks), // watch and default are aliases
83
+ 'build': series(...buildGulpTasks),
84
+ }, taskList.separate);
85
+ }
package/lib/get-config.js CHANGED
@@ -1,204 +1,203 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import { getProjectPath } from './get-path.js';
6
- import runPreprocess from './run-preprocess.js';
7
- import merge from './merge.js';
8
- import logError from './log-error.js';
9
-
10
- import each from 'lodash/each.js';
11
- import omit from 'lodash/omit.js';
12
- import isPlainObject from 'lodash/isPlainObject.js';
13
- import isArray from 'lodash/isArray.js';
14
- import reduce from 'lodash/reduce.js';
15
- import get from 'lodash/get.js';
16
- import { Module } from 'node:module';
17
-
18
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
-
20
- /**
21
- * Returns builder and project specific task and plugin configurations combined
22
- * Configuration is preprocessed
23
- *
24
- * @returns {object} Task configurations
25
- */
26
-
27
- let taskConfig = null;
28
-
29
- /**
30
- * Load and process config files
31
- *
32
- * @param {string} builderConfigFile Builder config file path
33
- * @returns {object} Task configurations
34
- */
35
- export async function getConfigAsync(builderConfigFile) {
36
- if (!taskConfig) {
37
- // Load all task configs
38
- taskConfig = itterateConfig(await loadConfig(), mergeConfigMode);
39
-
40
- // 1. First load project specific config.js
41
- const projectConfigPath = getProjectPath(builderConfigFile);
42
- let projectTaskConfig = {};
43
- let hasProjectConfigFile = true;
44
-
45
- try {
46
- fs.accessSync(projectConfigPath);
47
- } catch (err) {
48
- logError({ plugin: 'static-website-builder', message: `Couldn't find configuration file "${projectConfigPath}"` });
49
- hasProjectConfigFile = false;
50
- }
51
-
52
- if (hasProjectConfigFile) {
53
- await import(projectConfigPath).then((config) => {
54
- projectTaskConfig = itterateConfig(config, mergeConfigMode);
55
- });
56
- }
57
-
58
- // 2. Marge plugins into the config, each plugin is just a config
59
- const plugins = (taskConfig.plugins || []).concat(projectTaskConfig.plugins || []);
60
- if (plugins) {
61
- taskConfig.plugins = null;
62
- projectTaskConfig.plugins = null;
63
-
64
- each(plugins, (plugin) => {
65
- taskConfig = merge(taskConfig, itterateConfig(plugin, mergeConfigMode));
66
- });
67
- }
68
-
69
- // 3. Only after plugins has been executed, merge project specific config.js into main config
70
- if (projectTaskConfig) {
71
- taskConfig = merge(taskConfig, projectTaskConfig);
72
- }
73
-
74
- // 4. Preprocess
75
- taskConfig = runPreprocess(taskConfig);
76
- }
77
-
78
- return taskConfig;
79
- }
80
-
81
- /**
82
- * Returns loaded task config
83
- *
84
- * @returns {object} Task configurations
85
- */
86
- export function getConfig() {
87
- if (!taskConfig) {
88
- throw new Error('Task config not loaded yet');
89
- }
90
-
91
- return taskConfig;
92
- }
93
-
94
- /**
95
- * Returns task sub-config by path
96
- *
97
- * @param {...string} path Path to the sub-config
98
- * @returns {any} Task sub-config
99
- */
100
- export function getTaskConfig(...path) {
101
- return get(getConfig(), path, null);
102
- }
103
-
104
- /**
105
- * Itterate over each config property and call function on
106
- * each object or array
107
- *
108
- * @param {*} object
109
- * @param {*} fn
110
- * @protected
111
- */
112
- function itterateConfig(config, fn) {
113
- if (config === false) return false;
114
- const base = isPlainObject(config) ? {} : [];
115
-
116
- return reduce(
117
- config,
118
- (object, value, key) => {
119
- // Detect ES modules and extract 'default' and other properties
120
- if (value && Object.prototype.toString.call(value) === '[object Module]') {
121
- const module = value;
122
-
123
- if ('default' in module) {
124
- value = module.default;
125
- value.default = module.default;
126
- } else {
127
- value = {};
128
- }
129
-
130
- for (let key in module) {
131
- if (key !== 'default') {
132
- value[key] = module[key];
133
- }
134
- }
135
- }
136
-
137
- if (isPlainObject(value)) {
138
- object[key] = itterateConfig(fn(value), fn);
139
- } else if (isArray(value)) {
140
- object[key] = itterateConfig(value, fn);
141
- } else {
142
- object[key] = value;
143
- }
144
-
145
- return object;
146
- },
147
- base,
148
- );
149
- }
150
-
151
- /**
152
- * Merge 'production' or 'development' mode sub-ojbects into an object and remove
153
- * mode sub-objects
154
- *
155
- * @param {object} config Config
156
- * @returns {object} Config
157
- * @protected
158
- */
159
- function mergeConfigMode(config) {
160
- if ('production' in config || 'development' in config) {
161
- const mode = global.production ? 'production' : 'development';
162
- const value = typeof config[mode] === 'undefined' ? config : merge(config, config[mode]);
163
-
164
- if (value !== false) {
165
- return omit(value, ['production', 'development']);
166
- } else {
167
- return value;
168
- }
169
- } else {
170
- return config;
171
- }
172
- }
173
-
174
- /**
175
- * Load config files
176
- *
177
- * @returns {object} Configuration
178
- * @protected
179
- */
180
- async function loadConfig() {
181
- const taskFolder = path.resolve(__dirname, '../tasks');
182
- let taskConfig = {};
183
-
184
- await Promise.all(
185
- fs.readdirSync(taskFolder).map((folderName) => {
186
- // Ignore task folders which start with underscore
187
- if (folderName[0] !== '_') {
188
- const configFileName = path.resolve(taskFolder, folderName, 'config.js');
189
-
190
- try {
191
- fs.accessSync(configFileName);
192
- } catch (err) {
193
- return;
194
- }
195
-
196
- return import(configFileName).then((config) => {
197
- taskConfig = merge(taskConfig, config);
198
- });
199
- }
200
- }),
201
- );
202
-
203
- return taskConfig;
204
- }
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+
5
+ import { getProjectPath } from './get-path.js';
6
+ import runPreprocess from './run-preprocess.js';
7
+ import merge from './merge.js';
8
+ import logError from './log-error.js';
9
+
10
+ import each from 'lodash/each.js';
11
+ import omit from 'lodash/omit.js';
12
+ import isPlainObject from 'lodash/isPlainObject.js';
13
+ import isArray from 'lodash/isArray.js';
14
+ import reduce from 'lodash/reduce.js';
15
+ import get from 'lodash/get.js';
16
+
17
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
+
19
+ /**
20
+ * Returns builder and project specific task and plugin configurations combined
21
+ * Configuration is preprocessed
22
+ *
23
+ * @returns {object} Task configurations
24
+ */
25
+
26
+ let taskConfig = null;
27
+
28
+ /**
29
+ * Load and process config files
30
+ *
31
+ * @param {string} builderConfigFile Builder config file path
32
+ * @returns {object} Task configurations
33
+ */
34
+ export async function getConfigAsync(builderConfigFile) {
35
+ if (!taskConfig) {
36
+ // Load all task configs
37
+ taskConfig = itterateConfig(await loadConfig(), mergeConfigMode);
38
+
39
+ // 1. First load project specific config.js
40
+ const projectConfigPath = getProjectPath(builderConfigFile);
41
+ let projectTaskConfig = {};
42
+ let hasProjectConfigFile = true;
43
+
44
+ try {
45
+ fs.accessSync(projectConfigPath);
46
+ } catch (err) {
47
+ logError({ plugin: 'static-website-builder', message: `Couldn't find configuration file "${projectConfigPath}"` });
48
+ hasProjectConfigFile = false;
49
+ }
50
+
51
+ if (hasProjectConfigFile) {
52
+ await import(pathToFileURL(projectConfigPath)).then((config) => {
53
+ projectTaskConfig = itterateConfig(config, mergeConfigMode);
54
+ });
55
+ }
56
+
57
+ // 2. Marge plugins into the config, each plugin is just a config
58
+ const plugins = (taskConfig.plugins || []).concat(projectTaskConfig.plugins || []);
59
+ if (plugins) {
60
+ taskConfig.plugins = null;
61
+ projectTaskConfig.plugins = null;
62
+
63
+ each(plugins, (plugin) => {
64
+ taskConfig = merge(taskConfig, itterateConfig(plugin, mergeConfigMode));
65
+ });
66
+ }
67
+
68
+ // 3. Only after plugins has been executed, merge project specific config.js into main config
69
+ if (projectTaskConfig) {
70
+ taskConfig = merge(taskConfig, projectTaskConfig);
71
+ }
72
+
73
+ // 4. Preprocess
74
+ taskConfig = runPreprocess(taskConfig);
75
+ }
76
+
77
+ return taskConfig;
78
+ }
79
+
80
+ /**
81
+ * Returns loaded task config
82
+ *
83
+ * @returns {object} Task configurations
84
+ */
85
+ export function getConfig() {
86
+ if (!taskConfig) {
87
+ throw new Error('Task config not loaded yet');
88
+ }
89
+
90
+ return taskConfig;
91
+ }
92
+
93
+ /**
94
+ * Returns task sub-config by path
95
+ *
96
+ * @param {...string} path Path to the sub-config
97
+ * @returns {any} Task sub-config
98
+ */
99
+ export function getTaskConfig(...path) {
100
+ return get(getConfig(), path, null);
101
+ }
102
+
103
+ /**
104
+ * Itterate over each config property and call function on
105
+ * each object or array
106
+ *
107
+ * @param {*} object
108
+ * @param {*} fn
109
+ * @protected
110
+ */
111
+ function itterateConfig(config, fn) {
112
+ if (config === false) return false;
113
+ const base = isPlainObject(config) ? {} : [];
114
+
115
+ return reduce(
116
+ config,
117
+ (object, value, key) => {
118
+ // Detect ES modules and extract 'default' and other properties
119
+ if (value && Object.prototype.toString.call(value) === '[object Module]') {
120
+ const module = value;
121
+
122
+ if ('default' in module) {
123
+ value = module.default;
124
+ value.default = module.default;
125
+ } else {
126
+ value = {};
127
+ }
128
+
129
+ for (let key in module) {
130
+ if (key !== 'default') {
131
+ value[key] = module[key];
132
+ }
133
+ }
134
+ }
135
+
136
+ if (isPlainObject(value)) {
137
+ object[key] = itterateConfig(fn(value), fn);
138
+ } else if (isArray(value)) {
139
+ object[key] = itterateConfig(value, fn);
140
+ } else {
141
+ object[key] = value;
142
+ }
143
+
144
+ return object;
145
+ },
146
+ base,
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Merge 'production' or 'development' mode sub-ojbects into an object and remove
152
+ * mode sub-objects
153
+ *
154
+ * @param {object} config Config
155
+ * @returns {object} Config
156
+ * @protected
157
+ */
158
+ function mergeConfigMode(config) {
159
+ if ('production' in config || 'development' in config) {
160
+ const mode = global.production ? 'production' : 'development';
161
+ const value = typeof config[mode] === 'undefined' ? config : merge(config, config[mode]);
162
+
163
+ if (value !== false) {
164
+ return omit(value, ['production', 'development']);
165
+ } else {
166
+ return value;
167
+ }
168
+ } else {
169
+ return config;
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Load config files
175
+ *
176
+ * @returns {object} Configuration
177
+ * @protected
178
+ */
179
+ async function loadConfig() {
180
+ const taskFolder = path.resolve(__dirname, '../tasks');
181
+ let taskConfig = {};
182
+
183
+ await Promise.all(
184
+ fs.readdirSync(taskFolder).map((folderName) => {
185
+ // Ignore task folders which start with underscore
186
+ if (folderName[0] !== '_') {
187
+ const configFileName = path.resolve(taskFolder, folderName, 'config.js');
188
+
189
+ try {
190
+ fs.accessSync(configFileName);
191
+ } catch (err) {
192
+ return;
193
+ }
194
+
195
+ return import(pathToFileURL(configFileName)).then((config) => {
196
+ taskConfig = merge(taskConfig, config);
197
+ });
198
+ }
199
+ }),
200
+ );
201
+
202
+ return taskConfig;
203
+ }
@@ -1,23 +1,23 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- /**
5
- * Returns list of filenames in folder recursively
6
- *
7
- * @param {string} folder Folder path
8
- * @param {string} [subFolder=''] Subfolder path
9
- * @returns {array} List of filenames, relative to folder
10
- */
11
- export default function getFileNamesSync (folder, subFolder = '') {
12
- let fileNames = []
13
-
14
- fs.readdirSync(folder, { withFileTypes: true }).forEach(file => {
15
- if (file.isDirectory()) {
16
- fileNames = fileNames.concat(getFileNamesSync(path.join(folder, file.name), path.join(subFolder, file.name)));
17
- } else {
18
- fileNames.push(path.join(subFolder, file.name))
19
- }
20
- });
21
-
22
- return fileNames;
23
- }
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * Returns list of filenames in folder recursively
6
+ *
7
+ * @param {string} folder Folder path
8
+ * @param {string} [subFolder=''] Subfolder path
9
+ * @returns {array} List of filenames, relative to folder
10
+ */
11
+ export default function getFileNamesSync (folder, subFolder = '') {
12
+ let fileNames = []
13
+
14
+ fs.readdirSync(folder, { withFileTypes: true }).forEach(file => {
15
+ if (file.isDirectory()) {
16
+ fileNames = fileNames.concat(getFileNamesSync(path.join(folder, file.name), path.join(subFolder, file.name)));
17
+ } else {
18
+ fileNames.push(path.join(subFolder, file.name))
19
+ }
20
+ });
21
+
22
+ return fileNames;
23
+ }