binhend 2.1.31 → 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.31",
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 { parse } = require('path');
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 =
@@ -23,25 +23,25 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
23
23
  try {
24
24
  makeFullDirPath(fileOutputPath);
25
25
 
26
- var fileExtension = parse(file.name).ext;
27
-
28
- if (fileExtension === '.css') {
26
+ var filename = parseFileName(file.name);
27
+
28
+ if (filename.ext === '.css') {
29
29
  var cssModuleCode = 'binh.css(module);';
30
30
  writeToFileIfNew(fileOutputPath + '.js', cssModuleCode);
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 (fileExtension !== '.js' && fileExtension !== '.cjs' && fileExtension !== '.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;
38
38
  }
39
39
 
40
40
  var fileContent = readFileSync(fileSourcePath, { encoding: 'utf8', flag: 'r' });
41
- var formatCode = mapConfigValues(fileContent.trim()); // for .cjs (common js) and .mjs (module js) files, not build code but still bind config values
41
+ var formatCode = mapConfigValues(fileContent.trim()); // for .c.js files, not build code but still bind config values
42
42
 
43
- if (fileExtension === '.js') {
44
- // for .js files, build code and bind config values
43
+ if (!isExceptedJS(file)) {
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
  }
47
47
 
@@ -0,0 +1,35 @@
1
+
2
+
3
+ const { parse } = require('path');
4
+
5
+ function parseFileName(filename) {
6
+ const parsed = parse(filename);
7
+ const segments = parsed.base.split('.');
8
+
9
+ var ext2 = parsed.ext;
10
+
11
+ if (segments.length >= 3) {
12
+ // last two segments form the level 2 extension
13
+ ext2 = '.' + segments.slice(-2).join('.');
14
+ }
15
+
16
+ return {
17
+ ...parsed,
18
+ ext2,
19
+ };
20
+ }
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
+
31
+ module.exports = {
32
+ parseFileName,
33
+ isAcceptedJS,
34
+ isExceptedJS
35
+ };