binhend 2.3.9 → 2.3.10

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.3.9",
3
+ "version": "2.3.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -2,13 +2,26 @@
2
2
  const path = require('path');
3
3
  const { cli } = require('./configuration').ConfigLoader;
4
4
  const { String } = require('@binhend/validation');
5
+ const { isString } = require('@binhend/types');
5
6
 
6
- function env(env = String(), rootPath = String()) {
7
- rootPath = String(rootPath, { default: require.main.path });
7
+ function Options(options = {}) {
8
+ options = options || {};
8
9
 
9
- const envExtension = typeof env === 'string' ? `.${env}` : '';
10
- const configModuleFileName = `./env${envExtension}`;
11
- const configModuleFilePath = path.resolve(rootPath, configModuleFileName);
10
+ return {
11
+ cli: String(options.cli), // implicitly indicate env extension via a key in CLI configs
12
+ ext: String(options.ext), // explicitly declare env extension, lower priority
13
+ path: String(options.path, { default: require.main.path }), // root path where config module file located
14
+ };
15
+ }
16
+
17
+ function env(options = Options()) {
18
+ options = options || Options();
19
+
20
+ const cliConfigs = cli();
21
+ const env = isString(options.cli) && cliConfigs.hasOwnProperty(options.cli) ? cliConfigs[options.cli] : options.ext;
22
+ const envExtension = String(env, { default: undefined }) ? `.${env}` : '';
23
+ const configModuleFileName = `./env${envExtension}.js`;
24
+ const configModuleFilePath = path.resolve(options.path, configModuleFileName);
12
25
 
13
26
  try {
14
27
  const localConfigs = require(configModuleFilePath);
@@ -25,7 +38,7 @@ function env(env = String(), rootPath = String()) {
25
38
  };
26
39
  }
27
40
  catch (error) {
28
- throw new Error(`[BINHEND][CONFIG] Failed loading config from: ${configModuleFilePath}`, { cause: error });
41
+ throw new Error(`Failed loading config from: ${configModuleFilePath}`, { cause: error });
29
42
  }
30
43
  };
31
44
 
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const express = require('express');
4
4
 
5
5
  const { server } = require('@binhend/core');
6
+ const { config } = require('@binhend/config');
6
7
  const { isEmptyString, isString } = require('@binhend/types');
7
8
  const must = require('@binhend/validation');
8
9
  const moduleAlias = require('@binhend/module-alias');
@@ -57,6 +58,11 @@ function WebBuild(source, { output, external } = {}) {
57
58
  return this;
58
59
  };
59
60
 
61
+ this.bind = (localConfigs = {}) => {
62
+ Object.assign(config, localConfigs);
63
+ return this;
64
+ };
65
+
60
66
  setTimeout(() => {
61
67
  server().use(express.static(web));
62
68
  server().get('/*', (req, res) => res.sendFile('index.html', { root: web }));
@@ -40,6 +40,7 @@ function processEachFile({ source: sourceRootPath, web: outputRootPath, module:
40
40
  var component = require(fileStagePath);
41
41
  }
42
42
  catch (error) {
43
+ console.error('[BINHEND][WEB-BUILD] Failed web component:', fileStagePath);
43
44
  console.error('[BINHEND][WEB-BUILD]', error);
44
45
  return cloneFileIfNew(fileSourcePath, fileOutputPath);
45
46
  }