@videinfra/static-website-builder 1.10.1 → 1.11.0

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 (38) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/init/index.js +56 -56
  3. package/init/test/config/config.js +36 -36
  4. package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
  5. package/init/test/src/stylesheets/ignore-test.scss +4 -4
  6. package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
  7. package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
  8. package/lib/camelize-file-name.js +21 -21
  9. package/lib/get-config.js +157 -157
  10. package/lib/get-file-names.js +23 -23
  11. package/lib/get-path.js +109 -109
  12. package/lib/globs-helper.js +136 -136
  13. package/lib/log-error.js +15 -15
  14. package/lib/merge.js +27 -27
  15. package/package.json +2 -2
  16. package/plugins/sass-engine/preprocess-config.js +54 -54
  17. package/plugins/sass.js +38 -38
  18. package/plugins/twig-engine/preprocess-config.js +47 -47
  19. package/plugins/twig.js +65 -65
  20. package/tasks/data/data-loader-js.js +5 -5
  21. package/tasks/data/get-data.js +87 -87
  22. package/tasks/html/task.js +91 -91
  23. package/tasks/icons/config.js +52 -52
  24. package/tasks/javascripts/preprocess-config.js +42 -4
  25. package/tasks/javascripts/task.js +1 -1
  26. package/tasks/stylesheets/config.js +88 -88
  27. package/tasks/stylesheets/preprocess-config.js +41 -41
  28. package/tasks/stylesheets/task.js +69 -69
  29. package/tests/build/build.test.js +101 -101
  30. package/tests/camelize-file-name.test.js +11 -11
  31. package/tests/glob-helper.test.js +99 -99
  32. package/vendor/gulp-twig/LICENSE +20 -20
  33. package/vendor/gulp-twig/README.md +167 -167
  34. package/vendor/gulp-twig/index.js +130 -130
  35. package/vendor/gulp-twig/package.json +43 -43
  36. package/vendor/webpack-stream/index.js +261 -0
  37. package/vendor/webpack-stream/package.json +91 -0
  38. package/vendor/webpack-stream/readme.md +239 -0
@@ -1,91 +1,91 @@
1
- const gulp = require('gulp');
2
- const data = require('gulp-data');
3
- const gulpif = require('gulp-if');
4
- const htmlmin = require('gulp-htmlmin')
5
- const memoize = require('nano-memoize');
6
- const cached = require('gulp-cached');
7
- const dependents = require('gulp-dependents');
8
- const ignore = require('gulp-ignore');
9
-
10
- const getPaths = require('./../../lib/get-path');
11
- const getConfig = require('./../../lib/get-config');
12
- const globs = require('./../../lib/globs-helper');
13
-
14
- const taskStart = require('../../lib/gulp/task-start');
15
- const taskEnd = require('../../lib/gulp/task-end');
16
- const taskBeforeDest = require('../../lib/gulp/task-before-dest');
17
- const taskWatch = require('../../lib/gulp/task-watch');
18
-
19
- const getData = require('../data/get-data');
20
-
21
-
22
- const getGlobPaths = memoize(function () {
23
- const sourcePaths = getPaths.getSourcePaths('html');
24
- const extensions = getConfig.getTaskConfig('html', 'extensions');
25
-
26
- return globs.generate([
27
- globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
28
- ]);
29
- });
30
-
31
- const getGlobIgnorePaths = memoize(function () {
32
- const ignore = getConfig.getTaskConfig('html', 'ignore');
33
-
34
- return globs.generate([
35
- globs.paths(ignore), // Exclude files and folders from being rendered
36
- ]);
37
- });
38
-
39
- const getWatchGlobPaths = memoize(function () {
40
- const sourcePaths = getPaths.getSourcePaths('html');
41
- const extensions = getConfig.getTaskConfig('html', 'extensions');
42
- const dataExtensions = getConfig.getTaskConfig('data', 'extensions');
43
-
44
- return globs.generate(
45
- globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
46
- globs.paths(sourcePaths).filesWithExtensions(dataExtensions) // Data files
47
- );
48
- });
49
-
50
-
51
- const getEngine = memoize(function () {
52
- const engine = getConfig.getTaskConfig('html', 'engine');
53
- return engine ? engine() : (() => {});
54
- });
55
-
56
- function html (options) {
57
- const build = options && !!options.build;
58
-
59
- return function html () {
60
- return gulp.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(!!getConfig.getTaskConfig('html', 'dependents'), cached('html')))
65
- .pipe(gulpif(!!getConfig.getTaskConfig('html', 'dependents'), dependents(getConfig.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(!!getConfig.getTaskConfig('html', 'engine'), data(getData({ build: build }))))
72
- .pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), getEngine()))
73
-
74
- // Minify
75
- .pipe(gulpif(!!getConfig.getTaskConfig('html', 'htmlmin'), htmlmin(getConfig.getTaskConfig('html', 'htmlmin'))))
76
-
77
- .pipe(taskBeforeDest())
78
- .pipe(gulp.dest(getPaths.getDestPath('html')))
79
-
80
- // Reload on change
81
- .pipe(taskEnd());
82
- };
83
- }
84
-
85
- function htmlWatch () {
86
- return taskWatch(getWatchGlobPaths(), html({ build: false }));
87
- }
88
-
89
-
90
- exports.build = html({ build: true });
91
- exports.watch = htmlWatch;
1
+ const gulp = require('gulp');
2
+ const data = require('gulp-data');
3
+ const gulpif = require('gulp-if');
4
+ const htmlmin = require('gulp-htmlmin')
5
+ const memoize = require('nano-memoize');
6
+ const cached = require('gulp-cached');
7
+ const dependents = require('gulp-dependents');
8
+ const ignore = require('gulp-ignore');
9
+
10
+ const getPaths = require('./../../lib/get-path');
11
+ const getConfig = require('./../../lib/get-config');
12
+ const globs = require('./../../lib/globs-helper');
13
+
14
+ const taskStart = require('../../lib/gulp/task-start');
15
+ const taskEnd = require('../../lib/gulp/task-end');
16
+ const taskBeforeDest = require('../../lib/gulp/task-before-dest');
17
+ const taskWatch = require('../../lib/gulp/task-watch');
18
+
19
+ const getData = require('../data/get-data');
20
+
21
+
22
+ const getGlobPaths = memoize(function () {
23
+ const sourcePaths = getPaths.getSourcePaths('html');
24
+ const extensions = getConfig.getTaskConfig('html', 'extensions');
25
+
26
+ return globs.generate([
27
+ globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
28
+ ]);
29
+ });
30
+
31
+ const getGlobIgnorePaths = memoize(function () {
32
+ const ignore = getConfig.getTaskConfig('html', 'ignore');
33
+
34
+ return globs.generate([
35
+ globs.paths(ignore), // Exclude files and folders from being rendered
36
+ ]);
37
+ });
38
+
39
+ const getWatchGlobPaths = memoize(function () {
40
+ const sourcePaths = getPaths.getSourcePaths('html');
41
+ const extensions = getConfig.getTaskConfig('html', 'extensions');
42
+ const dataExtensions = getConfig.getTaskConfig('data', 'extensions');
43
+
44
+ return globs.generate(
45
+ globs.paths(sourcePaths).filesWithExtensions(extensions), // HTML / TWIG files
46
+ globs.paths(sourcePaths).filesWithExtensions(dataExtensions) // Data files
47
+ );
48
+ });
49
+
50
+
51
+ const getEngine = memoize(function () {
52
+ const engine = getConfig.getTaskConfig('html', 'engine');
53
+ return engine ? engine() : (() => {});
54
+ });
55
+
56
+ function html (options) {
57
+ const build = options && !!options.build;
58
+
59
+ return function html () {
60
+ return gulp.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(!!getConfig.getTaskConfig('html', 'dependents'), cached('html')))
65
+ .pipe(gulpif(!!getConfig.getTaskConfig('html', 'dependents'), dependents(getConfig.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(!!getConfig.getTaskConfig('html', 'engine'), data(getData({ build: build }))))
72
+ .pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), getEngine()))
73
+
74
+ // Minify
75
+ .pipe(gulpif(!!getConfig.getTaskConfig('html', 'htmlmin'), htmlmin(getConfig.getTaskConfig('html', 'htmlmin'))))
76
+
77
+ .pipe(taskBeforeDest())
78
+ .pipe(gulp.dest(getPaths.getDestPath('html')))
79
+
80
+ // Reload on change
81
+ .pipe(taskEnd());
82
+ };
83
+ }
84
+
85
+ function htmlWatch () {
86
+ return taskWatch(getWatchGlobPaths(), html({ build: false }));
87
+ }
88
+
89
+
90
+ exports.build = html({ build: true });
91
+ exports.watch = htmlWatch;
@@ -1,52 +1,52 @@
1
- exports.icons = {
2
- // Glob list of files, which to ignore, relative to the icon source folder
3
- // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
4
- ignore: [],
5
-
6
- // Filename extensions
7
- extensions: ['svg'],
8
-
9
- // SVG store configuration
10
- // see https://github.com/w0rm/gulp-svgstore
11
- svgstore: {
12
- },
13
-
14
- // SVG min configuration
15
- // see https://github.com/ben-eb/gulp-svgmin#plugins
16
- svgmin: [
17
- {
18
- removeUnknownsAndDefaults: false
19
- }
20
- ],
21
-
22
- // Production only settings, overwrites default settings
23
- production: {
24
- },
25
-
26
- // Development only settings, overwrites default settings
27
- development: {
28
- },
29
- };
30
-
31
- exports.preprocess = {
32
- icons: [
33
- require('./preprocess-config'),
34
- ]
35
- };
36
-
37
- exports.tasks = {
38
- icons: [
39
- require('./task'),
40
- ]
41
- };
42
-
43
-
44
- /**
45
- * Paths relative to the global src and dest folders
46
- */
47
- exports.paths = {
48
- icons: {
49
- 'src': 'icons',
50
- 'dest': 'assets/images',
51
- }
52
- };
1
+ exports.icons = {
2
+ // Glob list of files, which to ignore, relative to the icon source folder
3
+ // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
4
+ ignore: [],
5
+
6
+ // Filename extensions
7
+ extensions: ['svg'],
8
+
9
+ // SVG store configuration
10
+ // see https://github.com/w0rm/gulp-svgstore
11
+ svgstore: {
12
+ },
13
+
14
+ // SVG min configuration
15
+ // see https://github.com/ben-eb/gulp-svgmin#plugins
16
+ svgmin: [
17
+ {
18
+ removeUnknownsAndDefaults: false
19
+ }
20
+ ],
21
+
22
+ // Production only settings, overwrites default settings
23
+ production: {
24
+ },
25
+
26
+ // Development only settings, overwrites default settings
27
+ development: {
28
+ },
29
+ };
30
+
31
+ exports.preprocess = {
32
+ icons: [
33
+ require('./preprocess-config'),
34
+ ]
35
+ };
36
+
37
+ exports.tasks = {
38
+ icons: [
39
+ require('./task'),
40
+ ]
41
+ };
42
+
43
+
44
+ /**
45
+ * Paths relative to the global src and dest folders
46
+ */
47
+ exports.paths = {
48
+ icons: {
49
+ 'src': 'icons',
50
+ 'dest': 'assets/images',
51
+ }
52
+ };
@@ -3,6 +3,17 @@ const merge = require('../../lib/merge');
3
3
  const get = require('lodash/get');
4
4
  const map = require('lodash/map');
5
5
  const webpack = require('webpack');
6
+ const WatchExternalFilesPlugin = require('webpack-watch-files-plugin');
7
+
8
+ /**
9
+ * Require file without caching it
10
+ * @param {string} module Module path
11
+ * @returns {any} Module
12
+ */
13
+ function requireUncached(module) {
14
+ delete require.cache[require.resolve(module)];
15
+ return require(module);
16
+ }
6
17
 
7
18
  /**
8
19
  * Returns JS entry files
@@ -13,10 +24,31 @@ const webpack = require('webpack');
13
24
  function getEntry (config) {
14
25
  const entryFile = paths.getSourcePath('javascripts', config.entryList);
15
26
 
16
- // Dynamic imports only for webpack 5
17
- // return () => require(entryFile);
27
+ // console.log(require(entryFile));
28
+ // return () => {
29
+ // return new Promise((resolve) => {
30
+ // resolve(require(entryFile));
31
+ // });
32
+ // };
18
33
 
19
- return require(entryFile);
34
+ // return () => new Promise((resolve) => {
35
+ // resolve(['./demo', './demo2'])
36
+ // });
37
+
38
+ return function getEntries () {
39
+ // const entryURL = pathToFileURL(entryFile).href + '?_invalidate-cache=' + (++entriesCounter);
40
+
41
+ // console.log(require.cache.);
42
+ // console.log('loading entries:', entryURL);
43
+ // return import(entryURL).then((entries) => {
44
+ // console.log('loaded entries:', entries.default);
45
+ // return entries.default;
46
+ // });
47
+
48
+ const entries = requireUncached(entryFile);
49
+ console.log('entries:', entries);
50
+ return entries;
51
+ }
20
52
  }
21
53
 
22
54
  /**
@@ -51,7 +83,13 @@ module.exports = function preprocessJavascriptsConfig (config, fullConfig) {
51
83
  plugins: [
52
84
  new webpack.DefinePlugin({
53
85
  'process.env.NODE_ENV': JSON.stringify(global.production ? 'production' : 'development'),
54
- })
86
+ }),
87
+ new WatchExternalFilesPlugin.default({
88
+ verbose: false,
89
+ files: [
90
+ paths.getSourcePath('javascripts', config.entryList),
91
+ ],
92
+ }),
55
93
  ].concat(webpackPlugins),
56
94
 
57
95
  // Imports
@@ -1,6 +1,6 @@
1
1
  const gulp = require('gulp');
2
2
  const webpack = require('webpack');
3
- const gulpWebpack = require('webpack-stream');
3
+ const gulpWebpack = require('../../vendor/webpack-stream/index.js');
4
4
  const memoize = require('nano-memoize');
5
5
 
6
6
  const merge = require('../../lib/merge');
@@ -1,88 +1,88 @@
1
- exports.stylesheets = {
2
- // Engine is a function which returns a gulp pipe function, eg. sass()
3
- // Intended to be used by plugins, not manually
4
- engine: null,
5
-
6
- // Glob list of files, which to ignore, relative to the stylesheet source folder
7
- // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
8
- ignore: [],
9
-
10
- // File extensions
11
- extensions: ['css'],
12
-
13
- // Auto prefixer options
14
- // see https://github.com/postcss/autoprefixer#options
15
- autoprefixer: {
16
- },
17
-
18
- // PostCSS Nested Calc
19
- // see https://www.npmjs.com/package/@csstools/postcss-nested-calc
20
- nestedCalc: {
21
- preserve: false,
22
- },
23
-
24
- // PostCSS plugins and options
25
- // see https://github.com/postcss/postcss
26
- postcss: {
27
- plugins: [],
28
- options: {},
29
- },
30
-
31
- // Production only settings, overwrites default settings
32
- production: {
33
- // Source maps dsabled in production mode
34
- sourcemaps: false,
35
-
36
- // Minify CSS in production mode
37
- // see https://cssnano.co/guides/optimisations
38
- cssnano: {
39
- // Preset
40
- preset: 'default',
41
-
42
- // Configuration options
43
- calc: false,
44
- zindex: false,
45
- mergeIdents: false,
46
- reduceIdents: false,
47
- discardUnused: {
48
- fontFace: false
49
- }
50
- },
51
- },
52
-
53
- // Development only settings, overwrites default settings
54
- development: {
55
- // Enable source maps in development mode
56
- // See https://www.npmjs.com/package/gulp-sourcemaps
57
- sourcemaps: {
58
- init: {},
59
- write: {}
60
- },
61
-
62
- // Minification disabled in development mode
63
- cssnano: false,
64
- },
65
- };
66
-
67
- exports.preprocess = {
68
- stylesheets: [
69
- require('./preprocess-config'),
70
- ]
71
- };
72
-
73
- exports.tasks = {
74
- stylesheets: [
75
- require('./task'),
76
- ]
77
- };
78
-
79
-
80
- /**
81
- * Paths relative to the global src and dest folders
82
- */
83
- exports.paths = {
84
- stylesheets: {
85
- 'src': 'stylesheets',
86
- 'dest': 'assets/stylesheets',
87
- }
88
- };
1
+ exports.stylesheets = {
2
+ // Engine is a function which returns a gulp pipe function, eg. sass()
3
+ // Intended to be used by plugins, not manually
4
+ engine: null,
5
+
6
+ // Glob list of files, which to ignore, relative to the stylesheet source folder
7
+ // see https://gulpjs.com/docs/en/getting-started/explaining-globs/
8
+ ignore: [],
9
+
10
+ // File extensions
11
+ extensions: ['css'],
12
+
13
+ // Auto prefixer options
14
+ // see https://github.com/postcss/autoprefixer#options
15
+ autoprefixer: {
16
+ },
17
+
18
+ // PostCSS Nested Calc
19
+ // see https://www.npmjs.com/package/@csstools/postcss-nested-calc
20
+ nestedCalc: {
21
+ preserve: false,
22
+ },
23
+
24
+ // PostCSS plugins and options
25
+ // see https://github.com/postcss/postcss
26
+ postcss: {
27
+ plugins: [],
28
+ options: {},
29
+ },
30
+
31
+ // Production only settings, overwrites default settings
32
+ production: {
33
+ // Source maps dsabled in production mode
34
+ sourcemaps: false,
35
+
36
+ // Minify CSS in production mode
37
+ // see https://cssnano.co/guides/optimisations
38
+ cssnano: {
39
+ // Preset
40
+ preset: 'default',
41
+
42
+ // Configuration options
43
+ calc: false,
44
+ zindex: false,
45
+ mergeIdents: false,
46
+ reduceIdents: false,
47
+ discardUnused: {
48
+ fontFace: false
49
+ }
50
+ },
51
+ },
52
+
53
+ // Development only settings, overwrites default settings
54
+ development: {
55
+ // Enable source maps in development mode
56
+ // See https://www.npmjs.com/package/gulp-sourcemaps
57
+ sourcemaps: {
58
+ init: {},
59
+ write: {}
60
+ },
61
+
62
+ // Minification disabled in development mode
63
+ cssnano: false,
64
+ },
65
+ };
66
+
67
+ exports.preprocess = {
68
+ stylesheets: [
69
+ require('./preprocess-config'),
70
+ ]
71
+ };
72
+
73
+ exports.tasks = {
74
+ stylesheets: [
75
+ require('./task'),
76
+ ]
77
+ };
78
+
79
+
80
+ /**
81
+ * Paths relative to the global src and dest folders
82
+ */
83
+ exports.paths = {
84
+ stylesheets: {
85
+ 'src': 'stylesheets',
86
+ 'dest': 'assets/stylesheets',
87
+ }
88
+ };
@@ -1,41 +1,41 @@
1
- const cssnano = require('cssnano');
2
- const autoprefixer = require('autoprefixer');
3
- const postcssNestedCalc = require('@csstools/postcss-nested-calc');
4
- const find = require('lodash/find');
5
-
6
- /**
7
- * Modify configuration
8
- *
9
- * @param {object} config Stylesheet configuration
10
- * @param {object} fullConfig Full configuration
11
- * @returns {object} Transformed stylesheet configuration
12
- */
13
- module.exports = function processStylesheetsConfig (config, fullConfig) {
14
- if (config && config.cssnano) {
15
- // Autoprefixer ir running separatelly in postcss
16
- config.cssnano.autoprefixer = false;
17
- }
18
-
19
- if (config && config.postcss) {
20
- config.postcss.plugins = config.postcss.plugins || [];
21
-
22
- // Add nestedCalc
23
- if (config.nestedCalc) {
24
- config.postcss.plugins.push(postcssNestedCalc(config.nestedCalc));
25
- }
26
-
27
- // Add autoprefixer
28
- if (config.autoprefixer && !find(config.postcss.plugins, {'postcssPlugin': 'autoprefixer'})) {
29
- config.postcss.plugins.push(autoprefixer(config.autoprefixer));
30
- }
31
-
32
- // // Add CSS nano
33
- if (config.cssnano && !find(config.postcss.plugins, {'postcssPlugin': 'cssnano'})) {
34
- config.postcss.plugins.push(cssnano({
35
- preset: [config.cssnano.preset, config.cssnano]
36
- }));
37
- }
38
- }
39
-
40
- return config;
41
- }
1
+ const cssnano = require('cssnano');
2
+ const autoprefixer = require('autoprefixer');
3
+ const postcssNestedCalc = require('@csstools/postcss-nested-calc');
4
+ const find = require('lodash/find');
5
+
6
+ /**
7
+ * Modify configuration
8
+ *
9
+ * @param {object} config Stylesheet configuration
10
+ * @param {object} fullConfig Full configuration
11
+ * @returns {object} Transformed stylesheet configuration
12
+ */
13
+ module.exports = function processStylesheetsConfig (config, fullConfig) {
14
+ if (config && config.cssnano) {
15
+ // Autoprefixer ir running separatelly in postcss
16
+ config.cssnano.autoprefixer = false;
17
+ }
18
+
19
+ if (config && config.postcss) {
20
+ config.postcss.plugins = config.postcss.plugins || [];
21
+
22
+ // Add nestedCalc
23
+ if (config.nestedCalc) {
24
+ config.postcss.plugins.push(postcssNestedCalc(config.nestedCalc));
25
+ }
26
+
27
+ // Add autoprefixer
28
+ if (config.autoprefixer && !find(config.postcss.plugins, {'postcssPlugin': 'autoprefixer'})) {
29
+ config.postcss.plugins.push(autoprefixer(config.autoprefixer));
30
+ }
31
+
32
+ // // Add CSS nano
33
+ if (config.cssnano && !find(config.postcss.plugins, {'postcssPlugin': 'cssnano'})) {
34
+ config.postcss.plugins.push(cssnano({
35
+ preset: [config.cssnano.preset, config.cssnano]
36
+ }));
37
+ }
38
+ }
39
+
40
+ return config;
41
+ }