binhend 2.3.8 → 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/index.js +3 -3
- package/jsconfig.json +1 -1
- package/package.json +1 -1
- package/packages/config/index.js +1 -0
- package/packages/config/src/process.env.js +45 -0
- package/packages/utils/src/HttpError.js +2 -2
- package/packages/web/src/WebBuild.js +6 -0
- package/packages/web/src/component.build.js +1 -0
package/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const path = require('path');
|
|
|
11
11
|
|
|
12
12
|
//___ Run scripts ___//
|
|
13
13
|
const moduleAlias = require('./packages/module-alias'); // path alias '@' for requiring modules: require('@/any/path') - use jsconfig.json
|
|
14
|
-
moduleAlias.path('@binhend/*', [
|
|
14
|
+
moduleAlias.path('@binhend/*', [path.join(__dirname, './packages')]); // set path alias '@binhend' for all packages to call each others when 'npm install' in another project
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
//___ Load packages ___//
|
|
@@ -30,7 +30,7 @@ const csrf = require('./packages/middlewares/src/csrf');
|
|
|
30
30
|
const trycatch = require('./packages/middlewares/src/trycatch');
|
|
31
31
|
const { Auth } = require('./packages/middlewares/src/authorize');
|
|
32
32
|
|
|
33
|
-
const { config, ConfigLoader } = require('./packages/config
|
|
33
|
+
const { config, ConfigLoader, env } = require('./packages/config');
|
|
34
34
|
|
|
35
35
|
const CSD = require('./packages/csd/src/csd');
|
|
36
36
|
const CinCSD = require('./packages/csd/src/controller');
|
|
@@ -53,7 +53,7 @@ module.exports = {
|
|
|
53
53
|
|
|
54
54
|
cors, csrf, trycatch, Auth,
|
|
55
55
|
|
|
56
|
-
config, ConfigLoader,
|
|
56
|
+
env, config, ConfigLoader,
|
|
57
57
|
|
|
58
58
|
CSD, CinCSD, SinCSD, DinCSD, // only use CSD, others for exposing methods (via IDE auto-suggestion)
|
|
59
59
|
|
package/jsconfig.json
CHANGED
package/package.json
CHANGED
package/packages/config/index.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { cli } = require('./configuration').ConfigLoader;
|
|
4
|
+
const { String } = require('@binhend/validation');
|
|
5
|
+
const { isString } = require('@binhend/types');
|
|
6
|
+
|
|
7
|
+
function Options(options = {}) {
|
|
8
|
+
options = options || {};
|
|
9
|
+
|
|
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);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const localConfigs = require(configModuleFilePath);
|
|
28
|
+
|
|
29
|
+
for (var key in localConfigs) {
|
|
30
|
+
const value = localConfigs[key];
|
|
31
|
+
localConfigs[key] = typeof value === 'string' ? value : JSON.stringify(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
...localConfigs,
|
|
36
|
+
...process.env,
|
|
37
|
+
...cli()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new Error(`Failed loading config from: ${configModuleFilePath}`, { cause: error });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = { env };
|
|
@@ -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
|
}
|