@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.
- package/.prettierrc +11 -11
- package/CHANGELOG.md +214 -210
- package/README.md +102 -102
- package/bin/builder.js +40 -40
- package/eslint.config.js +39 -39
- package/gulpfile.js +63 -63
- package/init/default/config/config.js +44 -44
- package/init/default/src/html/data/global.js +9 -9
- package/init/default/src/javascripts/_entries.js +14 -14
- package/init/index.js +63 -63
- package/init/test/.env +6 -6
- package/init/test/.env.local +3 -2
- package/init/test/config/config.js +71 -67
- package/init/test/src/html/404.twig +12 -12
- package/init/test/src/html/data/global.js +10 -10
- package/init/test/src/html/env.twig +21 -21
- package/init/test/src/html/layouts/base.twig +1 -1
- package/init/test/src/html/other.twig +9 -9
- package/init/test/src/html/preposition.twig +4 -4
- package/init/test/src/javascripts/_entries-alt.js +10 -10
- package/init/test/src/javascripts/_entries.js +19 -19
- package/init/test/src/javascripts/common.js +13 -13
- package/init/test/src/javascripts/main.js +8 -8
- package/init/test/src/javascripts/something.ts +9 -9
- package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
- package/init/test/src/stylesheets/env-test.scss +28 -28
- package/init/test/src/stylesheets/ignore-test.scss +4 -4
- package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
- package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
- package/lib/camelize-file-name.js +21 -21
- package/lib/generate-gulp-tasks.js +85 -85
- package/lib/get-config.js +203 -204
- package/lib/get-file-names.js +23 -23
- package/lib/get-path.js +102 -102
- package/lib/globs-helper.js +243 -243
- package/lib/gulp/dynamic-task.js +8 -8
- package/lib/gulp/resolve-dynamic-task.js +11 -11
- package/lib/gulp/task-before-dest.js +8 -8
- package/lib/gulp/task-end.js +10 -10
- package/lib/gulp/task-start.js +12 -12
- package/lib/gulp/task-watch.js +66 -66
- package/lib/init/copy-folder.js +50 -50
- package/lib/init/folder-exists.js +10 -10
- package/lib/init/get-folder-list.js +16 -16
- package/lib/init/merge-package.js +17 -17
- package/lib/init/read-package.js +17 -17
- package/lib/log-error.js +15 -15
- package/lib/merge.js +27 -27
- package/lib/run-preprocess.js +32 -32
- package/lib/task-order.js +19 -19
- package/package.json +68 -68
- package/plugins/example/preprocess-config.js +17 -17
- package/plugins/example/task.js +55 -55
- package/plugins/example.js +38 -38
- package/plugins/sass-engine/preprocess-config.js +59 -59
- package/plugins/sass.js +41 -41
- package/plugins/twig/lodash-filters/filters.js +91 -91
- package/plugins/twig/lodash-filters.js +14 -14
- package/plugins/twig/symfony-filters/filters.js +102 -102
- package/plugins/twig/symfony-filters/preposition_nbsp.js +77 -77
- package/plugins/twig/symfony-filters.js +14 -14
- package/plugins/twig/symfony-functions/functions.js +31 -31
- package/plugins/twig/symfony-functions.js +14 -14
- package/plugins/twig-engine/preprocess-config.js +53 -53
- package/plugins/twig.js +74 -74
- package/tasks/browser-sync/config.js +39 -39
- package/tasks/browser-sync/preprocess-config.js +32 -32
- package/tasks/browser-sync/task.js +9 -9
- package/tasks/clean/config.js +20 -20
- package/tasks/clean/preprocess-config.js +19 -19
- package/tasks/clean/task.js +7 -7
- package/tasks/data/config.js +34 -34
- package/tasks/data/data-loader-js.js +14 -14
- package/tasks/data/data-loader-json.js +5 -5
- package/tasks/data/get-data.js +96 -96
- package/tasks/env/config.js +26 -23
- package/tasks/env/get-env.js +113 -81
- package/tasks/fonts/config.js +24 -24
- package/tasks/fonts/task.js +47 -47
- package/tasks/global/config.js +7 -7
- package/tasks/html/config.js +42 -42
- package/tasks/html/task.js +91 -91
- package/tasks/icons/config.js +47 -47
- package/tasks/icons/preprocess-config.js +60 -60
- package/tasks/icons/task.js +56 -56
- package/tasks/images/config.js +27 -27
- package/tasks/images/task.js +46 -46
- package/tasks/javascripts/config.js +69 -69
- package/tasks/javascripts/preprocess-config.js +109 -109
- package/tasks/javascripts/task.js +86 -86
- package/tasks/sitemap/config.js +48 -48
- package/tasks/sitemap/preprocess-config.js +18 -18
- package/tasks/sitemap/task.js +69 -69
- package/tasks/sizereport/config.js +23 -23
- package/tasks/sizereport/task.js +16 -16
- package/tasks/static/config.js +27 -27
- package/tasks/static/task.js +46 -46
- package/tasks/stylesheets/config.js +85 -85
- package/tasks/stylesheets/preprocess-config.js +41 -41
- package/tasks/stylesheets/task.js +73 -73
- package/tests/build/build.test.js +153 -153
- package/tests/camelize-file-name.test.js +11 -11
- package/tests/generate-gulp-tasks.test.js +78 -78
- package/tests/glob-helper.test.js +99 -99
- package/tests/merge.test.js +10 -10
- package/tests/preposition_nbsp.test.js +50 -50
- package/tests/run-preprocess.test.js +90 -90
- package/tests/sass-stringify.test.js +24 -24
- package/tests/sitemap.test.js +12 -12
- package/vendor/gulp-rolldown/index.js +151 -151
- package/vendor/gulp-rolldown/plugin-raw.js +17 -17
- package/vendor/gulp-rolldown/plugin-virtual-entry.js +30 -30
- package/vendor/gulp-sass/CHANGELOG.md +168 -168
- package/vendor/gulp-sass/LICENSE +20 -20
- package/vendor/gulp-sass/README.md +187 -187
- package/vendor/gulp-sass/index.js +208 -208
- package/vendor/gulp-sass/package.json +61 -61
- package/vendor/gulp-sass/sass-stringify.js +32 -32
- package/vendor/gulp-twig/LICENSE +20 -20
- package/vendor/gulp-twig/README.md +167 -167
- package/vendor/gulp-twig/index.js +138 -138
- 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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @param {*}
|
|
109
|
-
* @
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
value = module.default;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* @
|
|
156
|
-
* @
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* @
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
+
}
|
package/lib/get-file-names.js
CHANGED
|
@@ -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
|
+
}
|