@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/.eslintrc.js CHANGED
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export default {
2
2
  "env": {
3
3
  "browser": true,
4
4
  "commonjs": true,
package/.prettierrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "trailingComma": "all",
3
+ "useTabs": false,
4
+ "tabWidth": 4,
5
+ "semi": true,
6
+ "singleQuote": true,
7
+ "printWidth": 280,
8
+ "bracketSpacing": true,
9
+ "bracketSameLine": false,
10
+ "arrowParens": "always"
11
+ }
package/README.md CHANGED
@@ -51,7 +51,7 @@ Note: these commands are added to the project during `npm init`.
51
51
 
52
52
  ### Development server
53
53
 
54
- ```npx run builder```
54
+ ```npx run builder watch```
55
55
 
56
56
  ### Generate production ready files
57
57
 
@@ -80,7 +80,7 @@ Built-in plugins:
80
80
  Plugins can be enabled by adding them to the `config/config.js`, eg.
81
81
 
82
82
  ```js
83
- exports.plugins = [
83
+ export const plugins = [
84
84
  // Enables SASS engine and .sass and .scss file compilation
85
85
  require('@videinfra/static-website-builder/plugins/sass'),
86
86
 
package/bin/builder.js CHANGED
@@ -1,20 +1,28 @@
1
1
  #!/usr/bin/env node
2
- const path = require('path')
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import minimist from 'minimist';
5
+ import { fork } from 'child_process';
6
+ import { createRequire } from 'node:module';
3
7
 
4
- const allArgs = require('minimist')(process.argv.slice(2));
8
+ const require = createRequire(import.meta.url);
9
+ const allArgs = minimist(process.argv.slice(2));
5
10
  const additionalArgs = allArgs._;
6
11
 
7
12
  if (additionalArgs[0] === 'init') {
8
- const init = require('../init/index');
9
- init(additionalArgs[1]);
13
+ import('../init/index').then(({ default: init }) => {
14
+ init(additionalArgs[1]);
15
+ });
10
16
  } else {
17
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
+
11
19
  const builderEntryDir = path.resolve(__dirname, '../gulpfile.js');
12
20
  const gulpModulePath = path.dirname(require.resolve('gulp'));
13
21
  const gulpBinaryFile = path.join(gulpModulePath, '/bin/gulp');
14
22
 
15
23
  let args = ['--gulpfile', builderEntryDir];
16
24
 
17
- if(additionalArgs.length) {
25
+ if (additionalArgs.length) {
18
26
  args = args.concat(additionalArgs);
19
27
  }
20
28
 
@@ -25,10 +33,8 @@ if (additionalArgs[0] === 'init') {
25
33
  args = args.concat('--tasks', '');
26
34
  }
27
35
 
28
- require('child_process')
29
- .fork(gulpBinaryFile, args)
30
- .on('exit', function(code){
31
- // Exit with error if child process exited with an error
32
- process.exit(code);
33
- });
36
+ fork(gulpBinaryFile, args).on('exit', function (code) {
37
+ // Exit with error if child process exited with an error
38
+ process.exit(code);
39
+ });
34
40
  }
package/gulpfile.js ADDED
@@ -0,0 +1,63 @@
1
+ import { getConfigAsync } from './lib/get-config.js';
2
+ import generateGulpTasks from './lib/generate-gulp-tasks.js';
3
+
4
+ // Set mode globally it can be used by tasks
5
+ let hasProductionArg = false;
6
+
7
+ for (let i = 0; i < process.argv.length; i++) {
8
+ const argValue = process.argv[i];
9
+ // If build task is 'build' or '...-build' then set production mode
10
+ if (argValue === 'build' || argValue.match(/^[a-z0-9-]+-build$/)) {
11
+ hasProductionArg = true;
12
+ }
13
+ }
14
+
15
+ global.production = global.production || hasProductionArg || process.env.NODE_ENV === 'production';
16
+ global.development = !global.production;
17
+
18
+ // Config file
19
+ let builderConfigFile = process.env.BUILDER_CONFIG_FILE || 'config/config.js';
20
+
21
+ if (process.argv.indexOf('--config') !== -1) {
22
+ builderConfigFile = process.argv[process.argv.indexOf('--config') + 1];
23
+ } else {
24
+ for (let i = 0; i < process.argv.length; i++) {
25
+ if (process.argv[i].indexOf('--config=') !== -1) {
26
+ builderConfigFile = process.argv[i].substr(9);
27
+ }
28
+ }
29
+ }
30
+
31
+ // Load all config files and generate gulp tasks
32
+ const gulpTasks = generateGulpTasks(await getConfigAsync(builderConfigFile));
33
+
34
+ // Expose main tasks
35
+ export const build = gulpTasks.build;
36
+ export const watch = gulpTasks.watch;
37
+
38
+ // Expose separate tasks
39
+ export const clean = gulpTasks['clean-beforeBuild'];
40
+
41
+ export const fonts = gulpTasks['fonts-build'];
42
+ export const fontsWatch = gulpTasks['fonts-watch'];
43
+
44
+ export const html = gulpTasks['html-build'];
45
+ export const htmlWatch = gulpTasks['html-watch'];
46
+
47
+ export const icons = gulpTasks['icons-build'];
48
+ export const iconsWatch = gulpTasks['icons-watch'];
49
+
50
+ export const images = gulpTasks['images-build'];
51
+ export const imagesWatch = gulpTasks['images-watch'];
52
+
53
+ export const sitemap = gulpTasks['sitemap-afterBuild'];
54
+ export const sitemapWatch = gulpTasks['sitemap-watch'];
55
+
56
+ export const staticFiles = gulpTasks['staticFiles-build'];
57
+ export const staticFilesWatch = gulpTasks['staticFiles-watch'];
58
+
59
+ export const stylesheets = gulpTasks['stylesheets-build'];
60
+ export const stylesheetsWatch = gulpTasks['stylesheets-watch'];
61
+
62
+ export const javascripts = gulpTasks['javascripts-build'];
63
+ export const javascriptsWatch = gulpTasks['javascripts-watch'];
@@ -6,24 +6,27 @@
6
6
  * in each tasks config.js file
7
7
  */
8
8
 
9
- exports.clean = {};
10
- exports.static = {};
11
- exports.html = {};
12
- exports.data = {};
13
- exports.fonts = {};
14
- exports.icons = {};
15
- exports.images = {};
16
- exports.javascripts = {};
17
- exports.stylesheets = {};
18
- exports.browserSync = {};
19
- exports.sizereport = {};
9
+ import * as sassPlugin from '@videinfra/static-website-builder/plugins/sass';
10
+ import * as twigPlugin from '@videinfra/static-website-builder/plugins/twig';
20
11
 
21
- exports.plugins = [
12
+ export const clean = {};
13
+ export const staticFiles = {};
14
+ export const html = {};
15
+ export const data = {};
16
+ export const fonts = {};
17
+ export const icons = {};
18
+ export const images = {};
19
+ export const javascripts = {};
20
+ export const stylesheets = {};
21
+ export const browserSync = {};
22
+ export const sizereport = {};
23
+
24
+ export const plugins = [
22
25
  // Enables SASS engine and .sass and .scss file compilation
23
- require('@videinfra/static-website-builder/plugins/sass'),
26
+ sassPlugin,
24
27
 
25
28
  // Enables TwigJS engine .twig file compilation
26
- require('@videinfra/static-website-builder/plugins/twig'),
29
+ twigPlugin,
27
30
  ];
28
31
 
29
32
 
@@ -35,7 +38,7 @@ exports.plugins = [
35
38
  * in each tasks config.js file
36
39
  */
37
40
 
38
- exports.paths = {
41
+ export const paths = {
39
42
  src: './src',
40
43
  dest: './public',
41
44
  };
@@ -4,6 +4,6 @@
4
4
  * @example
5
5
  * <div>{{ name }}</div>
6
6
  */
7
- module.exports = {
7
+ export default {
8
8
  'name': 'World',
9
9
  };
@@ -2,7 +2,7 @@
2
2
  * All files listed in here are created / compiled and additionally
3
3
  * shared.js is automatically created, which contains all common JS (chunks / modules imported from more than 1 entry files).
4
4
  */
5
- module.exports = {
5
+ export default {
6
6
  'main': [
7
7
  './common',
8
8
  './main'
package/init/index.js CHANGED
@@ -1,56 +1,63 @@
1
- const path = require('../lib/get-path');
2
- const copyFolder = require('../lib/init/copy-folder');
3
- const readPackage = require('../lib/init/read-package');
4
- const mergePackage = require('../lib/init/merge-package');
5
- const folderExists = require('../lib/init/folder-exists');
6
- const getFolderList = require('../lib/init/get-folder-list');
7
- const chalk = require('chalk');
8
-
9
- module.exports = function init (template = 'default') {
10
- let templateName = template || 'default';
11
- let copyFrom = path.getBuilderPath('init', templateName);
12
- const copyTo = path.getProjectPath();
1
+ import { getBuilderPath, getProjectPath } from '../lib/get-path.js';
2
+ import copyFolder from '../lib/init/copy-folder.js';
3
+ import readPackage from '../lib/init/read-package.js';
4
+ import mergePackage from '../lib/init/merge-package.js';
5
+ import folderExists from '../lib/init/folder-exists.js';
6
+ import getFolderList from '../lib/init/get-folder-list.js';
7
+
8
+ import chalk from 'chalk';
9
+ import { exec } from 'child_process';
10
+
11
+ export default function init(template = 'default') {
12
+ let templateName = template || 'default';
13
+ let copyFrom = getBuilderPath('init', templateName);
14
+ const copyTo = getProjectPath();
13
15
 
14
16
  if (template === 'test' || !folderExists(copyFrom)) {
15
- console.log(chalk.red(`Template "${ templateName }" doesn't exist`));
17
+ console.log(chalk.red(`Template "${templateName}" doesn't exist`));
16
18
 
17
- getFolderList(path.getBuilderPath('init')).then((templates) => {
19
+ getFolderList(getBuilderPath('init')).then((templates) => {
18
20
  console.log('Available templates:');
19
- console.log(chalk.cyan(` ${ templates.join('\n ') }`));
21
+ console.log(chalk.cyan(` ${templates.join('\n ')}`));
20
22
  });
21
23
  return;
22
24
  }
23
25
 
24
- console.log(chalk.magenta(`Generating project files using template "${ templateName }"`));
26
+ console.log(chalk.magenta(`Generating project files using template "${templateName}"`));
25
27
 
26
28
  // Copy files
27
29
  const filesCopied = copyFolder(copyFrom, copyTo);
28
30
 
29
31
  // Merge template package.json into projects package.json
30
- const packageMerged = readPackage(path.getBuilderPath('init', templateName, 'package.json'), {}).then((package) => {
31
- return mergePackage(path.getProjectPath('package.json'), package).then(() => {
32
- if (package.dependencies || package.devDependencies) {
33
- console.log(chalk.magenta('Installing npm dependencies'));
34
-
35
- return new Promise((resolve, reject) => {
36
- require('child_process').exec('npm install', function (error, stdout, stderr) {
37
- resolve();
32
+ const packageMerged = readPackage(getBuilderPath('init', templateName, 'package.json'), {}).then((packageJSON) => {
33
+ return mergePackage(getProjectPath('package.json'), packageJSON)
34
+ .then(() => {
35
+ if (packageJSON.dependencies || packageJSON.devDependencies) {
36
+ console.log(chalk.magenta('Installing npm dependencies'));
37
+
38
+ return new Promise((resolve, _reject) => {
39
+ exec('npm install', function (_error, _stdout, _stderr) {
40
+ resolve();
41
+ });
38
42
  });
39
- });
40
- }
41
- }).catch((err) => {
42
- // Skip errors
43
- return Promise.resolve();
44
- });
43
+ }
44
+ })
45
+ .catch((_err) => {
46
+ // Skip errors
47
+ return Promise.resolve();
48
+ });
45
49
  });
46
50
 
47
- Promise.all([filesCopied, packageMerged]).then(() => {
48
- console.log(chalk.green('All done\n'));
51
+ Promise.all([filesCopied, packageMerged]).then(
52
+ () => {
53
+ console.log(chalk.green('All done\n'));
49
54
 
50
- console.log('To start the dev server:\n' + chalk.cyan(' npm run start'));
55
+ console.log('To start the dev server:\n' + chalk.cyan(' npm run start'));
51
56
 
52
- console.log('To build the project:\n' + chalk.cyan(' npm run build'));
53
- }, (err) => {
54
- throw err;
55
- });
57
+ console.log('To build the project:\n' + chalk.cyan(' npm run build'));
58
+ },
59
+ (err) => {
60
+ throw err;
61
+ },
62
+ );
56
63
  }
@@ -2,14 +2,18 @@
2
2
  * Build a project for testing
3
3
  */
4
4
 
5
- exports.clean = {};
6
- exports.static = {};
7
- exports.html = {};
8
- exports.data = {};
9
- exports.fonts = {};
10
- exports.icons = {};
11
- exports.images = {};
12
- exports.javascripts = {
5
+ import * as sassPlugin from '../../../plugins/sass.js';
6
+ import * as twigPlugin from '../../../plugins/twig.js';
7
+ import * as symfonyFiltersPlugin from '../../../plugins/twig/symfony-filters.js';
8
+
9
+ export const clean = {};
10
+ export const staticFiles = {};
11
+ export const html = {};
12
+ export const data = {};
13
+ export const fonts = {};
14
+ export const icons = {};
15
+ export const images = {};
16
+ export const javascripts = {
13
17
  entryList: [
14
18
  {
15
19
  name: '_entries.js',
@@ -22,21 +26,21 @@ exports.javascripts = {
22
26
  },
23
27
  ],
24
28
  };
25
- exports.stylesheets = {};
26
- exports.sizereport = false;
29
+ export const stylesheets = {};
30
+ export const sizereport = false;
27
31
 
28
- exports.plugins = [
32
+ export const plugins = [
29
33
  // Enables SASS engine and .sass and .scss file compilation
30
- require('../../../plugins/sass'),
34
+ sassPlugin,
31
35
 
32
36
  // Enables TwigJS engine .twig file compilation
33
- require('../../../plugins/twig'),
37
+ twigPlugin,
34
38
 
35
39
  // Enables TWIG Symfony filters
36
- require('../../../plugins/twig/symfony-filters'),
40
+ symfonyFiltersPlugin,
37
41
  ];
38
42
 
39
- exports.env = {
43
+ export const env = {
40
44
  map: {
41
45
  'HOST': 'host',
42
46
  'FOO': 'foo',
@@ -56,7 +60,7 @@ exports.env = {
56
60
  * in each tasks config.js file
57
61
  */
58
62
 
59
- exports.paths = {
63
+ export const paths = {
60
64
  src: './init/test/src',
61
65
  dest: './tests/build/public',
62
66
  env: ['./init/test/.env', './init/test/.env.local'],
@@ -4,7 +4,7 @@
4
4
  * @example
5
5
  * <div>{{ name }}</div>
6
6
  */
7
- module.exports = {
7
+ export default {
8
8
  'world': 'World',
9
9
  'hostFromGlobalJS': process.env.host,
10
10
  };
@@ -4,7 +4,7 @@
4
4
  * @param {string} str File name
5
5
  * @returns {string} Camelized name
6
6
  */
7
- module.exports = function camelizeFileName (str) {
7
+ export default function camelizeFileName (str) {
8
8
  return str
9
9
  // Remove extension
10
10
  .replace(/(.+?)\..*$/ig, '$1')
@@ -1,9 +1,9 @@
1
- const map = require('lodash/map');
2
- const assign = require('lodash/assign');
3
- const filter = require('lodash/filter');
4
- const { series, parallel } = require('gulp');
5
- const { DEFAULT_TASKS, BUILD_TASKS } = require('./task-order');
6
- const resolveDynamicTask = require('./gulp/resolve-dynamic-task');
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
7
 
8
8
  /**
9
9
  * Sort tasks by .order property
@@ -21,7 +21,7 @@ function sortTasks (tasks) {
21
21
  * @param {object} taskConfig Task config
22
22
  * @returns {object} Task list
23
23
  */
24
- function generateTaskList (taskConfig) {
24
+ export function generateTaskList (taskConfig) {
25
25
  const taskList = {
26
26
  'default': map(DEFAULT_TASKS, (taskName) => []),
27
27
  'build': map(BUILD_TASKS, (taskName) => []),
@@ -58,6 +58,9 @@ function generateTaskList (taskConfig) {
58
58
  taskList.default = filter(taskList.default, taskGroup => taskGroup.length).sort(sortTasks);
59
59
  taskList.build = filter(taskList.build, taskGroup => taskGroup.length).sort(sortTasks);
60
60
 
61
+ // Alias default to watch
62
+ taskList.watch = taskList.default;
63
+
61
64
  return taskList;
62
65
  }
63
66
 
@@ -67,7 +70,7 @@ function generateTaskList (taskConfig) {
67
70
  * @param {object} taskConfig Task config
68
71
  * @returns {object} Gulp task list
69
72
  */
70
- module.exports = function generateGulpTasks (taskConfig) {
73
+ export default function generateGulpTasks (taskConfig) {
71
74
  const taskList = generateTaskList(taskConfig);
72
75
 
73
76
  // Create gulp tasks with parallel and series
@@ -76,8 +79,7 @@ module.exports = function generateGulpTasks (taskConfig) {
76
79
 
77
80
  return assign({
78
81
  'default': series(...defaultGulpTasks),
82
+ 'watch': series(...defaultGulpTasks), // watch and default are aliases
79
83
  'build': series(...buildGulpTasks),
80
84
  }, taskList.separate);
81
85
  }
82
-
83
- module.exports.generateTaskList = generateTaskList;