@videinfra/static-website-builder 2.0.4 → 2.0.6

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 +226 -214
  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 -3
  13. package/init/test/config/config.js +71 -71
  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 -203
  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 +135 -96
  76. package/tasks/env/config.js +26 -26
  77. package/tasks/env/get-env.js +113 -113
  78. package/tasks/fonts/config.js +24 -24
  79. package/tasks/fonts/task.js +51 -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 +159 -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,21 +1,21 @@
1
- /**
2
- * Camelize filename
3
- *
4
- * @param {string} str File name
5
- * @returns {string} Camelized name
6
- */
7
- export default function camelizeFileName (str) {
8
- return str
9
- // Remove extension
10
- .replace(/(.+?)\..*$/ig, '$1')
11
- // Remove dot
12
- .replace(/\./g, '')
13
- // Replace non alpha-numeric characters
14
- .replace(/[^a-z0-9]/ig, ' ')
15
- // Uppercase words
16
- .replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
17
- return index === 0 ? word.toLowerCase() : word.toUpperCase();
18
- })
19
- // Remove empty spaces
20
- .replace(/\s+/g, '');
21
- }
1
+ /**
2
+ * Camelize filename
3
+ *
4
+ * @param {string} str File name
5
+ * @returns {string} Camelized name
6
+ */
7
+ export default function camelizeFileName (str) {
8
+ return str
9
+ // Remove extension
10
+ .replace(/(.+?)\..*$/ig, '$1')
11
+ // Remove dot
12
+ .replace(/\./g, '')
13
+ // Replace non alpha-numeric characters
14
+ .replace(/[^a-z0-9]/ig, ' ')
15
+ // Uppercase words
16
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
17
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
18
+ })
19
+ // Remove empty spaces
20
+ .replace(/\s+/g, '');
21
+ }
@@ -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,203 +1,203 @@
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
+ 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
+ }