binhend 2.3.9 → 2.3.11
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
|
@@ -2,31 +2,45 @@
|
|
|
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
|
|
7
|
-
|
|
7
|
+
function Options(options = {}) {
|
|
8
|
+
options = options || {};
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
const localConfigs = {};
|
|
12
26
|
|
|
13
27
|
try {
|
|
14
|
-
const
|
|
28
|
+
const fileConfigs = require(configModuleFilePath);
|
|
15
29
|
|
|
16
|
-
for (var key in
|
|
17
|
-
const value =
|
|
30
|
+
for (var key in fileConfigs) {
|
|
31
|
+
const value = fileConfigs[key];
|
|
18
32
|
localConfigs[key] = typeof value === 'string' ? value : JSON.stringify(value);
|
|
19
33
|
}
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
...localConfigs,
|
|
23
|
-
...process.env,
|
|
24
|
-
...cli()
|
|
25
|
-
};
|
|
26
34
|
}
|
|
27
35
|
catch (error) {
|
|
28
|
-
|
|
36
|
+
console.log(`[BINHEND][CONFIG] No config file: ${configModuleFilePath}`);
|
|
29
37
|
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...localConfigs,
|
|
41
|
+
...process.env,
|
|
42
|
+
...cli()
|
|
43
|
+
};
|
|
30
44
|
};
|
|
31
45
|
|
|
32
46
|
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
|
}
|