oox 0.3.0-beta9 → 0.3.1
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/LICENSE +21 -21
- package/README.md +29 -32
- package/app.js +131 -143
- package/bin/argv.js +63 -70
- package/bin/cli.js +57 -43
- package/bin/configurer.js +60 -62
- package/bin/loader.mjs +392 -279
- package/bin/proxy-import.js +12 -0
- package/bin/proxy-require.js +88 -0
- package/bin/register.js +46 -55
- package/bin/starter.js +63 -66
- package/index.js +155 -168
- package/index.mjs +4 -4
- package/logger.js +25 -40
- package/modules/http/index.js +234 -192
- package/modules/http/utils.js +74 -73
- package/modules/index.js +86 -88
- package/modules/module.js +11 -16
- package/modules/socketio/client.js +97 -101
- package/modules/socketio/index.js +171 -168
- package/modules/socketio/server.js +188 -136
- package/modules/socketio/socket.js +1 -4
- package/package.json +14 -12
- package/types/app.d.ts +50 -51
- package/types/bin/argv.d.ts +8 -8
- package/types/bin/cli.d.ts +6 -2
- package/types/bin/configurer.d.ts +3 -1
- package/types/bin/proxy-import.d.ts +4 -0
- package/types/bin/proxy-require.d.ts +5 -0
- package/types/bin/register.d.ts +1 -1
- package/types/bin/starter.d.ts +5 -1
- package/types/index.d.ts +78 -76
- package/types/logger.d.ts +5 -4
- package/types/modules/http/index.d.ts +58 -47
- package/types/modules/http/utils.d.ts +14 -17
- package/types/modules/index.d.ts +24 -24
- package/types/modules/module.d.ts +11 -13
- package/types/modules/socketio/client.d.ts +23 -23
- package/types/modules/socketio/index.d.ts +37 -37
- package/types/modules/socketio/server.d.ts +44 -35
- package/types/modules/socketio/socket.d.ts +11 -11
- package/types/utils.d.ts +6 -6
- package/utils.js +57 -63
- package/bin/proxyer.js +0 -61
- package/types/bin/proxyer.d.ts +0 -1
package/bin/configurer.js
CHANGED
|
@@ -1,62 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
exports.configure = configure;
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as argv from './argv.js';
|
|
4
|
+
/**
|
|
5
|
+
* x.y=1 => { x: { y: 1 } }
|
|
6
|
+
*/
|
|
7
|
+
function mergeFlatEnv(env) {
|
|
8
|
+
for (const key of Object.keys(env)) {
|
|
9
|
+
// x.y.z
|
|
10
|
+
if (key.includes('.') && !key.startsWith('.') && !key.endsWith('.')) {
|
|
11
|
+
const subKeys = key.split('.');
|
|
12
|
+
const valueKey = subKeys.pop() || '';
|
|
13
|
+
let tmpEnv = env;
|
|
14
|
+
for (const subKey of subKeys) {
|
|
15
|
+
if (subKey in tmpEnv) { }
|
|
16
|
+
else {
|
|
17
|
+
tmpEnv[subKey] = {};
|
|
18
|
+
}
|
|
19
|
+
tmpEnv = tmpEnv[subKey];
|
|
20
|
+
}
|
|
21
|
+
tmpEnv[valueKey] = env[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function readEnvFile(filePath) {
|
|
26
|
+
let env = {};
|
|
27
|
+
if (filePath && fs.existsSync(filePath)) {
|
|
28
|
+
if (filePath.endsWith('.json')) {
|
|
29
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
30
|
+
env = JSON.parse(raw);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const finalPath = path.resolve(filePath).replace(/\\/g, '/');
|
|
34
|
+
env = await import(`file://${finalPath}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('Env file not found: ' + filePath);
|
|
39
|
+
}
|
|
40
|
+
return env.default || env;
|
|
41
|
+
}
|
|
42
|
+
export async function buildConfig(mergeEnv) {
|
|
43
|
+
const env = Object.create(null);
|
|
44
|
+
const defaultEnvPath = argv.getEnvArg('default-env');
|
|
45
|
+
const targetEnvPath = argv.getEnvArg('env');
|
|
46
|
+
const defaultEnv = defaultEnvPath ? await readEnvFile(defaultEnvPath) : {};
|
|
47
|
+
const targetEnv = targetEnvPath ? await readEnvFile(targetEnvPath) : {};
|
|
48
|
+
Object.assign(env, defaultEnv, targetEnv, argv.getAllEnvArgs());
|
|
49
|
+
mergeFlatEnv(env);
|
|
50
|
+
if ('string' === typeof env.ignore)
|
|
51
|
+
env.ignore = env.ignore.split(',');
|
|
52
|
+
if ('string' === typeof env.registry)
|
|
53
|
+
env.registry = env.registry.split(',');
|
|
54
|
+
if ('string' === typeof env.origin && env.origin.includes(',')) {
|
|
55
|
+
env.origin = env.origin.split(',');
|
|
56
|
+
}
|
|
57
|
+
if (mergeEnv)
|
|
58
|
+
Object.assign(env, mergeEnv);
|
|
59
|
+
return env;
|
|
60
|
+
}
|