@videinfra/static-website-builder 1.12.0 → 1.13.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.
- package/CHANGELOG.md +8 -0
- package/init/index.js +56 -56
- package/init/test/config/config.js +48 -36
- package/init/test/src/javascripts/_entries-alt.js +13 -0
- 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/get-file-names.js +23 -23
- package/lib/get-path.js +109 -109
- package/lib/globs-helper.js +136 -136
- package/lib/log-error.js +15 -15
- package/lib/merge.js +27 -27
- 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 +1 -1
- package/tasks/javascripts/preprocess-config.js +28 -18
- 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 +115 -101
- package/tests/camelize-file-name.test.js +11 -11
- package/tests/glob-helper.test.js +99 -99
- 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/vendor/webpack-stream/index.js +1 -9
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.13.0] - 2024-08-23
|
|
8
|
+
### Added
|
|
9
|
+
- Added 'outpuSubFolder' property to entries configuration
|
|
10
|
+
|
|
11
|
+
## [1.12.1] - 2024-08-19
|
|
12
|
+
### Added
|
|
13
|
+
- Version string to the dynamically loaded JS files
|
|
14
|
+
|
|
7
15
|
## [1.12.0] - 2024-02-25
|
|
8
16
|
### Added
|
|
9
17
|
- Support for multiple entry lists which each has its own "shared" chunk file
|
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,48 @@
|
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
entryList: [
|
|
14
|
+
{
|
|
15
|
+
name: '_entries.js',
|
|
16
|
+
shared: 'shared',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: '_entries-alt.js',
|
|
20
|
+
shared: 'shared',
|
|
21
|
+
outpuSubFolder: 'alt'
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
exports.stylesheets = {};
|
|
26
|
+
exports.sizereport = false;
|
|
27
|
+
|
|
28
|
+
exports.plugins = [
|
|
29
|
+
// Enables SASS engine and .sass and .scss file compilation
|
|
30
|
+
require('../../../plugins/sass'),
|
|
31
|
+
|
|
32
|
+
// Enables TwigJS engine .twig file compilation
|
|
33
|
+
require('../../../plugins/twig'),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* Path configuration
|
|
39
|
+
* All options will be merged with defaults, but not replaces whole configuration object
|
|
40
|
+
*
|
|
41
|
+
* Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
|
|
42
|
+
* in each tasks config.js file
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
exports.paths = {
|
|
46
|
+
src: './init/test/src',
|
|
47
|
+
dest: './tests/build/public',
|
|
48
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* All files listed in here are created / compiled and additionally
|
|
3
|
+
* shared.js is automatically created, which contains all common JS (chunks / modules imported from more than 1 entry files).
|
|
4
|
+
*/
|
|
5
|
+
module.exports = {
|
|
6
|
+
'shared': [
|
|
7
|
+
'./common'
|
|
8
|
+
],
|
|
9
|
+
'main': [
|
|
10
|
+
'./common',
|
|
11
|
+
'./main'
|
|
12
|
+
]
|
|
13
|
+
};
|
|
@@ -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
|
+
}
|
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
|
+
}
|
package/lib/get-path.js
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const memoize = require('nano-memoize');
|
|
3
|
-
const getConfig = require('./get-config');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns builder and project specific path configurations merged
|
|
8
|
-
*
|
|
9
|
-
* @returns {object} Configuration
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const getPathConfig = memoize(function () {
|
|
13
|
-
return getConfig.getConfig().paths;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns a path relative to the project folder
|
|
18
|
-
*
|
|
19
|
-
* @param {...any} paths List of paths
|
|
20
|
-
* @returns {string} Path
|
|
21
|
-
*/
|
|
22
|
-
function getProjectPath (...paths) {
|
|
23
|
-
return path.resolve(process.env.INIT_CWD || process.cwd(), ...paths);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns a path relative to the builder folder
|
|
28
|
-
*
|
|
29
|
-
* @param {...any} paths List of paths
|
|
30
|
-
* @returns {string} Path
|
|
31
|
-
*/
|
|
32
|
-
function getBuilderPath (...paths) {
|
|
33
|
-
return path.resolve(__dirname, '../', ...paths);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Returns task source path or paths
|
|
38
|
-
*
|
|
39
|
-
* @param {string} name Task name
|
|
40
|
-
* @param {...string} paths Additional sub paths
|
|
41
|
-
* @returns {string|array} Task source path or list of paths
|
|
42
|
-
*/
|
|
43
|
-
function getSourcePath (name, ...paths) {
|
|
44
|
-
const pathConfig = getPathConfig();
|
|
45
|
-
const path = pathConfig[name].src;
|
|
46
|
-
|
|
47
|
-
if (typeof path === 'string') {
|
|
48
|
-
return getProjectPath(pathConfig.src, path, ...paths);
|
|
49
|
-
} else if (Array.isArray(path)) {
|
|
50
|
-
return path.map((path) => getProjectPath(pathConfig.src, path, ...paths));
|
|
51
|
-
} else {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Returns task source paths
|
|
58
|
-
*
|
|
59
|
-
* @param {string} name Task name
|
|
60
|
-
* @param {...string} paths Additional sub paths
|
|
61
|
-
* @returns {array} Task source paths
|
|
62
|
-
*/
|
|
63
|
-
function getSourcePaths (name, ...paths) {
|
|
64
|
-
const path = getSourcePath(name, ...paths);
|
|
65
|
-
|
|
66
|
-
if (typeof path === 'string') {
|
|
67
|
-
return [path];
|
|
68
|
-
} else {
|
|
69
|
-
return path;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Returns task destination path
|
|
75
|
-
*
|
|
76
|
-
* @param {string} [name] Task name
|
|
77
|
-
* @param {...string} paths Additional sub paths
|
|
78
|
-
* @returns {string} Task destination path
|
|
79
|
-
*/
|
|
80
|
-
function getDestPath (name, ...paths) {
|
|
81
|
-
const pathConfig = getPathConfig();
|
|
82
|
-
|
|
83
|
-
if (name) {
|
|
84
|
-
return getProjectPath(pathConfig.dest, pathConfig[name].dest || '', ...paths);
|
|
85
|
-
} else {
|
|
86
|
-
return getProjectPath(pathConfig.dest);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Returns public path
|
|
92
|
-
*
|
|
93
|
-
* @param {string} [name] Task name
|
|
94
|
-
* @returns {string} Task public path
|
|
95
|
-
*/
|
|
96
|
-
function getPublicPath (name) {
|
|
97
|
-
const destFullPath = getDestPath(name);
|
|
98
|
-
const destPath = getDestPath();
|
|
99
|
-
return destFullPath.replace(destPath, '') + '/';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
exports.getPathConfig = getPathConfig;
|
|
104
|
-
exports.getSourcePath = getSourcePath;
|
|
105
|
-
exports.getSourcePaths = getSourcePaths;
|
|
106
|
-
exports.getDestPath = getDestPath;
|
|
107
|
-
exports.getProjectPath = getProjectPath;
|
|
108
|
-
exports.getBuilderPath = getBuilderPath;
|
|
109
|
-
exports.getPublicPath = getPublicPath;
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const memoize = require('nano-memoize');
|
|
3
|
+
const getConfig = require('./get-config');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns builder and project specific path configurations merged
|
|
8
|
+
*
|
|
9
|
+
* @returns {object} Configuration
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const getPathConfig = memoize(function () {
|
|
13
|
+
return getConfig.getConfig().paths;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a path relative to the project folder
|
|
18
|
+
*
|
|
19
|
+
* @param {...any} paths List of paths
|
|
20
|
+
* @returns {string} Path
|
|
21
|
+
*/
|
|
22
|
+
function getProjectPath (...paths) {
|
|
23
|
+
return path.resolve(process.env.INIT_CWD || process.cwd(), ...paths);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns a path relative to the builder folder
|
|
28
|
+
*
|
|
29
|
+
* @param {...any} paths List of paths
|
|
30
|
+
* @returns {string} Path
|
|
31
|
+
*/
|
|
32
|
+
function getBuilderPath (...paths) {
|
|
33
|
+
return path.resolve(__dirname, '../', ...paths);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns task source path or paths
|
|
38
|
+
*
|
|
39
|
+
* @param {string} name Task name
|
|
40
|
+
* @param {...string} paths Additional sub paths
|
|
41
|
+
* @returns {string|array} Task source path or list of paths
|
|
42
|
+
*/
|
|
43
|
+
function getSourcePath (name, ...paths) {
|
|
44
|
+
const pathConfig = getPathConfig();
|
|
45
|
+
const path = pathConfig[name].src;
|
|
46
|
+
|
|
47
|
+
if (typeof path === 'string') {
|
|
48
|
+
return getProjectPath(pathConfig.src, path, ...paths);
|
|
49
|
+
} else if (Array.isArray(path)) {
|
|
50
|
+
return path.map((path) => getProjectPath(pathConfig.src, path, ...paths));
|
|
51
|
+
} else {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns task source paths
|
|
58
|
+
*
|
|
59
|
+
* @param {string} name Task name
|
|
60
|
+
* @param {...string} paths Additional sub paths
|
|
61
|
+
* @returns {array} Task source paths
|
|
62
|
+
*/
|
|
63
|
+
function getSourcePaths (name, ...paths) {
|
|
64
|
+
const path = getSourcePath(name, ...paths);
|
|
65
|
+
|
|
66
|
+
if (typeof path === 'string') {
|
|
67
|
+
return [path];
|
|
68
|
+
} else {
|
|
69
|
+
return path;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns task destination path
|
|
75
|
+
*
|
|
76
|
+
* @param {string} [name] Task name
|
|
77
|
+
* @param {...string} paths Additional sub paths
|
|
78
|
+
* @returns {string} Task destination path
|
|
79
|
+
*/
|
|
80
|
+
function getDestPath (name, ...paths) {
|
|
81
|
+
const pathConfig = getPathConfig();
|
|
82
|
+
|
|
83
|
+
if (name) {
|
|
84
|
+
return getProjectPath(pathConfig.dest, pathConfig[name].dest || '', ...paths);
|
|
85
|
+
} else {
|
|
86
|
+
return getProjectPath(pathConfig.dest);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns public path
|
|
92
|
+
*
|
|
93
|
+
* @param {string} [name] Task name
|
|
94
|
+
* @returns {string} Task public path
|
|
95
|
+
*/
|
|
96
|
+
function getPublicPath (name) {
|
|
97
|
+
const destFullPath = getDestPath(name);
|
|
98
|
+
const destPath = getDestPath();
|
|
99
|
+
return destFullPath.replace(destPath, '') + '/';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
exports.getPathConfig = getPathConfig;
|
|
104
|
+
exports.getSourcePath = getSourcePath;
|
|
105
|
+
exports.getSourcePaths = getSourcePaths;
|
|
106
|
+
exports.getDestPath = getDestPath;
|
|
107
|
+
exports.getProjectPath = getProjectPath;
|
|
108
|
+
exports.getBuilderPath = getBuilderPath;
|
|
109
|
+
exports.getPublicPath = getPublicPath;
|