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