alemonjs 2.1.13 → 2.1.15
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/lib/app/define-children.d.ts +2 -0
- package/lib/app/define-children.js +19 -0
- package/lib/app/define-pl.ts +0 -0
- package/lib/app/define-platform.d.ts +5 -0
- package/lib/app/define-platform.js +32 -0
- package/lib/app/index.d.ts +2 -1
- package/lib/app/index.js +2 -1
- package/lib/cbp/connects/client.js +1 -1
- package/lib/client.js +1 -1
- package/lib/index.js +2 -1
- package/lib/types/event/base/message.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ResultCode } from '../core/variable.js';
|
|
2
|
+
|
|
3
|
+
const defineChildren = callback => {
|
|
4
|
+
if (typeof callback === 'function' || typeof callback === 'object') {
|
|
5
|
+
return {
|
|
6
|
+
_name: 'app',
|
|
7
|
+
callback
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
logger.error({
|
|
11
|
+
code: ResultCode.FailParams,
|
|
12
|
+
message: 'Invalid callback: callback must be a object or function',
|
|
13
|
+
data: null
|
|
14
|
+
});
|
|
15
|
+
throw new Error('Invalid callback: callback must be a object or function');
|
|
16
|
+
};
|
|
17
|
+
global.defineChildren = defineChildren;
|
|
18
|
+
|
|
19
|
+
export { defineChildren };
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const definePlatform = (options) => {
|
|
2
|
+
const mainProcess = () => {
|
|
3
|
+
['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
|
|
4
|
+
process?.on?.(sig, () => {
|
|
5
|
+
logger.info?.(`[@alemonjs/qq-bot][${sig}] 收到信号,正在关闭...`);
|
|
6
|
+
setImmediate(() => process.exit(0));
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
process?.on?.('exit', code => {
|
|
10
|
+
logger.info?.(`[@alemonjs/qq-bot][exit] 进程退出,code=${code}`);
|
|
11
|
+
});
|
|
12
|
+
process.on('message', msg => {
|
|
13
|
+
try {
|
|
14
|
+
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
15
|
+
if (data?.type === 'start') {
|
|
16
|
+
options.main();
|
|
17
|
+
}
|
|
18
|
+
else if (data?.type === 'stop') {
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
});
|
|
24
|
+
if (process.send) {
|
|
25
|
+
process.send(JSON.stringify({ type: 'ready' }));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
mainProcess();
|
|
29
|
+
return options.main;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { definePlatform };
|
package/lib/app/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './store.js';
|
|
2
2
|
export * from './load_modules/index.js';
|
|
3
|
-
export * from './define-
|
|
3
|
+
export * from './define-children.js';
|
|
4
|
+
export * from './define-platform.js';
|
|
4
5
|
export * from './define-response.js';
|
|
5
6
|
export * from './define-middleware.js';
|
|
6
7
|
export * from './event-group.js';
|
package/lib/app/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { ChildrenApp, Core, Logger, Middleware, MiddlewareRouter, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseMiddleware, ResponseRouter, State, StateSubscribe, SubscribeList, core, logger } from './store.js';
|
|
2
2
|
export { loadModels, run } from './load_modules/load.js';
|
|
3
3
|
export { loadChildren, loadChildrenFile } from './load_modules/loadChild.js';
|
|
4
|
-
export { defineChildren } from './define-
|
|
4
|
+
export { defineChildren } from './define-children.js';
|
|
5
|
+
export { definePlatform } from './define-platform.js';
|
|
5
6
|
export { defineResponse, lazy } from './define-response.js';
|
|
6
7
|
export { defineMiddleware } from './define-middleware.js';
|
|
7
8
|
export { onGroup } from './event-group.js';
|
|
@@ -6,7 +6,7 @@ import 'path';
|
|
|
6
6
|
import 'yaml';
|
|
7
7
|
import { ResultCode } from '../../core/variable.js';
|
|
8
8
|
import '../../app/load_modules/loadChild.js';
|
|
9
|
-
import '../../app/define-
|
|
9
|
+
import '../../app/define-children.js';
|
|
10
10
|
import '../../app/define-response.js';
|
|
11
11
|
import '../../app/define-middleware.js';
|
|
12
12
|
import '../../app/event-group.js';
|
package/lib/client.js
CHANGED
|
@@ -16,7 +16,7 @@ import 'fs/promises';
|
|
|
16
16
|
import './app/store.js';
|
|
17
17
|
import { loadModels } from './app/load_modules/load.js';
|
|
18
18
|
import './app/load_modules/loadChild.js';
|
|
19
|
-
import './app/define-
|
|
19
|
+
import './app/define-children.js';
|
|
20
20
|
import './app/define-response.js';
|
|
21
21
|
import './app/define-middleware.js';
|
|
22
22
|
import './app/event-group.js';
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,8 @@ export { cbpServer } from './cbp/server/main.js';
|
|
|
8
8
|
export { ChildrenApp, Core, Logger, Middleware, MiddlewareRouter, ProcessorEventAutoClearMap, ProcessorEventUserAudoClearMap, Response, ResponseMiddleware, ResponseRouter, State, StateSubscribe, SubscribeList, core, logger } from './app/store.js';
|
|
9
9
|
export { loadModels, run } from './app/load_modules/load.js';
|
|
10
10
|
export { loadChildren, loadChildrenFile } from './app/load_modules/loadChild.js';
|
|
11
|
-
export { defineChildren } from './app/define-
|
|
11
|
+
export { defineChildren } from './app/define-children.js';
|
|
12
|
+
export { definePlatform } from './app/define-platform.js';
|
|
12
13
|
export { defineResponse, lazy } from './app/define-response.js';
|
|
13
14
|
export { defineMiddleware } from './app/define-middleware.js';
|
|
14
15
|
export { onGroup } from './app/event-group.js';
|