@videinfra/static-website-builder 1.4.3 → 1.5.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 CHANGED
@@ -4,6 +4,10 @@ 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.0] - 2022-04-13
8
+ ### Fixed
9
+ - Read files in `data` folder recursively
10
+
7
11
  ## [1.4.3] - 2022-03-08
8
12
  ### Fixed
9
13
  - Fixed negative glob paths not working
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@videinfra/static-website-builder",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "Customizable static site project builder",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -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,26 +6,9 @@ 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
  module.exports = function getData () {
32
14
  const folders = getPaths.getSourcePaths('data');
@@ -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
- fs.readdirSync(folder).forEach(fileName => {
21
+ getFileNamesSync(folder).forEach(fileName => {
40
22
  // Ignore files matching 'ignore' list
41
23
  if (ignore.length && micromatch.isMatch(fileName, ignore)) {
42
24
  return;
@@ -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
+ });