@videinfra/static-website-builder 1.11.1 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/init/index.js +56 -56
- package/init/test/config/config.js +36 -36
- package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
- package/init/test/src/stylesheets/ignore-test.scss +4 -4
- package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
- package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
- package/lib/camelize-file-name.js +21 -21
- package/lib/generate-gulp-tasks.js +4 -3
- package/lib/get-config.js +157 -157
- package/lib/get-file-names.js +23 -23
- package/lib/get-path.js +109 -109
- package/lib/globs-helper.js +136 -136
- package/lib/gulp/dynamic-task.js +8 -0
- package/lib/gulp/resolve-dynamic-task.js +11 -0
- package/lib/log-error.js +15 -15
- package/lib/merge.js +27 -27
- package/lib/run-preprocess.js +1 -1
- package/package.json +1 -1
- package/plugins/sass-engine/preprocess-config.js +54 -54
- package/plugins/sass.js +38 -38
- package/plugins/twig-engine/preprocess-config.js +47 -47
- package/plugins/twig.js +65 -65
- package/tasks/data/data-loader-js.js +5 -5
- package/tasks/data/get-data.js +87 -87
- package/tasks/html/task.js +91 -91
- package/tasks/icons/config.js +52 -52
- package/tasks/javascripts/config.js +13 -2
- package/tasks/javascripts/preprocess-config.js +121 -50
- package/tasks/javascripts/task.js +40 -16
- package/tasks/javascripts/webpack-url-version.js +32 -0
- package/tasks/stylesheets/config.js +88 -88
- package/tasks/stylesheets/preprocess-config.js +41 -41
- package/tasks/stylesheets/task.js +69 -69
- package/tests/build/build.test.js +101 -101
- package/tests/camelize-file-name.test.js +11 -11
- package/tests/glob-helper.test.js +99 -99
- package/tests/run-preprocess.test.js +2 -1
- package/vendor/gulp-twig/LICENSE +20 -20
- package/vendor/gulp-twig/README.md +167 -167
- package/vendor/gulp-twig/index.js +130 -130
- package/vendor/gulp-twig/package.json +43 -43
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.12.1] - 2024-08-19
|
|
8
|
+
### Added
|
|
9
|
+
- Version string to the dynamically loaded JS files
|
|
10
|
+
|
|
11
|
+
## [1.12.0] - 2024-02-25
|
|
12
|
+
### Added
|
|
13
|
+
- Support for multiple entry lists which each has its own "shared" chunk file
|
|
14
|
+
|
|
7
15
|
## [1.11.1] - 2024-02-24
|
|
8
16
|
### Fixed
|
|
9
17
|
- Fixed dependencies
|
package/init/index.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
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();
|
|
13
|
-
|
|
14
|
-
if (template === 'test' || !folderExists(copyFrom)) {
|
|
15
|
-
console.log(chalk.red(`Template "${ templateName }" doesn't exist`));
|
|
16
|
-
|
|
17
|
-
getFolderList(path.getBuilderPath('init')).then((templates) => {
|
|
18
|
-
console.log('Available templates:');
|
|
19
|
-
console.log(chalk.cyan(` ${ templates.join('\n ') }`));
|
|
20
|
-
});
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
console.log(chalk.magenta(`Generating project files using template "${ templateName }"`));
|
|
25
|
-
|
|
26
|
-
// Copy files
|
|
27
|
-
const filesCopied = copyFolder(copyFrom, copyTo);
|
|
28
|
-
|
|
29
|
-
// 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();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}).catch((err) => {
|
|
42
|
-
// Skip errors
|
|
43
|
-
return Promise.resolve();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
Promise.all([filesCopied, packageMerged]).then(() => {
|
|
48
|
-
console.log(chalk.green('All done\n'));
|
|
49
|
-
|
|
50
|
-
console.log('To start the dev server:\n' + chalk.cyan(' npm run start'));
|
|
51
|
-
|
|
52
|
-
console.log('To build the project:\n' + chalk.cyan(' npm run build'));
|
|
53
|
-
}, (err) => {
|
|
54
|
-
throw err;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
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();
|
|
13
|
+
|
|
14
|
+
if (template === 'test' || !folderExists(copyFrom)) {
|
|
15
|
+
console.log(chalk.red(`Template "${ templateName }" doesn't exist`));
|
|
16
|
+
|
|
17
|
+
getFolderList(path.getBuilderPath('init')).then((templates) => {
|
|
18
|
+
console.log('Available templates:');
|
|
19
|
+
console.log(chalk.cyan(` ${ templates.join('\n ') }`));
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log(chalk.magenta(`Generating project files using template "${ templateName }"`));
|
|
25
|
+
|
|
26
|
+
// Copy files
|
|
27
|
+
const filesCopied = copyFolder(copyFrom, copyTo);
|
|
28
|
+
|
|
29
|
+
// 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();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
// Skip errors
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
Promise.all([filesCopied, packageMerged]).then(() => {
|
|
48
|
+
console.log(chalk.green('All done\n'));
|
|
49
|
+
|
|
50
|
+
console.log('To start the dev server:\n' + chalk.cyan(' npm run start'));
|
|
51
|
+
|
|
52
|
+
console.log('To build the project:\n' + chalk.cyan(' npm run build'));
|
|
53
|
+
}, (err) => {
|
|
54
|
+
throw err;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Build a project for testing
|
|
3
|
-
*/
|
|
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 = {};
|
|
13
|
-
exports.stylesheets = {};
|
|
14
|
-
exports.sizereport = false;
|
|
15
|
-
|
|
16
|
-
exports.plugins = [
|
|
17
|
-
// Enables SASS engine and .sass and .scss file compilation
|
|
18
|
-
require('../../../plugins/sass'),
|
|
19
|
-
|
|
20
|
-
// Enables TwigJS engine .twig file compilation
|
|
21
|
-
require('../../../plugins/twig'),
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
* Path configuration
|
|
27
|
-
* All options will be merged with defaults, but not replaces whole configuration object
|
|
28
|
-
*
|
|
29
|
-
* Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
|
|
30
|
-
* in each tasks config.js file
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
exports.paths = {
|
|
34
|
-
src: './init/test/src',
|
|
35
|
-
dest: './tests/build/public',
|
|
36
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* Build a project for testing
|
|
3
|
+
*/
|
|
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 = {};
|
|
13
|
+
exports.stylesheets = {};
|
|
14
|
+
exports.sizereport = false;
|
|
15
|
+
|
|
16
|
+
exports.plugins = [
|
|
17
|
+
// Enables SASS engine and .sass and .scss file compilation
|
|
18
|
+
require('../../../plugins/sass'),
|
|
19
|
+
|
|
20
|
+
// Enables TwigJS engine .twig file compilation
|
|
21
|
+
require('../../../plugins/twig'),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Path configuration
|
|
27
|
+
* All options will be merged with defaults, but not replaces whole configuration object
|
|
28
|
+
*
|
|
29
|
+
* Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
|
|
30
|
+
* in each tasks config.js file
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
exports.paths = {
|
|
34
|
+
src: './init/test/src',
|
|
35
|
+
dest: './tests/build/public',
|
|
36
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
main {
|
|
2
|
-
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
|
|
3
|
-
}
|
|
1
|
+
main {
|
|
2
|
+
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
|
|
3
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
--yes: ;
|
|
3
|
-
--no: initial;
|
|
4
|
-
}
|
|
1
|
+
:root {
|
|
2
|
+
--yes: ;
|
|
3
|
+
--no: initial;
|
|
4
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
body {
|
|
2
|
-
padding-top: calc(10vw + calc(10vh * 1.5));
|
|
3
|
-
}
|
|
1
|
+
body {
|
|
2
|
+
padding-top: calc(10vw + calc(10vh * 1.5));
|
|
3
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
@import "settings/colors";
|
|
2
|
-
@import "components/button";
|
|
1
|
+
@import "settings/colors";
|
|
2
|
+
@import "components/button";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Camelize filename
|
|
3
|
-
*
|
|
4
|
-
* @param {string} str File name
|
|
5
|
-
* @returns {string} Camelized name
|
|
6
|
-
*/
|
|
7
|
-
module.exports = function camelizeFileName (str) {
|
|
8
|
-
return str
|
|
9
|
-
// Remove extension
|
|
10
|
-
.replace(/(.+?)\..*$/ig, '$1')
|
|
11
|
-
// Remove dot
|
|
12
|
-
.replace(/\./g, '')
|
|
13
|
-
// Replace non alpha-numeric characters
|
|
14
|
-
.replace(/[^a-z0-9]/ig, ' ')
|
|
15
|
-
// Uppercase words
|
|
16
|
-
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
17
|
-
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
18
|
-
})
|
|
19
|
-
// Remove empty spaces
|
|
20
|
-
.replace(/\s+/g, '');
|
|
21
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Camelize filename
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str File name
|
|
5
|
+
* @returns {string} Camelized name
|
|
6
|
+
*/
|
|
7
|
+
module.exports = function camelizeFileName (str) {
|
|
8
|
+
return str
|
|
9
|
+
// Remove extension
|
|
10
|
+
.replace(/(.+?)\..*$/ig, '$1')
|
|
11
|
+
// Remove dot
|
|
12
|
+
.replace(/\./g, '')
|
|
13
|
+
// Replace non alpha-numeric characters
|
|
14
|
+
.replace(/[^a-z0-9]/ig, ' ')
|
|
15
|
+
// Uppercase words
|
|
16
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
17
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
18
|
+
})
|
|
19
|
+
// Remove empty spaces
|
|
20
|
+
.replace(/\s+/g, '');
|
|
21
|
+
}
|
|
@@ -3,6 +3,7 @@ const assign = require('lodash/assign');
|
|
|
3
3
|
const filter = require('lodash/filter');
|
|
4
4
|
const { series, parallel } = require('gulp');
|
|
5
5
|
const { DEFAULT_TASKS, BUILD_TASKS } = require('./task-order');
|
|
6
|
+
const resolveDynamicTask = require('./gulp/resolve-dynamic-task');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -28,16 +29,16 @@ function generateTaskList (taskConfig) {
|
|
|
28
29
|
|
|
29
30
|
// Create individual tasks, which can be run separatelly
|
|
30
31
|
for (let gulpTaskName in gulpTaskList) {
|
|
31
|
-
taskList.separate[`${ taskName }-${ gulpTaskName }`] = gulpTaskList[gulpTaskName];
|
|
32
|
+
taskList.separate[`${ taskName }-${ gulpTaskName }`] = resolveDynamicTask(gulpTaskList[gulpTaskName]);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
for (let t = 0; t < DEFAULT_TASKS.length; t++) {
|
|
35
36
|
if (DEFAULT_TASKS[t] in gulpTaskList) {
|
|
36
|
-
const gulpTask = gulpTaskList[DEFAULT_TASKS[t]];
|
|
37
|
+
const gulpTask = resolveDynamicTask(gulpTaskList[DEFAULT_TASKS[t]]);
|
|
37
38
|
taskList.default[t].push(gulpTask);
|
|
38
39
|
}
|
|
39
40
|
if (BUILD_TASKS[t] in gulpTaskList) {
|
|
40
|
-
const gulpTask = gulpTaskList[BUILD_TASKS[t]];
|
|
41
|
+
const gulpTask = resolveDynamicTask(gulpTaskList[BUILD_TASKS[t]]);
|
|
41
42
|
taskList.build[t].push(gulpTask);
|
|
42
43
|
}
|
|
43
44
|
}
|
package/lib/get-config.js
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
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');
|
|
7
|
-
|
|
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');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns builder and project specific task and plugin configurations combined
|
|
18
|
-
* Configuration is preprocessed
|
|
19
|
-
*
|
|
20
|
-
* @returns {object} Task configurations
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
let taskConfig = null;
|
|
24
|
-
|
|
25
|
-
function getConfig (builderConfigFile) {
|
|
26
|
-
if (!taskConfig) {
|
|
27
|
-
// Load all task configs
|
|
28
|
-
taskConfig = itterateConfig(loadConfig(), mergeConfigMode);
|
|
29
|
-
|
|
30
|
-
// 1. First load project specific config.js
|
|
31
|
-
const projectConfigPath = getPath.getProjectPath(builderConfigFile);
|
|
32
|
-
let projectTaskConfig = {};
|
|
33
|
-
let hasProjectConfigFile = true;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
fs.accessSync(projectConfigPath);
|
|
37
|
-
} catch (err) {
|
|
38
|
-
logError({'plugin': 'static-website-builder', 'message': `Couldn't find configuration file "${ projectConfigPath }"`});
|
|
39
|
-
hasProjectConfigFile = false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (hasProjectConfigFile) {
|
|
43
|
-
projectTaskConfig = itterateConfig(require(projectConfigPath), mergeConfigMode);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 2. Marge plugins into the config, each plugin is just a config
|
|
47
|
-
const plugins = (taskConfig.plugins || []).concat(projectTaskConfig.plugins || []);
|
|
48
|
-
if (plugins) {
|
|
49
|
-
taskConfig.plugins = null;
|
|
50
|
-
projectTaskConfig.plugins = null;
|
|
51
|
-
|
|
52
|
-
each(plugins, (plugin) => {
|
|
53
|
-
taskConfig = merge(taskConfig, itterateConfig(plugin, mergeConfigMode));
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 3. Only after plugins has been executed, merge project specific config.js into main config
|
|
58
|
-
if (projectTaskConfig) {
|
|
59
|
-
taskConfig = merge(taskConfig, projectTaskConfig);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 4. Preprocess
|
|
63
|
-
taskConfig = runPreprocess(taskConfig);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return taskConfig;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Returns task sub-config by path
|
|
71
|
-
*
|
|
72
|
-
* @param {...string} path Path to the sub-config
|
|
73
|
-
* @returns {any} Task sub-config
|
|
74
|
-
*/
|
|
75
|
-
function getTaskConfig (...path) {
|
|
76
|
-
return get(getConfig(), path, null);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Itterate over each config property and call function on
|
|
81
|
-
* each object or array
|
|
82
|
-
*
|
|
83
|
-
* @param {*} object
|
|
84
|
-
* @param {*} fn
|
|
85
|
-
* @protected
|
|
86
|
-
*/
|
|
87
|
-
function itterateConfig (config, fn) {
|
|
88
|
-
if (config === false) return false;
|
|
89
|
-
const base = isPlainObject(config) ? {} : [];
|
|
90
|
-
|
|
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
|
-
}
|
|
99
|
-
|
|
100
|
-
return object;
|
|
101
|
-
}, base);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Merge 'production' or 'development' mode sub-ojbects into an object and remove
|
|
106
|
-
* mode sub-objects
|
|
107
|
-
*
|
|
108
|
-
* @param {object} config Config
|
|
109
|
-
* @returns {object} Config
|
|
110
|
-
* @protected
|
|
111
|
-
*/
|
|
112
|
-
function mergeConfigMode (config) {
|
|
113
|
-
if ('production' in config || 'development' in config) {
|
|
114
|
-
const mode = global.production ? 'production' : 'development';
|
|
115
|
-
const value = merge(config, config[mode]);
|
|
116
|
-
|
|
117
|
-
if (value !== false) {
|
|
118
|
-
return omit(value, ['production', 'development']);
|
|
119
|
-
} else {
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
return config;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Load config files
|
|
129
|
-
*
|
|
130
|
-
* @returns {object} Configuration
|
|
131
|
-
* @protected
|
|
132
|
-
*/
|
|
133
|
-
function loadConfig () {
|
|
134
|
-
const taskFolder = path.resolve(__dirname, '../tasks');
|
|
135
|
-
let taskConfig = {};
|
|
136
|
-
|
|
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;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
taskConfig = merge(taskConfig, require(configFileName));
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
return taskConfig;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
exports.getConfig = getConfig;
|
|
157
|
-
exports.getTaskConfig = getTaskConfig;
|
|
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');
|
|
7
|
+
|
|
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');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns builder and project specific task and plugin configurations combined
|
|
18
|
+
* Configuration is preprocessed
|
|
19
|
+
*
|
|
20
|
+
* @returns {object} Task configurations
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
let taskConfig = null;
|
|
24
|
+
|
|
25
|
+
function getConfig (builderConfigFile) {
|
|
26
|
+
if (!taskConfig) {
|
|
27
|
+
// Load all task configs
|
|
28
|
+
taskConfig = itterateConfig(loadConfig(), mergeConfigMode);
|
|
29
|
+
|
|
30
|
+
// 1. First load project specific config.js
|
|
31
|
+
const projectConfigPath = getPath.getProjectPath(builderConfigFile);
|
|
32
|
+
let projectTaskConfig = {};
|
|
33
|
+
let hasProjectConfigFile = true;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
fs.accessSync(projectConfigPath);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
logError({'plugin': 'static-website-builder', 'message': `Couldn't find configuration file "${ projectConfigPath }"`});
|
|
39
|
+
hasProjectConfigFile = false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (hasProjectConfigFile) {
|
|
43
|
+
projectTaskConfig = itterateConfig(require(projectConfigPath), mergeConfigMode);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 2. Marge plugins into the config, each plugin is just a config
|
|
47
|
+
const plugins = (taskConfig.plugins || []).concat(projectTaskConfig.plugins || []);
|
|
48
|
+
if (plugins) {
|
|
49
|
+
taskConfig.plugins = null;
|
|
50
|
+
projectTaskConfig.plugins = null;
|
|
51
|
+
|
|
52
|
+
each(plugins, (plugin) => {
|
|
53
|
+
taskConfig = merge(taskConfig, itterateConfig(plugin, mergeConfigMode));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 3. Only after plugins has been executed, merge project specific config.js into main config
|
|
58
|
+
if (projectTaskConfig) {
|
|
59
|
+
taskConfig = merge(taskConfig, projectTaskConfig);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 4. Preprocess
|
|
63
|
+
taskConfig = runPreprocess(taskConfig);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return taskConfig;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns task sub-config by path
|
|
71
|
+
*
|
|
72
|
+
* @param {...string} path Path to the sub-config
|
|
73
|
+
* @returns {any} Task sub-config
|
|
74
|
+
*/
|
|
75
|
+
function getTaskConfig (...path) {
|
|
76
|
+
return get(getConfig(), path, null);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Itterate over each config property and call function on
|
|
81
|
+
* each object or array
|
|
82
|
+
*
|
|
83
|
+
* @param {*} object
|
|
84
|
+
* @param {*} fn
|
|
85
|
+
* @protected
|
|
86
|
+
*/
|
|
87
|
+
function itterateConfig (config, fn) {
|
|
88
|
+
if (config === false) return false;
|
|
89
|
+
const base = isPlainObject(config) ? {} : [];
|
|
90
|
+
|
|
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
|
+
}
|
|
99
|
+
|
|
100
|
+
return object;
|
|
101
|
+
}, base);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Merge 'production' or 'development' mode sub-ojbects into an object and remove
|
|
106
|
+
* mode sub-objects
|
|
107
|
+
*
|
|
108
|
+
* @param {object} config Config
|
|
109
|
+
* @returns {object} Config
|
|
110
|
+
* @protected
|
|
111
|
+
*/
|
|
112
|
+
function mergeConfigMode (config) {
|
|
113
|
+
if ('production' in config || 'development' in config) {
|
|
114
|
+
const mode = global.production ? 'production' : 'development';
|
|
115
|
+
const value = merge(config, config[mode]);
|
|
116
|
+
|
|
117
|
+
if (value !== false) {
|
|
118
|
+
return omit(value, ['production', 'development']);
|
|
119
|
+
} else {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
return config;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Load config files
|
|
129
|
+
*
|
|
130
|
+
* @returns {object} Configuration
|
|
131
|
+
* @protected
|
|
132
|
+
*/
|
|
133
|
+
function loadConfig () {
|
|
134
|
+
const taskFolder = path.resolve(__dirname, '../tasks');
|
|
135
|
+
let taskConfig = {};
|
|
136
|
+
|
|
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;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
taskConfig = merge(taskConfig, require(configFileName));
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return taskConfig;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
exports.getConfig = getConfig;
|
|
157
|
+
exports.getTaskConfig = getTaskConfig;
|
package/lib/get-file-names.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns list of filenames in folder recursively
|
|
6
|
-
*
|
|
7
|
-
* @param {string} folder Folder path
|
|
8
|
-
* @param {string} [subFolder=''] Subfolder path
|
|
9
|
-
* @returns {array} List of filenames, relative to folder
|
|
10
|
-
*/
|
|
11
|
-
module.exports = function getFileNamesSync (folder, subFolder = '') {
|
|
12
|
-
let fileNames = []
|
|
13
|
-
|
|
14
|
-
fs.readdirSync(folder, { withFileTypes: true }).forEach(file => {
|
|
15
|
-
if (file.isDirectory()) {
|
|
16
|
-
fileNames = fileNames.concat(getFileNamesSync(path.join(folder, file.name), path.join(subFolder, file.name)));
|
|
17
|
-
} else {
|
|
18
|
-
fileNames.push(path.join(subFolder, file.name))
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return fileNames;
|
|
23
|
-
}
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns list of filenames in folder recursively
|
|
6
|
+
*
|
|
7
|
+
* @param {string} folder Folder path
|
|
8
|
+
* @param {string} [subFolder=''] Subfolder path
|
|
9
|
+
* @returns {array} List of filenames, relative to folder
|
|
10
|
+
*/
|
|
11
|
+
module.exports = function getFileNamesSync (folder, subFolder = '') {
|
|
12
|
+
let fileNames = []
|
|
13
|
+
|
|
14
|
+
fs.readdirSync(folder, { withFileTypes: true }).forEach(file => {
|
|
15
|
+
if (file.isDirectory()) {
|
|
16
|
+
fileNames = fileNames.concat(getFileNamesSync(path.join(folder, file.name), path.join(subFolder, file.name)));
|
|
17
|
+
} else {
|
|
18
|
+
fileNames.push(path.join(subFolder, file.name))
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return fileNames;
|
|
23
|
+
}
|