binhend 2.1.34 → 2.1.36

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/index.js CHANGED
@@ -28,7 +28,7 @@ const typedefs = require('./src/utils/typedefs');
28
28
  const Bromise = require('./src/utils/Bromise.js');
29
29
 
30
30
  /** CLIENT - Frontend */
31
- const { WebBuilder } = require('./src/web');
31
+ const { WebBuild } = require('./src/web');
32
32
  const { binh } = require('./src/web/component.method');
33
33
 
34
34
  // Run scripts
@@ -50,6 +50,7 @@ module.exports = {
50
50
  typedefs,
51
51
  validation,
52
52
  Bromise,
53
- WebBuilder,
53
+ WebBuild,
54
+ WebBuilder: WebBuild,
54
55
  binh
55
56
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.34",
3
+ "version": "2.1.36",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -20,19 +20,24 @@ function processEachFile({ source: sourceRootPath, web: outputRootPath, module:
20
20
  scanNestedFiles(stageRootPath, (file, done) => {
21
21
  if (done) return callbackDone instanceof Function ? callbackDone({ outputRootPath }) : null;
22
22
 
23
- var fileSourcePath = file.path.replace(stageRootPath, sourceRootPath);
24
- var fileOutputPath = file.path.replace(stageRootPath, outputRootPath);
23
+ var fileStagePath = file.path;
24
+ var fileSourcePath = fileStagePath.replace(stageRootPath, sourceRootPath);
25
+ var fileOutputPath = fileStagePath.replace(stageRootPath, outputRootPath);
25
26
 
26
27
  makeFullDirPath(fileOutputPath);
27
28
 
28
29
  var filename = parseFileName(file.name);
29
30
 
30
- if (!isAcceptedJS(filename) || isExceptedJS(filename)) {
31
+ if (!isAcceptedJS(filename)) { // if not JavaScript file (.js .cjs .mjs) => copy file from source path
31
32
  return cloneFileIfNew(fileSourcePath, fileOutputPath);
32
33
  }
33
34
 
35
+ if (isExceptedJS(filename)) { // if JavaScript file is .c.js (exceptional file) => copy file from module path (stage path)
36
+ return cloneFileIfNew(fileStagePath, fileOutputPath);
37
+ }
38
+
34
39
  try {
35
- var component = require(file.path);
40
+ var component = require(fileStagePath);
36
41
  }
37
42
  catch (error) {
38
43
  console.error('[BINHEND][WEB-BUILD]', error);
package/src/web/index.js CHANGED
@@ -8,32 +8,40 @@ const Component = require('./component');
8
8
  const { server } = require('../server');
9
9
  const express = require('express');
10
10
 
11
- function WebBuilder(source, { output, external } = {}) {
11
+ const DEFAULT_DIR_BUILD = 'build';
12
+ const DEFAULT_DIR_BUILD_WEB = 'web';
13
+ const DEFAULT_DIR_BUILD_MODULE = 'module';
14
+ const DEFAULT_DIR_BUILD_EXTERNAL = 'NPM';
15
+
16
+ function WebBuild(source, { output, external } = {}) {
12
17
 
13
18
  if (isEmptyString(source)) throw new Error(`[BINHEND][WEB] Require source code location. Current: source: ${source}`);
14
19
 
15
20
  source = path.resolve(source);
16
- output = isString(output) ? output : 'build';
21
+ output = isString(output) ? output : DEFAULT_DIR_BUILD;
17
22
 
18
23
  if (source === path.resolve(output)) throw new Error(`[BINHEND][WEB] Location of build output & source code should NOT be the same: ${source}`);
19
24
 
20
- var module = path.resolve(output, 'module');
21
- var web = path.resolve(output, 'web');
22
- var external = mustString(external) || 'NPM';
25
+ var module = path.resolve(output, DEFAULT_DIR_BUILD_MODULE);
26
+ var web = path.resolve(output, DEFAULT_DIR_BUILD_MODULE);
27
+ var external = mustString(external) || DEFAULT_DIR_BUILD_EXTERNAL;
23
28
 
24
29
  this.bundle = () => {
25
30
  Component.isLazy = false;
26
31
  ComponentFormat.generate(source, module, () => ComponentBuild.bundle({ source, web, module }));
32
+ return this;
27
33
  };
28
34
 
29
35
  this.lazy = () => {
30
36
  Component.isLazy = true;
31
37
  ComponentFormat.generate(source, module, () => ComponentBuild.lazyload({ source, web, module, external }));
38
+ return this;
32
39
  };
33
40
 
34
41
  this.modulify = (outputModulePath) => {
35
42
  outputModulePath = isString(outputModulePath) ? path.resolve(outputModulePath) : module;
36
43
  ComponentFormat.generate(source, outputModulePath);
44
+ return this;
37
45
  };
38
46
 
39
47
  this.path = () => {
@@ -42,6 +50,7 @@ function WebBuilder(source, { output, external } = {}) {
42
50
 
43
51
  this.minify = (flag = true) => {
44
52
  Component.minification = flag;
53
+ return this;
45
54
  };
46
55
 
47
56
  setTimeout(() => {
@@ -55,5 +64,5 @@ function WebBuilder(source, { output, external } = {}) {
55
64
  }
56
65
 
57
66
  module.exports = {
58
- WebBuilder
67
+ WebBuild
59
68
  };