@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,47 +1,47 @@
1
- import gulp from 'gulp';
2
- import nanomemoize from 'nano-memoize';
3
-
4
- import globs from './../../lib/globs-helper.js';
5
- import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
6
- import { getTaskConfig } from './../../lib/get-config.js';
7
-
8
- import taskStart from '../../lib/gulp/task-start.js';
9
- import taskEnd from '../../lib/gulp/task-end.js';
10
- import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
11
- import taskWatch from '../../lib/gulp/task-watch.js';
12
-
13
- const getWatchGlobPaths = function (forChokidar = false) {
14
- const sourcePaths = getSourcePaths('fonts');
15
- const extensions = getTaskConfig('fonts', 'extensions');
16
- const ignore = getTaskConfig('fonts', 'ignore');
17
-
18
- return globs.generate(
19
- globs.paths(sourcePaths).filesWithExtensions(extensions), // Files to watch
20
- globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
21
- forChokidar,
22
- );
23
- };
24
- const getGlobPaths = nanomemoize.nanomemoize(function () {
25
- return getWatchGlobPaths(false);
26
- });
27
-
28
- function fonts() {
29
- return (
30
- gulp
31
- .src(getGlobPaths(), { since: gulp.lastRun(fonts) })
32
- .pipe(taskStart())
33
-
34
- .pipe(taskBeforeDest())
35
- .pipe(gulp.dest(getDestPath('fonts')))
36
-
37
- // Reload on change
38
- .pipe(taskEnd())
39
- );
40
- }
41
-
42
- function fontsWatch() {
43
- return taskWatch(getWatchGlobPaths(true), fonts);
44
- }
45
-
46
- export const build = fonts;
47
- export const watch = fontsWatch;
1
+ import gulp from 'gulp';
2
+ import nanomemoize from 'nano-memoize';
3
+
4
+ import globs from './../../lib/globs-helper.js';
5
+ import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
6
+ import { getTaskConfig } from './../../lib/get-config.js';
7
+
8
+ import taskStart from '../../lib/gulp/task-start.js';
9
+ import taskEnd from '../../lib/gulp/task-end.js';
10
+ import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
11
+ import taskWatch from '../../lib/gulp/task-watch.js';
12
+
13
+ const getWatchGlobPaths = function (forChokidar = false) {
14
+ const sourcePaths = getSourcePaths('fonts');
15
+ const extensions = getTaskConfig('fonts', 'extensions');
16
+ const ignore = getTaskConfig('fonts', 'ignore');
17
+
18
+ return globs.generate(
19
+ globs.paths(sourcePaths).filesWithExtensions(extensions), // Files to watch
20
+ globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
21
+ forChokidar,
22
+ );
23
+ };
24
+ const getGlobPaths = nanomemoize.nanomemoize(function () {
25
+ return getWatchGlobPaths(false);
26
+ });
27
+
28
+ function fonts() {
29
+ return (
30
+ gulp
31
+ .src(getGlobPaths(), { since: gulp.lastRun(fonts) })
32
+ .pipe(taskStart())
33
+
34
+ .pipe(taskBeforeDest())
35
+ .pipe(gulp.dest(getDestPath('fonts')))
36
+
37
+ // Reload on change
38
+ .pipe(taskEnd())
39
+ );
40
+ }
41
+
42
+ function fontsWatch() {
43
+ return taskWatch(getWatchGlobPaths(true), fonts);
44
+ }
45
+
46
+ export const build = fonts;
47
+ export const watch = fontsWatch;
@@ -1,7 +1,7 @@
1
- /**
2
- * Paths relative to the project path from where `npm run ...` command is run
3
- */
4
- export const paths = {
5
- src: './src',
6
- dest: './public',
7
- };
1
+ /**
2
+ * Paths relative to the project path from where `npm run ...` command is run
3
+ */
4
+ export const paths = {
5
+ src: './src',
6
+ dest: './public',
7
+ };
@@ -1,42 +1,42 @@
1
- import * as htmlTask from './task.js';
2
-
3
- export const html = {
4
- // Engine is a function which returns a gulp pipe function, eg. sass()
5
- // Intended to be used by plugins, not manually
6
- engine: null,
7
-
8
- // Filename extensions
9
- extensions: ['html'],
10
-
11
- // Glob list of files, which to ignore, relative to the html source folder
12
- // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
13
- ignore: [],
14
-
15
- // Production only settings, overwrites default settings
16
- production: {
17
- // Enable HTML minification
18
- htmlmin: {
19
- collapseWhitespace: true,
20
- },
21
- },
22
-
23
- // Development only settings, overwrites default settings
24
- development: {
25
- // Disable HTML minification
26
- htmlmin: false,
27
- },
28
- };
29
-
30
- export const tasks = {
31
- html: [htmlTask],
32
- };
33
-
34
- /**
35
- * Paths relative to the global src and dest folders
36
- */
37
- export const paths = {
38
- html: {
39
- src: 'html',
40
- dest: '',
41
- },
42
- };
1
+ import * as htmlTask from './task.js';
2
+
3
+ export const html = {
4
+ // Engine is a function which returns a gulp pipe function, eg. sass()
5
+ // Intended to be used by plugins, not manually
6
+ engine: null,
7
+
8
+ // Filename extensions
9
+ extensions: ['html'],
10
+
11
+ // Glob list of files, which to ignore, relative to the html source folder
12
+ // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
13
+ ignore: [],
14
+
15
+ // Production only settings, overwrites default settings
16
+ production: {
17
+ // Enable HTML minification
18
+ htmlmin: {
19
+ collapseWhitespace: true,
20
+ },
21
+ },
22
+
23
+ // Development only settings, overwrites default settings
24
+ development: {
25
+ // Disable HTML minification
26
+ htmlmin: false,
27
+ },
28
+ };
29
+
30
+ export const tasks = {
31
+ html: [htmlTask],
32
+ };
33
+
34
+ /**
35
+ * Paths relative to the global src and dest folders
36
+ */
37
+ export const paths = {
38
+ html: {
39
+ src: 'html',
40
+ dest: '',
41
+ },
42
+ };
@@ -1,91 +1,91 @@
1
- import gulp from 'gulp';
2
- import data from 'gulp-data';
3
- import gulpif from 'gulp-if';
4
- import htmlmin from 'gulp-htmlmin';
5
- import nanomemoize from 'nano-memoize';
6
- import cached from 'gulp-cached';
7
- import dependents from 'gulp-dependents';
8
- import ignore from 'gulp-ignore';
9
-
10
- import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
11
- import { getTaskConfig } from './../../lib/get-config.js';
12
- import globs from './../../lib/globs-helper.js';
13
-
14
- import taskStart from '../../lib/gulp/task-start.js';
15
- import taskEnd from '../../lib/gulp/task-end.js';
16
- import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
17
- import taskWatch from '../../lib/gulp/task-watch.js';
18
-
19
- import getData from '../data/get-data.js';
20
-
21
- const getGlobPaths = nanomemoize.nanomemoize(function () {
22
- const sourcePaths = getSourcePaths('html');
23
- const extensions = getTaskConfig('html', 'extensions');
24
-
25
- return globs.generate([
26
- globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
27
- ]);
28
- });
29
-
30
- const getGlobIgnorePaths = nanomemoize.nanomemoize(function () {
31
- const ignore = getTaskConfig('html', 'ignore');
32
-
33
- return globs.generate([
34
- globs.paths(ignore), // Exclude files and folders from being rendered
35
- ]);
36
- });
37
-
38
- const getWatchGlobPaths = function () {
39
- const sourcePaths = getSourcePaths('html');
40
- const extensions = getTaskConfig('html', 'extensions'); // HTML / TWIG files
41
- const dataExtensions = getTaskConfig('data', 'extensions'); // Data files
42
-
43
- return globs.generate(
44
- globs.paths(sourcePaths).filesWithExtensions(extensions.concat(dataExtensions)),
45
- true, // for chokidar
46
- );
47
- };
48
-
49
- const getEngine = function () {
50
- const engine = getTaskConfig('html', 'engine');
51
- return engine ? engine() : () => {};
52
- };
53
-
54
- function html(options) {
55
- const build = options && !!options.build;
56
-
57
- return function html() {
58
- return (
59
- gulp
60
- .src(getGlobPaths())
61
- .pipe(taskStart())
62
-
63
- // Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
64
- .pipe(gulpif(!!getTaskConfig('html', 'dependents'), cached('html')))
65
- .pipe(gulpif(!!getTaskConfig('html', 'dependents'), dependents(getTaskConfig('dependents'))))
66
-
67
- // Prevent file from being rendered if it's in the ignore list
68
- .pipe(ignore.exclude(getGlobIgnorePaths(), {}))
69
-
70
- // Preprocess using TWIG
71
- .pipe(gulpif(!!getTaskConfig('html', 'engine'), data(getData({ build: build }))))
72
- .pipe(gulpif(!!getTaskConfig('html', 'engine'), getEngine()))
73
-
74
- // Minify
75
- .pipe(gulpif(!!getTaskConfig('html', 'htmlmin'), htmlmin(getTaskConfig('html', 'htmlmin'))))
76
-
77
- .pipe(taskBeforeDest())
78
- .pipe(gulp.dest(getDestPath('html')))
79
-
80
- // Reload on change
81
- .pipe(taskEnd())
82
- );
83
- };
84
- }
85
-
86
- function htmlWatch() {
87
- return taskWatch(getWatchGlobPaths(), html({ build: false }));
88
- }
89
-
90
- export const build = html({ build: true });
91
- export const watch = htmlWatch;
1
+ import gulp from 'gulp';
2
+ import data from 'gulp-data';
3
+ import gulpif from 'gulp-if';
4
+ import htmlmin from 'gulp-htmlmin';
5
+ import nanomemoize from 'nano-memoize';
6
+ import cached from 'gulp-cached';
7
+ import dependents from 'gulp-dependents';
8
+ import ignore from 'gulp-ignore';
9
+
10
+ import { getSourcePaths, getDestPath } from './../../lib/get-path.js';
11
+ import { getTaskConfig } from './../../lib/get-config.js';
12
+ import globs from './../../lib/globs-helper.js';
13
+
14
+ import taskStart from '../../lib/gulp/task-start.js';
15
+ import taskEnd from '../../lib/gulp/task-end.js';
16
+ import taskBeforeDest from '../../lib/gulp/task-before-dest.js';
17
+ import taskWatch from '../../lib/gulp/task-watch.js';
18
+
19
+ import getData from '../data/get-data.js';
20
+
21
+ const getGlobPaths = nanomemoize.nanomemoize(function () {
22
+ const sourcePaths = getSourcePaths('html');
23
+ const extensions = getTaskConfig('html', 'extensions');
24
+
25
+ return globs.generate([
26
+ globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
27
+ ]);
28
+ });
29
+
30
+ const getGlobIgnorePaths = nanomemoize.nanomemoize(function () {
31
+ const ignore = getTaskConfig('html', 'ignore');
32
+
33
+ return globs.generate([
34
+ globs.paths(ignore), // Exclude files and folders from being rendered
35
+ ]);
36
+ });
37
+
38
+ const getWatchGlobPaths = function () {
39
+ const sourcePaths = getSourcePaths('html');
40
+ const extensions = getTaskConfig('html', 'extensions'); // HTML / TWIG files
41
+ const dataExtensions = getTaskConfig('data', 'extensions'); // Data files
42
+
43
+ return globs.generate(
44
+ globs.paths(sourcePaths).filesWithExtensions(extensions.concat(dataExtensions)),
45
+ true, // for chokidar
46
+ );
47
+ };
48
+
49
+ const getEngine = function () {
50
+ const engine = getTaskConfig('html', 'engine');
51
+ return engine ? engine() : () => {};
52
+ };
53
+
54
+ function html(options) {
55
+ const build = options && !!options.build;
56
+
57
+ return function html() {
58
+ return (
59
+ gulp
60
+ .src(getGlobPaths())
61
+ .pipe(taskStart())
62
+
63
+ // Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
64
+ .pipe(gulpif(!build && !!getTaskConfig('html', 'dependents'), cached('html')))
65
+ .pipe(gulpif(!build && !!getTaskConfig('html', 'dependents'), dependents(getTaskConfig('dependents'))))
66
+
67
+ // Prevent file from being rendered if it's in the ignore list
68
+ .pipe(ignore.exclude(getGlobIgnorePaths(), {}))
69
+
70
+ // Preprocess using TWIG
71
+ .pipe(gulpif(!!getTaskConfig('html', 'engine'), data(getData({ build: build }))))
72
+ .pipe(gulpif(!!getTaskConfig('html', 'engine'), getEngine()))
73
+
74
+ // Minify
75
+ .pipe(gulpif(!!getTaskConfig('html', 'htmlmin'), htmlmin(getTaskConfig('html', 'htmlmin'))))
76
+
77
+ .pipe(taskBeforeDest())
78
+ .pipe(gulp.dest(getDestPath('html')))
79
+
80
+ // Reload on change
81
+ .pipe(taskEnd())
82
+ );
83
+ };
84
+ }
85
+
86
+ function htmlWatch() {
87
+ return taskWatch(getWatchGlobPaths(), html({ build: false }));
88
+ }
89
+
90
+ export const build = html({ build: true });
91
+ export const watch = htmlWatch;
@@ -1,47 +1,47 @@
1
- import * as preprocessIconConfig from './preprocess-config.js';
2
- import * as iconTask from './task.js';
3
-
4
- export const icons = {
5
- // Glob list of files, which to ignore, relative to the icon source folder
6
- // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
7
- ignore: [],
8
-
9
- // Filename extensions
10
- extensions: ['svg'],
11
-
12
- // SVG store configuration
13
- // see https://github.com/w0rm/gulp-svgstore
14
- svgstore: {},
15
-
16
- // SVG min configuration
17
- // see https://github.com/ben-eb/gulp-svgmin#plugins
18
- svgmin: [
19
- {
20
- removeUnknownsAndDefaults: false,
21
- },
22
- ],
23
-
24
- // Production only settings, overwrites default settings
25
- production: {},
26
-
27
- // Development only settings, overwrites default settings
28
- development: {},
29
- };
30
-
31
- export const preprocess = {
32
- icons: [preprocessIconConfig],
33
- };
34
-
35
- export const tasks = {
36
- icons: [iconTask],
37
- };
38
-
39
- /**
40
- * Paths relative to the global src and dest folders
41
- */
42
- export const paths = {
43
- icons: {
44
- src: 'icons',
45
- dest: 'assets/images',
46
- },
47
- };
1
+ import * as preprocessIconConfig from './preprocess-config.js';
2
+ import * as iconTask from './task.js';
3
+
4
+ export const icons = {
5
+ // Glob list of files, which to ignore, relative to the icon source folder
6
+ // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
7
+ ignore: [],
8
+
9
+ // Filename extensions
10
+ extensions: ['svg'],
11
+
12
+ // SVG store configuration
13
+ // see https://github.com/w0rm/gulp-svgstore
14
+ svgstore: {},
15
+
16
+ // SVG min configuration
17
+ // see https://github.com/ben-eb/gulp-svgmin#plugins
18
+ svgmin: [
19
+ {
20
+ removeUnknownsAndDefaults: false,
21
+ },
22
+ ],
23
+
24
+ // Production only settings, overwrites default settings
25
+ production: {},
26
+
27
+ // Development only settings, overwrites default settings
28
+ development: {},
29
+ };
30
+
31
+ export const preprocess = {
32
+ icons: [preprocessIconConfig],
33
+ };
34
+
35
+ export const tasks = {
36
+ icons: [iconTask],
37
+ };
38
+
39
+ /**
40
+ * Paths relative to the global src and dest folders
41
+ */
42
+ export const paths = {
43
+ icons: {
44
+ src: 'icons',
45
+ dest: 'assets/images',
46
+ },
47
+ };
@@ -1,60 +1,60 @@
1
- import path from 'path';
2
- import isPlainObject from 'lodash/isPlainObject.js';
3
- import reduce from 'lodash/reduce.js';
4
-
5
-
6
- /**
7
- * Convert svgmin object configuration into array of objects
8
- *
9
- * @param {object} config Configuration
10
- * @returns {array} Configuration
11
- */
12
- function convertSVGMINObjectConfigIntoArray (config) {
13
- reduce(config, (config, value, key) => {
14
- const obj = {};
15
- obj[key] = value;
16
- return config;
17
- }, []);
18
- }
19
-
20
- /**
21
- * Modify configuration
22
- *
23
- * @param {object} config Icons configuration
24
- * @param {object} fullConfig Full configuration
25
- * @returns {object} Transformed icons configuration
26
- */
27
- export default function preprocessIconsConfig (config, fullConfig) {
28
- // Disable whole task if SVG store is disabled
29
- if (!config.svgstore) {
30
- return false;
31
- }
32
-
33
- // Normalize svgmin config
34
- if (config && config.svgmin) {
35
- let svgmin = config._svgmin = config.svgmin;
36
-
37
- if (isPlainObject(svgmin)) {
38
- // Convert {a:true,b:false} into [{a:true},{b:false}]
39
- svgmin = config._svgmin = convertSVGMINObjectConfigIntoArray(svgmin);
40
- } else if (!Array.isArray(svgmin)) {
41
- svgmin = config._svgmin = [];
42
- }
43
-
44
- // Use function to output svgmin configuration
45
- // Add ID attribute transformation
46
- config.svgmin = function getSVGMinOptions (file) {
47
- var prefix = path.basename(file.relative, path.extname(file.relative));
48
- return {
49
- plugins: [{
50
- cleanupIDs: {
51
- prefix: prefix + '-',
52
- minify: true
53
- }
54
- }].concat(svgmin)
55
- }
56
- };
57
- }
58
-
59
- return config;
60
- }
1
+ import path from 'path';
2
+ import isPlainObject from 'lodash/isPlainObject.js';
3
+ import reduce from 'lodash/reduce.js';
4
+
5
+
6
+ /**
7
+ * Convert svgmin object configuration into array of objects
8
+ *
9
+ * @param {object} config Configuration
10
+ * @returns {array} Configuration
11
+ */
12
+ function convertSVGMINObjectConfigIntoArray (config) {
13
+ reduce(config, (config, value, key) => {
14
+ const obj = {};
15
+ obj[key] = value;
16
+ return config;
17
+ }, []);
18
+ }
19
+
20
+ /**
21
+ * Modify configuration
22
+ *
23
+ * @param {object} config Icons configuration
24
+ * @param {object} fullConfig Full configuration
25
+ * @returns {object} Transformed icons configuration
26
+ */
27
+ export default function preprocessIconsConfig (config, fullConfig) {
28
+ // Disable whole task if SVG store is disabled
29
+ if (!config.svgstore) {
30
+ return false;
31
+ }
32
+
33
+ // Normalize svgmin config
34
+ if (config && config.svgmin) {
35
+ let svgmin = config._svgmin = config.svgmin;
36
+
37
+ if (isPlainObject(svgmin)) {
38
+ // Convert {a:true,b:false} into [{a:true},{b:false}]
39
+ svgmin = config._svgmin = convertSVGMINObjectConfigIntoArray(svgmin);
40
+ } else if (!Array.isArray(svgmin)) {
41
+ svgmin = config._svgmin = [];
42
+ }
43
+
44
+ // Use function to output svgmin configuration
45
+ // Add ID attribute transformation
46
+ config.svgmin = function getSVGMinOptions (file) {
47
+ var prefix = path.basename(file.relative, path.extname(file.relative));
48
+ return {
49
+ plugins: [{
50
+ cleanupIDs: {
51
+ prefix: prefix + '-',
52
+ minify: true
53
+ }
54
+ }].concat(svgmin)
55
+ }
56
+ };
57
+ }
58
+
59
+ return config;
60
+ }