@videinfra/static-website-builder 2.0.0-beta.2 → 2.0.0-beta.3

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 (99) hide show
  1. package/.eslintrc.js +1 -1
  2. package/.prettierrc +11 -0
  3. package/README.md +2 -2
  4. package/bin/builder.js +17 -11
  5. package/gulpfile.js +63 -0
  6. package/init/default/config/config.js +18 -15
  7. package/init/default/src/html/data/global.js +1 -1
  8. package/init/default/src/javascripts/_entries.js +1 -1
  9. package/init/index.js +44 -37
  10. package/init/test/config/config.js +20 -16
  11. package/init/test/src/html/data/global.js +1 -1
  12. package/lib/camelize-file-name.js +1 -1
  13. package/lib/generate-gulp-tasks.js +12 -10
  14. package/lib/get-config.js +99 -52
  15. package/lib/get-file-names.js +3 -3
  16. package/lib/get-path.js +15 -22
  17. package/lib/globs-helper.js +22 -47
  18. package/lib/gulp/dynamic-task.js +1 -1
  19. package/lib/gulp/resolve-dynamic-task.js +1 -1
  20. package/lib/gulp/task-before-dest.js +2 -2
  21. package/lib/gulp/task-end.js +5 -5
  22. package/lib/gulp/task-start.js +3 -3
  23. package/lib/gulp/task-watch.js +10 -10
  24. package/lib/init/copy-folder.js +4 -4
  25. package/lib/init/folder-exists.js +2 -2
  26. package/lib/init/get-folder-list.js +3 -3
  27. package/lib/init/merge-package.js +8 -8
  28. package/lib/init/read-package.js +2 -2
  29. package/lib/log-error.js +3 -3
  30. package/lib/merge.js +3 -3
  31. package/lib/run-preprocess.js +2 -2
  32. package/lib/task-order.js +7 -13
  33. package/package.json +6 -4
  34. package/plugins/example/preprocess-config.js +1 -1
  35. package/plugins/example/task.js +13 -13
  36. package/plugins/example.js +8 -6
  37. package/plugins/sass-engine/preprocess-config.js +15 -19
  38. package/plugins/sass.js +5 -3
  39. package/plugins/twig/lodash-filters/filters.js +12 -10
  40. package/plugins/twig/lodash-filters.js +3 -3
  41. package/plugins/twig/symfony-filters/filters.js +11 -10
  42. package/plugins/twig/symfony-filters/preposition_nbsp.js +1 -1
  43. package/plugins/twig/symfony-filters.js +6 -6
  44. package/plugins/twig/symfony-functions/functions.js +2 -2
  45. package/plugins/twig/symfony-functions.js +6 -6
  46. package/plugins/twig-engine/preprocess-config.js +8 -8
  47. package/plugins/twig.js +11 -6
  48. package/tasks/browser-sync/config.js +9 -6
  49. package/tasks/browser-sync/preprocess-config.js +5 -7
  50. package/tasks/browser-sync/task.js +5 -5
  51. package/tasks/clean/config.js +8 -5
  52. package/tasks/clean/preprocess-config.js +5 -5
  53. package/tasks/clean/task.js +5 -5
  54. package/tasks/data/config.js +11 -13
  55. package/tasks/data/data-loader-js.js +11 -2
  56. package/tasks/data/data-loader-json.js +3 -3
  57. package/tasks/data/get-data.js +55 -52
  58. package/tasks/env/config.js +2 -2
  59. package/tasks/env/get-env.js +13 -13
  60. package/tasks/fonts/config.js +9 -10
  61. package/tasks/fonts/task.js +27 -27
  62. package/tasks/global/config.js +1 -1
  63. package/tasks/html/config.js +13 -15
  64. package/tasks/html/task.js +55 -54
  65. package/tasks/icons/config.js +17 -22
  66. package/tasks/icons/preprocess-config.js +4 -4
  67. package/tasks/icons/task.js +34 -35
  68. package/tasks/images/config.js +11 -14
  69. package/tasks/images/task.js +26 -26
  70. package/tasks/javascripts/config.js +12 -14
  71. package/tasks/javascripts/preprocess-config.js +30 -30
  72. package/tasks/javascripts/task.js +40 -43
  73. package/tasks/sitemap/config.js +12 -13
  74. package/tasks/sitemap/preprocess-config.js +2 -2
  75. package/tasks/sitemap/task.js +44 -38
  76. package/tasks/sizereport/config.js +5 -3
  77. package/tasks/sizereport/task.js +8 -8
  78. package/tasks/static/config.js +12 -15
  79. package/tasks/static/task.js +27 -28
  80. package/tasks/stylesheets/config.js +16 -19
  81. package/tasks/stylesheets/preprocess-config.js +5 -5
  82. package/tasks/stylesheets/task.js +28 -28
  83. package/tests/build/build.test.js +23 -22
  84. package/tests/camelize-file-name.test.js +1 -1
  85. package/tests/generate-gulp-tasks.test.js +11 -5
  86. package/tests/glob-helper.test.js +1 -1
  87. package/tests/merge.test.js +1 -1
  88. package/tests/preposition_nbsp.test.js +7 -6
  89. package/tests/run-preprocess.test.js +2 -1
  90. package/tests/sass-stringify.test.js +1 -1
  91. package/tests/sitemap.test.js +7 -6
  92. package/vendor/gulp-rolldown/index.js +27 -29
  93. package/vendor/gulp-sass/README.md +10 -19
  94. package/vendor/gulp-sass/index.js +129 -135
  95. package/vendor/gulp-sass/package.json +1 -0
  96. package/vendor/gulp-sass/sass-stringify.js +1 -1
  97. package/vendor/gulp-twig/index.js +32 -27
  98. package/vendor/gulp-twig/package.json +1 -0
  99. package/gulpfile.js/index.js +0 -32
package/lib/get-config.js CHANGED
@@ -1,17 +1,21 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const getPath = require('./get-path');
4
- const runPreprocess = require('./run-preprocess');
5
- const merge = require('./merge');
6
- const logError = require('./log-error');
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'node:url';
7
4
 
8
- const each = require('lodash/each');
9
- const omit = require('lodash/omit');
10
- const isPlainObject = require('lodash/isPlainObject');
11
- const isArray = require('lodash/isArray');
12
- const reduce = require('lodash/reduce');
13
- const get = require('lodash/get');
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';
14
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));
15
19
 
16
20
  /**
17
21
  * Returns builder and project specific task and plugin configurations combined
@@ -22,25 +26,33 @@ const get = require('lodash/get');
22
26
 
23
27
  let taskConfig = null;
24
28
 
25
- function getConfig (builderConfigFile) {
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) {
26
36
  if (!taskConfig) {
27
37
  // Load all task configs
28
- taskConfig = itterateConfig(loadConfig(), mergeConfigMode);
38
+ taskConfig = itterateConfig(await loadConfig(), mergeConfigMode);
29
39
 
30
40
  // 1. First load project specific config.js
31
- const projectConfigPath = getPath.getProjectPath(builderConfigFile);
32
- let projectTaskConfig = {};
33
- let hasProjectConfigFile = true;
41
+ const projectConfigPath = getProjectPath(builderConfigFile);
42
+ let projectTaskConfig = {};
43
+ let hasProjectConfigFile = true;
34
44
 
35
45
  try {
36
46
  fs.accessSync(projectConfigPath);
37
47
  } catch (err) {
38
- logError({'plugin': 'static-website-builder', 'message': `Couldn't find configuration file "${ projectConfigPath }"`});
48
+ logError({ plugin: 'static-website-builder', message: `Couldn't find configuration file "${projectConfigPath}"` });
39
49
  hasProjectConfigFile = false;
40
50
  }
41
51
 
42
52
  if (hasProjectConfigFile) {
43
- projectTaskConfig = itterateConfig(require(projectConfigPath), mergeConfigMode);
53
+ await import(projectConfigPath).then((config) => {
54
+ projectTaskConfig = itterateConfig(config, mergeConfigMode);
55
+ });
44
56
  }
45
57
 
46
58
  // 2. Marge plugins into the config, each plugin is just a config
@@ -64,7 +76,20 @@ function getConfig (builderConfigFile) {
64
76
  }
65
77
 
66
78
  return taskConfig;
67
- };
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
+ }
68
93
 
69
94
  /**
70
95
  * Returns task sub-config by path
@@ -72,7 +97,7 @@ function getConfig (builderConfigFile) {
72
97
  * @param {...string} path Path to the sub-config
73
98
  * @returns {any} Task sub-config
74
99
  */
75
- function getTaskConfig (...path) {
100
+ export function getTaskConfig(...path) {
76
101
  return get(getConfig(), path, null);
77
102
  }
78
103
 
@@ -84,21 +109,43 @@ function getTaskConfig (...path) {
84
109
  * @param {*} fn
85
110
  * @protected
86
111
  */
87
- function itterateConfig (config, fn) {
112
+ function itterateConfig(config, fn) {
88
113
  if (config === false) return false;
89
114
  const base = isPlainObject(config) ? {} : [];
90
115
 
91
- return reduce(config, (object, value, key) => {
92
- if (isPlainObject(value)) {
93
- object[key]= itterateConfig(fn(value), fn);
94
- } else if (isArray(value)) {
95
- object[key]= itterateConfig(value, fn);
96
- } else {
97
- object[key] = value;
98
- }
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
+ }
99
144
 
100
- return object;
101
- }, base);
145
+ return object;
146
+ },
147
+ base,
148
+ );
102
149
  }
103
150
 
104
151
  /**
@@ -109,7 +156,7 @@ function itterateConfig (config, fn) {
109
156
  * @returns {object} Config
110
157
  * @protected
111
158
  */
112
- function mergeConfigMode (config) {
159
+ function mergeConfigMode(config) {
113
160
  if ('production' in config || 'development' in config) {
114
161
  const mode = global.production ? 'production' : 'development';
115
162
  const value = merge(config, config[mode]);
@@ -130,28 +177,28 @@ function mergeConfigMode (config) {
130
177
  * @returns {object} Configuration
131
178
  * @protected
132
179
  */
133
- function loadConfig () {
180
+ async function loadConfig() {
134
181
  const taskFolder = path.resolve(__dirname, '../tasks');
135
182
  let taskConfig = {};
136
183
 
137
- fs.readdirSync(taskFolder).forEach(folderName => {
138
- // Ignore task folders which start with underscore
139
- if (folderName[0] !== '_') {
140
- const configFileName = path.resolve(taskFolder, folderName, 'config.js');
141
-
142
- try {
143
- fs.accessSync(configFileName);
144
- } catch (err) {
145
- return;
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
+ });
146
199
  }
147
-
148
- taskConfig = merge(taskConfig, require(configFileName));
149
- }
150
- });
200
+ }),
201
+ );
151
202
 
152
203
  return taskConfig;
153
- };
154
-
155
-
156
- exports.getConfig = getConfig;
157
- exports.getTaskConfig = getTaskConfig;
204
+ }
@@ -1,5 +1,5 @@
1
- const fs = require('fs');
2
- const path = require('path');
1
+ import fs from 'fs';
2
+ import path from 'path';
3
3
 
4
4
  /**
5
5
  * Returns list of filenames in folder recursively
@@ -8,7 +8,7 @@ const path = require('path');
8
8
  * @param {string} [subFolder=''] Subfolder path
9
9
  * @returns {array} List of filenames, relative to folder
10
10
  */
11
- module.exports = function getFileNamesSync (folder, subFolder = '') {
11
+ export default function getFileNamesSync (folder, subFolder = '') {
12
12
  let fileNames = []
13
13
 
14
14
  fs.readdirSync(folder, { withFileTypes: true }).forEach(file => {
package/lib/get-path.js CHANGED
@@ -1,7 +1,9 @@
1
- const path = require('path');
2
- const { nanomemoize } = require('nano-memoize');
3
- const getConfig = require('./get-config');
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import nanomemoize from 'nano-memoize';
4
+ import { getConfig } from './get-config.js';
4
5
 
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
7
 
6
8
  /**
7
9
  * Returns builder and project specific path configurations merged
@@ -9,8 +11,8 @@ const getConfig = require('./get-config');
9
11
  * @returns {object} Configuration
10
12
  */
11
13
 
12
- const getPathConfig = nanomemoize(function () {
13
- return getConfig.getConfig().paths;
14
+ export const getPathConfig = nanomemoize.nanomemoize(function () {
15
+ return getConfig().paths;
14
16
  });
15
17
 
16
18
  /**
@@ -19,9 +21,9 @@ const getPathConfig = nanomemoize(function () {
19
21
  * @param {...any} paths List of paths
20
22
  * @returns {string} Path
21
23
  */
22
- function getProjectPath (...paths) {
24
+ export function getProjectPath(...paths) {
23
25
  return path.resolve(process.env.INIT_CWD || process.cwd(), ...paths);
24
- };
26
+ }
25
27
 
26
28
  /**
27
29
  * Returns a path relative to the builder folder
@@ -29,9 +31,9 @@ function getProjectPath (...paths) {
29
31
  * @param {...any} paths List of paths
30
32
  * @returns {string} Path
31
33
  */
32
- function getBuilderPath (...paths) {
34
+ export function getBuilderPath(...paths) {
33
35
  return path.resolve(__dirname, '../', ...paths);
34
- };
36
+ }
35
37
 
36
38
  /**
37
39
  * Returns task source path or paths
@@ -40,7 +42,7 @@ function getBuilderPath (...paths) {
40
42
  * @param {...string} paths Additional sub paths
41
43
  * @returns {string|array} Task source path or list of paths
42
44
  */
43
- function getSourcePath (name, ...paths) {
45
+ export function getSourcePath(name, ...paths) {
44
46
  const pathConfig = getPathConfig();
45
47
  const path = pathConfig[name].src;
46
48
 
@@ -60,7 +62,7 @@ function getSourcePath (name, ...paths) {
60
62
  * @param {...string} paths Additional sub paths
61
63
  * @returns {array} Task source paths
62
64
  */
63
- function getSourcePaths (name, ...paths) {
65
+ export function getSourcePaths(name, ...paths) {
64
66
  const path = getSourcePath(name, ...paths);
65
67
 
66
68
  if (typeof path === 'string') {
@@ -77,7 +79,7 @@ function getSourcePaths (name, ...paths) {
77
79
  * @param {...string} paths Additional sub paths
78
80
  * @returns {string} Task destination path
79
81
  */
80
- function getDestPath (name, ...paths) {
82
+ export function getDestPath(name, ...paths) {
81
83
  const pathConfig = getPathConfig();
82
84
 
83
85
  if (name) {
@@ -93,17 +95,8 @@ function getDestPath (name, ...paths) {
93
95
  * @param {string} [name] Task name
94
96
  * @returns {string} Task public path
95
97
  */
96
- function getPublicPath (name) {
98
+ export function getPublicPath(name) {
97
99
  const destFullPath = getDestPath(name);
98
100
  const destPath = getDestPath();
99
101
  return destFullPath.replace(destPath, '') + '/';
100
102
  }
101
-
102
-
103
- exports.getPathConfig = getPathConfig;
104
- exports.getSourcePath = getSourcePath;
105
- exports.getSourcePaths = getSourcePaths;
106
- exports.getDestPath = getDestPath;
107
- exports.getProjectPath = getProjectPath;
108
- exports.getBuilderPath = getBuilderPath;
109
- exports.getPublicPath = getPublicPath;
@@ -1,7 +1,7 @@
1
- const path = require("path");
2
- const flatten = require("lodash/flatten");
3
- const map = require("lodash/map");
4
- const filter = require("lodash/filter");
1
+ import path from 'path';
2
+ import flatten from 'lodash/flatten.js';
3
+ import map from 'lodash/map.js';
4
+ import filter from 'lodash/filter.js';
5
5
 
6
6
  const REGEX_DOT_PREFIX = /^\.+/;
7
7
  const REGEX_WINDOWS_BACKSLASH = /\\/g;
@@ -18,45 +18,31 @@ class GlobObject {
18
18
  }
19
19
 
20
20
  paths(paths) {
21
- const pathsArr = Array.isArray(paths)
22
- ? paths
23
- : typeof paths === "string"
24
- ? [paths]
25
- : [];
21
+ const pathsArr = Array.isArray(paths) ? paths : typeof paths === 'string' ? [paths] : [];
26
22
 
27
23
  if (pathsArr.length) {
28
24
  if (this.pathsArr.length) {
29
25
  this.map((basePath) => {
30
26
  return pathsArr.map((subPath) => {
31
27
  // If subpath starts with specia character "!" then prepend that to the begining of full paths
32
- const negativePath = subPath[0] === "!" ? "!" : "";
33
- const subPathNormalized = negativePath
34
- ? subPath.substr(1)
35
- : subPath;
28
+ const negativePath = subPath[0] === '!' ? '!' : '';
29
+ const subPathNormalized = negativePath ? subPath.substr(1) : subPath;
36
30
 
37
- return (
38
- negativePath +
39
- path.join(basePath, subPathNormalized)
40
- );
31
+ return negativePath + path.join(basePath, subPathNormalized);
41
32
  });
42
33
  });
43
34
 
44
35
  this.mapRaw((basePath) => {
45
36
  return pathsArr.map((subPath) => {
46
37
  // If subpath starts with specia character "!" then prepend that to the begining of full paths
47
- const negativePath = subPath[0] === "!" ? "!" : "";
48
- const subPathNormalized = negativePath
49
- ? subPath.substr(1)
50
- : subPath;
38
+ const negativePath = subPath[0] === '!' ? '!' : '';
39
+ const subPathNormalized = negativePath ? subPath.substr(1) : subPath;
51
40
 
52
41
  if (negativePath) {
53
42
  this.isIgnore = true;
54
43
  }
55
44
 
56
- return (
57
- negativePath +
58
- path.join(basePath, subPathNormalized)
59
- );
45
+ return negativePath + path.join(basePath, subPathNormalized);
60
46
  });
61
47
  });
62
48
  } else {
@@ -77,19 +63,16 @@ class GlobObject {
77
63
  * @returns {object} GlobObject
78
64
  */
79
65
  filesWithExtensions(extensions) {
80
- const extensionsArr =
81
- typeof extensions === "string" ? [extensions] : extensions;
66
+ const extensionsArr = typeof extensions === 'string' ? [extensions] : extensions;
82
67
 
83
68
  if (extensionsArr && extensionsArr.length) {
84
- let extensionString = "";
69
+ let extensionString = '';
85
70
 
86
71
  // Remove dot from the extension name
87
- let extensionsArrNormalized = map(extensionsArr, (extension) =>
88
- extension.replace(REGEX_DOT_PREFIX, ""),
89
- );
72
+ let extensionsArrNormalized = map(extensionsArr, (extension) => extension.replace(REGEX_DOT_PREFIX, ''));
90
73
 
91
74
  if (extensionsArrNormalized.length > 1) {
92
- extensionString = `/**/*.{${extensionsArrNormalized.join(",")}}`;
75
+ extensionString = `/**/*.{${extensionsArrNormalized.join(',')}}`;
93
76
  } else {
94
77
  extensionString = `/**/*.${extensionsArrNormalized}`;
95
78
  }
@@ -129,10 +112,7 @@ class GlobObject {
129
112
  * @returns {object} GlobObject
130
113
  */
131
114
  map(fn) {
132
- this.pathsArr = filter(
133
- flatten(map(this.pathsArr, fn)),
134
- (path) => !!path,
135
- );
115
+ this.pathsArr = filter(flatten(map(this.pathsArr, fn)), (path) => !!path);
136
116
  return this;
137
117
  }
138
118
 
@@ -143,10 +123,7 @@ class GlobObject {
143
123
  * @returns {object} GlobObject
144
124
  */
145
125
  mapRaw(fn) {
146
- this.pathsArrRaw = filter(
147
- flatten(map(this.pathsArrRaw, fn)),
148
- (path) => !!path,
149
- );
126
+ this.pathsArrRaw = filter(flatten(map(this.pathsArrRaw, fn)), (path) => !!path);
150
127
  return this;
151
128
  }
152
129
 
@@ -161,7 +138,7 @@ class GlobObject {
161
138
  return [];
162
139
  } else {
163
140
  return map(this.pathsArr, (path) => {
164
- return path.replace(REGEX_WINDOWS_BACKSLASH, "/");
141
+ return path.replace(REGEX_WINDOWS_BACKSLASH, '/');
165
142
  });
166
143
  }
167
144
  }
@@ -177,7 +154,7 @@ class GlobObject {
177
154
  return [];
178
155
  } else {
179
156
  return map(this.pathsArrRaw, (path) => {
180
- return path.replace(REGEX_WINDOWS_BACKSLASH, "/");
157
+ return path.replace(REGEX_WINDOWS_BACKSLASH, '/');
181
158
  });
182
159
  }
183
160
  }
@@ -189,9 +166,7 @@ class GlobObject {
189
166
  */
190
167
  generate(forChokidar = false) {
191
168
  if (forChokidar) {
192
- const paths = this.toArrayRaw().map((path) =>
193
- this.isAllFiles || this.hasExtensions ? path + "/." : path,
194
- );
169
+ const paths = this.toArrayRaw().map((path) => (this.isAllFiles || this.hasExtensions ? path + '/.' : path));
195
170
 
196
171
  if (this.hadEmptyPaths && this.isIgnore) {
197
172
  return {
@@ -225,7 +200,7 @@ function paths(paths) {
225
200
  }
226
201
 
227
202
  function generate(...globs) {
228
- const isLastArgBoolean = typeof globs[globs.length - 1] === "boolean";
203
+ const isLastArgBoolean = typeof globs[globs.length - 1] === 'boolean';
229
204
  const forChokidar = isLastArgBoolean ? globs.pop() : false;
230
205
 
231
206
  if (forChokidar) {
@@ -262,7 +237,7 @@ function chokidarFilterIgnorePaths(ignorePaths) {
262
237
  };
263
238
  }
264
239
 
265
- module.exports = {
240
+ export default {
266
241
  generate,
267
242
  paths,
268
243
  };
@@ -2,7 +2,7 @@
2
2
  * Similar to parallel() and serial() but instead of getting tasks immediatelly
3
3
  * it's executed after config has been loaded
4
4
  */
5
- module.exports = function dynamicTask (fn) {
5
+ export default function dynamicTask (fn) {
6
6
  fn.dynamicTasks = true;
7
7
  return fn;
8
8
  }
@@ -2,7 +2,7 @@
2
2
  * Similar to parallel() and serial() but instead of getting tasks immediatelly
3
3
  * it's executed after config has been loaded
4
4
  */
5
- module.exports = function resolveDynamicTask (fn) {
5
+ export default function resolveDynamicTask (fn) {
6
6
  if (fn.dynamicTasks) {
7
7
  return fn();
8
8
  } else {
@@ -1,8 +1,8 @@
1
- const plumber = require('gulp-plumber');
1
+ import plumber from 'gulp-plumber';
2
2
 
3
3
  /**
4
4
  * Gulp task pipe function which handles errors
5
5
  */
6
- module.exports = function taskBeforeDest () {
6
+ export default function taskBeforeDest () {
7
7
  return plumber.stop();
8
8
  }
@@ -1,10 +1,10 @@
1
- const gulpif = require('gulp-if');
2
- const getConfig = require('../get-config');
3
- const browserSync = require('browser-sync');
1
+ import gulpif from 'gulp-if';
2
+ import { getTaskConfig } from '../get-config.js';
3
+ import browserSync from 'browser-sync';
4
4
 
5
5
  /**
6
6
  * Gulp task pipe function which handles browsersync reloading
7
7
  */
8
- module.exports = function taskEnd () {
9
- return gulpif(!!getConfig.getTaskConfig('browserSync'), browserSync.stream());
8
+ export default function taskEnd () {
9
+ return gulpif(!!getTaskConfig('browserSync'), browserSync.stream());
10
10
  };
@@ -1,10 +1,10 @@
1
- const plumber = require('gulp-plumber');
2
- const logError = require('../log-error');
1
+ import plumber from 'gulp-plumber';
2
+ import logError from '../log-error.js';
3
3
 
4
4
  /**
5
5
  * Gulp task pipe function which handles errors
6
6
  */
7
- module.exports = function taskStart () {
7
+ export default function taskStart () {
8
8
  return plumber(function (error) {
9
9
  // Fail whole gulp process if in production mode
10
10
  logError.call(this, error, global.production);
@@ -1,14 +1,14 @@
1
- const { parallel } = require("gulp");
2
- const chokidar = require("chokidar");
3
- const debounce = require("lodash/debounce");
4
- const asyncDone = require("async-done");
1
+ import { parallel } from 'gulp';
2
+ import chokidar from 'chokidar';
3
+ import debounce from 'lodash/debounce.js';
4
+ import asyncDone from 'async-done';
5
5
 
6
6
  /**
7
7
  * Gulp task watch function using latest chokidar
8
8
  * with better OSX support and file watching functionality
9
9
  * than outdated gulp.watch
10
10
  */
11
- module.exports = function taskWatch(globs, callback, isParallel = false) {
11
+ export default function taskWatch(globs, callback, isParallel = false) {
12
12
  const parallelCallback = isParallel ? callback : parallel(callback);
13
13
  const debouncedCallback = debounce(onChange, 120);
14
14
  let running = false;
@@ -41,26 +41,26 @@ module.exports = function taskWatch(globs, callback, isParallel = false) {
41
41
  }
42
42
 
43
43
  if (!globs.paths) {
44
- throw new Error("No paths provided for chokidar watch");
44
+ throw new Error('No paths provided for chokidar watch');
45
45
  }
46
46
 
47
47
  return chokidar
48
48
  .watch(globs.paths, {
49
49
  ignoreInitial: true,
50
50
  })
51
- .on("add", (path) => {
51
+ .on('add', (path) => {
52
52
  if (!isIgnoredPath(path)) {
53
53
  debouncedCallback(path);
54
54
  }
55
55
  })
56
- .on("change", (path) => {
56
+ .on('change', (path) => {
57
57
  if (!isIgnoredPath(path)) {
58
58
  debouncedCallback(path);
59
59
  }
60
60
  })
61
- .on("unlink", (path) => {
61
+ .on('unlink', (path) => {
62
62
  if (!isIgnoredPath(path)) {
63
63
  debouncedCallback(path);
64
64
  }
65
65
  });
66
- };
66
+ }
@@ -1,6 +1,6 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const fsPromise = require('fs').promises;
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import fsPromise from 'fs/promises';
4
4
 
5
5
 
6
6
  function copyFile(from, to, file) {
@@ -47,4 +47,4 @@ function copyFolder(from, to) {
47
47
  }
48
48
 
49
49
 
50
- module.exports = copyFolder;
50
+ export default copyFolder;
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
1
+ import fs from 'fs';
2
2
 
3
- module.exports = function folderExists (folder) {
3
+ export default function folderExists (folder) {
4
4
  try {
5
5
  const stat = fs.lstatSync(folder);
6
6
  return stat.isDirectory();
@@ -1,7 +1,7 @@
1
- const path = require('path');
2
- const fsPromise = require('fs').promises;
1
+ import path from 'path';
2
+ import fsPromise from 'fs/promises';
3
3
 
4
- module.exports = function getFolderList (folder) {
4
+ export default function getFolderList (folder) {
5
5
  return fsPromise.readdir(folder).then((files) => {
6
6
  return Promise.all(files.map((file) => {
7
7
  return fsPromise.lstat(path.join(folder, file)).then((stats) => {
@@ -1,14 +1,14 @@
1
- const readPackage = require('./read-package');
2
- const fsPromise = require('fs').promises;
3
- const merge = require('../merge');
4
- const isEqual = require('lodash/isEqual');
1
+ import readPackage from './read-package.js';
2
+ import merge from '../merge.js';
3
+ import fsPromise from 'fs/promises';
4
+ import isEqual from 'lodash/isEqual.js';
5
5
 
6
- module.exports = function mergePackage (fileName, content) {
7
- return readPackage(fileName).then((package) => {
8
- const newPackage = merge({}, package, content);
6
+ export default function mergePackage (fileName, content) {
7
+ return readPackage(fileName).then((packageContent) => {
8
+ const newPackage = merge({}, packageContent, content);
9
9
 
10
10
  // Write only if file has changed
11
- if (!isEqual(package, newPackage)) {
11
+ if (!isEqual(packageContent, newPackage)) {
12
12
  return fsPromise.writeFile(fileName, JSON.stringify(newPackage, null, ' '));
13
13
  } else {
14
14
  return Promise.resolve();