@videinfra/static-website-builder 1.4.3 → 1.5.2
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 +12 -0
- package/init/index.js +0 -1
- package/lib/camelize-file-name.js +21 -0
- package/lib/get-file-names.js +23 -0
- package/lib/log-error.js +1 -1
- package/package.json +17 -17
- package/tasks/data/get-data.js +26 -22
- package/tasks/html/task.js +22 -19
- package/tests/camelize-file-name.test.js +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ 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.5.2] - 2022-06-17
|
|
8
|
+
### Updated
|
|
9
|
+
- In build mode prevent data from being read more than once
|
|
10
|
+
|
|
11
|
+
## [1.5.1] - 2022-04-14
|
|
12
|
+
### Fixed
|
|
13
|
+
- Dependency update
|
|
14
|
+
|
|
15
|
+
## [1.5.0] - 2022-04-13
|
|
16
|
+
### Fixed
|
|
17
|
+
- Read files in `data` folder recursively
|
|
18
|
+
|
|
7
19
|
## [1.4.3] - 2022-03-08
|
|
8
20
|
### Fixed
|
|
9
21
|
- Fixed negative glob paths not working
|
package/init/index.js
CHANGED
|
@@ -6,7 +6,6 @@ const folderExists = require('../lib/init/folder-exists');
|
|
|
6
6
|
const getFolderList = require('../lib/init/get-folder-list');
|
|
7
7
|
const chalk = require('chalk');
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
module.exports = function init (template = 'default') {
|
|
11
10
|
let templateName = template || 'default';
|
|
12
11
|
let copyFrom = path.getBuilderPath('init', templateName);
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
package/lib/log-error.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@videinfra/static-website-builder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Customizable static site project builder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"test": "gulp build --silent --config=init/test/config/config.js && jest"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@babel/core": "^7.
|
|
28
|
-
"@babel/preset-env": "^7.
|
|
29
|
-
"autoprefixer": "^9.
|
|
30
|
-
"babel-loader": "^8.2.
|
|
31
|
-
"browser-sync": "^2.
|
|
27
|
+
"@babel/core": "^7.17.9",
|
|
28
|
+
"@babel/preset-env": "^7.16.11",
|
|
29
|
+
"autoprefixer": "^9.8.8",
|
|
30
|
+
"babel-loader": "^8.2.4",
|
|
31
|
+
"browser-sync": "^2.27.9",
|
|
32
32
|
"chalk": "4.0.0",
|
|
33
|
-
"chokidar": "^3.5.
|
|
34
|
-
"cross-env": "^7.0.
|
|
35
|
-
"cssnano": "^4.1.
|
|
36
|
-
"del": "^
|
|
33
|
+
"chokidar": "^3.5.3",
|
|
34
|
+
"cross-env": "^7.0.3",
|
|
35
|
+
"cssnano": "^4.1.11",
|
|
36
|
+
"del": "^6.0.0",
|
|
37
37
|
"gulp": "^4.0.2",
|
|
38
38
|
"gulp-cached": "^1.1.1",
|
|
39
39
|
"gulp-data": "^1.3.1",
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
"gulp-ignore": "^3.0.0",
|
|
44
44
|
"gulp-plumber": "^1.2.1",
|
|
45
45
|
"gulp-postcss": "^8.0.0",
|
|
46
|
-
"gulp-sass": "^4.1.
|
|
46
|
+
"gulp-sass": "^4.1.1",
|
|
47
47
|
"gulp-sizereport": "^1.2.1",
|
|
48
48
|
"gulp-sourcemaps": "^3.0.0",
|
|
49
|
-
"gulp-svgmin": "^
|
|
50
|
-
"gulp-svgstore": "^
|
|
49
|
+
"gulp-svgmin": "^4.1.0",
|
|
50
|
+
"gulp-svgstore": "^9.0.0",
|
|
51
51
|
"gulp-twig": "^1.2.0",
|
|
52
|
-
"minimist": "^1.2.
|
|
53
|
-
"nano-memoize": "^1.
|
|
54
|
-
"webpack": "^4.
|
|
52
|
+
"minimist": "^1.2.6",
|
|
53
|
+
"nano-memoize": "^1.3.0",
|
|
54
|
+
"webpack": "^4.46.0",
|
|
55
55
|
"webpack-stream": "^5.2.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"jest": "^
|
|
58
|
+
"jest": "^27.5.1"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/tasks/data/get-data.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
1
|
const path = require('path');
|
|
3
2
|
const reduce = require('lodash/reduce');
|
|
4
3
|
const micromatch = require('micromatch'); // gulp dependency
|
|
@@ -7,28 +6,11 @@ const merge = require('../../lib/merge');
|
|
|
7
6
|
const getPaths = require('../../lib/get-path');
|
|
8
7
|
const getConfig = require('../../lib/get-config');
|
|
9
8
|
const logError = require('../../lib/log-error');
|
|
9
|
+
const getFileNamesSync = require('../../lib/get-file-names');
|
|
10
|
+
const camelizeFileName = require('../../lib/camelize-file-name');
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Camelize filename
|
|
13
|
-
*
|
|
14
|
-
* @param {string} str File name
|
|
15
|
-
* @returns {string} Camelized name
|
|
16
|
-
*/
|
|
17
|
-
function camelizeFileName (str) {
|
|
18
|
-
return str
|
|
19
|
-
// Remove extension
|
|
20
|
-
.replace(/\.[^.]+$/ig, '')
|
|
21
|
-
// Replace non alpha-numeric characters
|
|
22
|
-
.replace(/[^a-z0-9]/ig, ' ')
|
|
23
|
-
// Uppercase words
|
|
24
|
-
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
25
|
-
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
26
|
-
})
|
|
27
|
-
// Remove empty spaces
|
|
28
|
-
.replace(/\s+/g, '');
|
|
29
|
-
}
|
|
30
12
|
|
|
31
|
-
|
|
13
|
+
function getData () {
|
|
32
14
|
const folders = getPaths.getSourcePaths('data');
|
|
33
15
|
const extensions = getConfig.getTaskConfig('data', 'extensions');
|
|
34
16
|
const loaders = getConfig.getTaskConfig('data', 'loaders');
|
|
@@ -36,7 +18,7 @@ module.exports = function getData () {
|
|
|
36
18
|
const group = getConfig.getTaskConfig('data', 'groupByFileName');
|
|
37
19
|
|
|
38
20
|
const data = reduce(folders, (data, folder) => {
|
|
39
|
-
|
|
21
|
+
getFileNamesSync(folder).forEach(fileName => {
|
|
40
22
|
// Ignore files matching 'ignore' list
|
|
41
23
|
if (ignore.length && micromatch.isMatch(fileName, ignore)) {
|
|
42
24
|
return;
|
|
@@ -81,3 +63,25 @@ module.exports = function getData () {
|
|
|
81
63
|
|
|
82
64
|
return data;
|
|
83
65
|
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
let cache = null;
|
|
69
|
+
|
|
70
|
+
module.exports = function (options) {
|
|
71
|
+
const build = options && !!options.build;
|
|
72
|
+
|
|
73
|
+
return function () {
|
|
74
|
+
if (build) {
|
|
75
|
+
// Cache during full build
|
|
76
|
+
if (!cache) {
|
|
77
|
+
cache = getData();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return cache;
|
|
81
|
+
} else {
|
|
82
|
+
// Don't cache during watch build
|
|
83
|
+
cache = null;
|
|
84
|
+
return getData();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
package/tasks/html/task.js
CHANGED
|
@@ -53,36 +53,39 @@ const getEngine = memoize(function () {
|
|
|
53
53
|
return engine ? engine() : (() => {});
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
+
function html (options) {
|
|
57
|
+
const build = options && !!options.build;
|
|
56
58
|
|
|
57
|
-
function html () {
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
return function html () {
|
|
60
|
+
return gulp.src(getGlobPaths())
|
|
61
|
+
.pipe(taskStart())
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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'))))
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
// Prevent file from being rendered if it's in the ignore list
|
|
68
|
+
.pipe(ignore.exclude(getGlobIgnorePaths(), {}))
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
// Preprocess using TWIG
|
|
71
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), data(getData({ build: build }))))
|
|
72
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), getEngine()))
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
// Minify
|
|
75
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'htmlmin'), htmlmin(getConfig.getTaskConfig('html', 'htmlmin'))))
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
.pipe(taskBeforeDest())
|
|
78
|
+
.pipe(gulp.dest(getPaths.getDestPath('html')))
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
// Reload on change
|
|
81
|
+
.pipe(taskEnd());
|
|
82
|
+
};
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
function htmlWatch () {
|
|
83
|
-
return taskWatch(getWatchGlobPaths(), html);
|
|
86
|
+
return taskWatch(getWatchGlobPaths(), html({ build: false }));
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
|
|
87
|
-
exports.build = html;
|
|
90
|
+
exports.build = html({ build: true });
|
|
88
91
|
exports.watch = htmlWatch;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const camelizeFileName = require('../lib/camelize-file-name');
|
|
2
|
+
|
|
3
|
+
test('Camelize file name', () => {
|
|
4
|
+
expect(camelizeFileName('test-file-name')).toBe('testFileName');
|
|
5
|
+
expect(camelizeFileName('testFileName')).toBe('testFileName');
|
|
6
|
+
expect(camelizeFileName('testFile_name')).toBe('testFileName');
|
|
7
|
+
expect(camelizeFileName('test-file-name.jpg')).toBe('testFileName');
|
|
8
|
+
expect(camelizeFileName('testFileName.jpg')).toBe('testFileName');
|
|
9
|
+
expect(camelizeFileName('test-āēūīķļ-name.jpg.png')).toBe('testName');
|
|
10
|
+
expect(camelizeFileName('.gitignore')).toBe('gitignore');
|
|
11
|
+
});
|