binhend 2.1.32 → 2.1.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.32",
3
+ "version": "2.1.33",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -1,6 +1,7 @@
1
1
  // @ts-nocheck
2
2
 
3
3
  const path = require('path');
4
+ const { parseFileName, isAcceptedJS, isExceptedJS } = require('./file-check');
4
5
  const { scanNestedFiles, cloneFileIfNew, writeToFileIfNew, makeFullDirPath } = require('./component.file');
5
6
  const CodeFormat = require('./code');
6
7
  const Component = require('./component');
@@ -24,7 +25,9 @@ function processEachFile({ source: sourceRootPath, web: outputRootPath, module:
24
25
 
25
26
  makeFullDirPath(fileOutputPath);
26
27
 
27
- if (path.parse(file.name).ext !== '.js') {
28
+ var filename = parseFileName(file.name);
29
+
30
+ if (!isAcceptedJS(filename) || isExceptedJS(filename)) {
28
31
  return cloneFileIfNew(fileSourcePath, fileOutputPath);
29
32
  }
30
33
 
@@ -32,7 +35,7 @@ function processEachFile({ source: sourceRootPath, web: outputRootPath, module:
32
35
  var component = require(file.path);
33
36
  }
34
37
  catch (error) {
35
- if (path.parse(file.name).ext === '.js') console.error('[BINHEND][WEB-BUILD]', error);
38
+ console.error('[BINHEND][WEB-BUILD]', error);
36
39
  return cloneFileIfNew(fileSourcePath, fileOutputPath);
37
40
  }
38
41
 
@@ -1,6 +1,6 @@
1
1
  const { config } = require('../configuration');
2
2
  const { readFileSync } = require('fs');
3
- const { parseFileName } = require('./filename-parser');
3
+ const { parseFileName, isAcceptedJS, isExceptedJS } = require('./file-check');
4
4
  const { scanNestedFiles, cloneFileIfNew, printError, makeFullDirPath, writeToFileIfNew } = require('./component.file');
5
5
 
6
6
  const PREFIX_CODE =
@@ -31,7 +31,7 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
31
31
  // not return here, but wait for next "if" statement to be copied to build folder, then return there.
32
32
  }
33
33
 
34
- if (filename.ext !== '.js' && filename.ext !== '.cjs' && filename.ext !== '.mjs') {
34
+ if (!isAcceptedJS(filename)) {
35
35
  // any files not JS (.css, .jpg, etc.) will be copied to build folder.
36
36
  cloneFileIfNew(fileSourcePath, fileOutputPath);
37
37
  return;
@@ -40,7 +40,7 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
40
40
  var fileContent = readFileSync(fileSourcePath, { encoding: 'utf8', flag: 'r' });
41
41
  var formatCode = mapConfigValues(fileContent.trim()); // for .c.js files, not build code but still bind config values
42
42
 
43
- if (filename.ext2 !== '.c.js') {
43
+ if (!isExceptedJS(file)) {
44
44
  // except for .c.js files, build code and bind config values for other JS files (.js, .cjs, .mjs)
45
45
  formatCode = PREFIX_CODE + formatCode + '\r\n\r\n;binh.final(module);';
46
46
  }
@@ -19,6 +19,17 @@ function parseFileName(filename) {
19
19
  };
20
20
  }
21
21
 
22
+ function isAcceptedJS(parsedFileName) {
23
+ const fileExtension = parsedFileName.ext;
24
+ return fileExtension === '.js' || fileExtension === '.cjs' || fileExtension === '.mjs';
25
+ }
26
+
27
+ function isExceptedJS(parseFileName) {
28
+ return parseFileName.ext2 === '.c.js';
29
+ }
30
+
22
31
  module.exports = {
23
- parseFileName
32
+ parseFileName,
33
+ isAcceptedJS,
34
+ isExceptedJS
24
35
  };