binhend 2.1.4 → 2.1.6

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.4",
3
+ "version": "2.1.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -33,6 +33,10 @@ function isEmptyString(input) {
33
33
  return isString(input) && input.length === 0;
34
34
  }
35
35
 
36
+ function mustString(input) {
37
+ return isString(input) ? input : '';
38
+ }
39
+
36
40
  function isNumber(input) {
37
41
  return typeof input === 'number' || typeOf(input) === 'Number';
38
42
  }
@@ -81,6 +85,7 @@ module.exports = Object.assign(typeOf, {
81
85
  mustNumber,
82
86
  isString,
83
87
  isEmptyString,
88
+ mustString,
84
89
  isSymbol,
85
90
  isBigInt
86
91
  });
package/src/web/index.js CHANGED
@@ -1,24 +1,24 @@
1
1
 
2
2
  const path = require('path');
3
- const { isEmptyString, isString } = require('../utils/typeOf');
3
+ const { isEmptyString, isString, mustString } = require('../utils/typeOf');
4
4
  const ComponentFormat = require('./component.format');
5
5
  const ComponentBuild = require('./component.build');
6
6
  const Component = require('./component');
7
7
  const { server } = require('../server');
8
8
  const express = require('express');
9
9
 
10
- function WebBuilder(source, { output } = {}) {
10
+ function WebBuilder(source, { output, external } = {}) {
11
11
 
12
12
  if (isEmptyString(source)) throw new Error(`[BINHEND][WEB] Require source code location. Current: source: ${source}`);
13
13
 
14
14
  source = path.resolve(source);
15
15
  output = isString(output) ? output : 'build';
16
16
 
17
- if (source === path.resolve(output)) throw new Error(`[BINHEND][WEB] Location of build output & source code should not be the same: ${source}`);
17
+ if (source === path.resolve(output)) throw new Error(`[BINHEND][WEB] Location of build output & source code should NOT be the same: ${source}`);
18
18
 
19
19
  var module = path.resolve(output, 'module');
20
20
  var web = path.resolve(output, 'web');
21
- var external = path.resolve(web, 'NPM');
21
+ var external = mustString(external) || 'NPM';
22
22
 
23
23
  this.bundle = () => {
24
24
  ComponentFormat.generate(source, module, () => ComponentBuild.bundle({ source, web, module }));
@@ -28,6 +28,11 @@ function WebBuilder(source, { output } = {}) {
28
28
  ComponentFormat.generate(source, module, () => ComponentBuild.lazyload({ source, web, module, external }));
29
29
  };
30
30
 
31
+ this.modulify = (outputModulePath) => {
32
+ outputModulePath = isString(outputModulePath) ? path.resolve(outputModulePath) : module;
33
+ ComponentFormat.generate(source, outputModulePath);
34
+ };
35
+
31
36
  this.path = () => {
32
37
  return web;
33
38
  };