ee-core 4.0.0-beta.1 → 4.0.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/app/application.d.ts +5 -0
- package/app/boot.d.ts +5 -0
- package/app/boot.js +0 -7
- package/app/dir.d.ts +1 -0
- package/app/events.d.ts +14 -0
- package/app/index.d.ts +2 -0
- package/config/config_loader.d.ts +13 -0
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +2 -1
- package/config/index.d.ts +28 -0
- package/const/channel.d.ts +16 -0
- package/const/channel.js +1 -1
- package/controller/controller_loader.d.ts +9 -0
- package/controller/index.d.ts +2 -0
- package/core/index.d.ts +2 -0
- package/core/loader/file_loader.d.ts +66 -0
- package/core/utils/index.d.ts +12 -0
- package/core/utils/timing.d.ts +22 -0
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +5 -5
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +12 -7
- package/cross/index.d.ts +2 -0
- package/cross/index.js +2 -2
- package/electron/app/index.d.ts +5 -0
- package/electron/index.d.ts +3 -0
- package/electron/window/index.d.ts +6 -0
- package/exception/index.d.ts +9 -0
- package/exception/index.js +8 -22
- package/html/index.d.ts +1 -0
- package/index.d.ts +2 -0
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +2 -2
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +3 -18
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +13 -38
- package/jobs/index.d.ts +3 -0
- package/jobs/load-balancer/algorithm/index.d.ts +4 -0
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/random.d.ts +2 -0
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
- package/jobs/load-balancer/consts.d.ts +8 -0
- package/jobs/load-balancer/index.d.ts +96 -0
- package/jobs/load-balancer/scheduler.d.ts +16 -0
- package/loader/index.d.ts +9 -0
- package/loader/index.js +4 -22
- package/log/index.d.ts +5 -0
- package/log/logger.d.ts +2 -0
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +2 -12
- package/message/index.d.ts +3 -0
- package/package.json +8 -1
- package/ps/index.d.ts +37 -0
- package/ps/index.js +2 -12
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +10 -3
- package/socket/index.d.ts +10 -0
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +13 -6
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +7 -2
- package/storage/index.d.ts +5 -0
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +2 -2
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +1 -11
- package/utils/index.d.ts +10 -0
- package/utils/index.js +7 -17
- package/utils/ip.d.ts +2 -0
- package/utils/is.d.ts +14 -0
- package/utils/json.d.ts +5 -0
- package/utils/pargv.d.ts +3 -0
- package/utils/port/index.d.ts +1 -0
- package/utils/wrap.d.ts +4 -0
- package/const/index.js +0 -5
package/app/boot.d.ts
ADDED
package/app/boot.js
CHANGED
|
@@ -9,14 +9,12 @@ const { loadConfig } = require('../config');
|
|
|
9
9
|
const { loadLog } = require('../log');
|
|
10
10
|
const { app } = require('./application');
|
|
11
11
|
const { loadDir } = require('./dir');
|
|
12
|
-
// const { isJsProject } = require('../utils');
|
|
13
12
|
|
|
14
13
|
class ElectronEgg {
|
|
15
14
|
constructor() {
|
|
16
15
|
const baseDir = electronApp.getAppPath();
|
|
17
16
|
const { env } = process;
|
|
18
17
|
const environmet = getArgumentByName('env') || 'prod';
|
|
19
|
-
console.log('argv:', process.argv);
|
|
20
18
|
|
|
21
19
|
const options = {
|
|
22
20
|
env: environmet,
|
|
@@ -36,11 +34,6 @@ class ElectronEgg {
|
|
|
36
34
|
options.execDir = path.dirname(electronApp.getPath('exe'));
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
// js开发环境使用源码目录
|
|
40
|
-
// if (isJsProject(baseDir) && environmet !== 'prod' ) {
|
|
41
|
-
// options.electronDir = path.join(baseDir, 'electron');
|
|
42
|
-
// }
|
|
43
|
-
|
|
44
37
|
// normalize env
|
|
45
38
|
env.EE_ENV = environmet;
|
|
46
39
|
env.EE_APP_NAME = options.appName;
|
package/app/dir.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadDir(): void;
|
package/app/events.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class EventBus {
|
|
2
|
+
lifecycleEvents: {};
|
|
3
|
+
eventsMap: {};
|
|
4
|
+
register(eventName: string, handler: Function): void;
|
|
5
|
+
emitLifecycle(eventName: string, ...args: any[]): void;
|
|
6
|
+
on(eventName: string, handler: Function): void;
|
|
7
|
+
emit(eventName: string, ...args: any[]): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const eventBus: EventBus;
|
|
10
|
+
export declare const Ready: "ready";
|
|
11
|
+
export declare const ElectronAppReady: "electron-app-ready";
|
|
12
|
+
export declare const WindowReady: "window-ready";
|
|
13
|
+
export declare const Preload: "preload";
|
|
14
|
+
export declare const BeforeClose: "before-close";
|
package/app/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Timing } from "../core/utils/timing";
|
|
2
|
+
import { EEConfig } from "./default_config";
|
|
3
|
+
export declare class ConfigLoader {
|
|
4
|
+
timing: Timing;
|
|
5
|
+
/**
|
|
6
|
+
* Load config/config.xxx.js
|
|
7
|
+
*/
|
|
8
|
+
load(): EEConfig;
|
|
9
|
+
_AppConfig(): EEConfig;
|
|
10
|
+
_loadConfig(dirpath: string, filename: string): EEConfig;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { BrowserWindowConstructorOptions } from 'electron';
|
|
2
|
+
|
|
3
|
+
export declare interface AppConfig {
|
|
4
|
+
openDevTools?: boolean | Object;
|
|
5
|
+
singleLock?: boolean;
|
|
6
|
+
windowsOption?: BrowserWindowConstructorOptions;
|
|
7
|
+
logger?: LoggerConfig;
|
|
8
|
+
socketServer?: SocketConfig;
|
|
9
|
+
httpServer?: HttpConfig;
|
|
10
|
+
remote?: RemoteConfig;
|
|
11
|
+
mainServer?: MainConfig;
|
|
12
|
+
exception?: ExceptionConfig;
|
|
13
|
+
job?: JobConfig;
|
|
14
|
+
cross?: CrossConfig;
|
|
15
|
+
}
|
|
16
|
+
export declare interface LoggerConfig {
|
|
17
|
+
type?: string;
|
|
18
|
+
dir?: string;
|
|
19
|
+
encoding?: string;
|
|
20
|
+
env?: string;
|
|
21
|
+
level?: string;
|
|
22
|
+
consoleLevel?: string;
|
|
23
|
+
disableConsoleAfterReady?: boolean;
|
|
24
|
+
outputJSON?: boolean;
|
|
25
|
+
buffer?: boolean;
|
|
26
|
+
appLogName: string;
|
|
27
|
+
coreLogName?: string;
|
|
28
|
+
agentLogName?: string;
|
|
29
|
+
errorLogName: string;
|
|
30
|
+
coreLogger?: {};
|
|
31
|
+
allowDebugAtProd?: boolean;
|
|
32
|
+
enablePerformanceTimer?: boolean;
|
|
33
|
+
rotator?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare interface SocketConfig {
|
|
36
|
+
enable: boolean;
|
|
37
|
+
port: number;
|
|
38
|
+
path?: string;
|
|
39
|
+
connectTimeout?: number;
|
|
40
|
+
pingTimeout?: number;
|
|
41
|
+
pingInterval?: number;
|
|
42
|
+
maxHttpBufferSize?: number;
|
|
43
|
+
transports?: string[];
|
|
44
|
+
cors?: {
|
|
45
|
+
origin?: boolean;
|
|
46
|
+
};
|
|
47
|
+
channel?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare interface HttpConfig {
|
|
50
|
+
enable: boolean;
|
|
51
|
+
https?: {
|
|
52
|
+
enable: boolean;
|
|
53
|
+
key: string;
|
|
54
|
+
cert: string;
|
|
55
|
+
};
|
|
56
|
+
protocol?: string;
|
|
57
|
+
host?: string;
|
|
58
|
+
port: number;
|
|
59
|
+
cors?: {
|
|
60
|
+
origin?: string;
|
|
61
|
+
};
|
|
62
|
+
body?: {
|
|
63
|
+
multipart?: boolean;
|
|
64
|
+
formidable?: {
|
|
65
|
+
keepExtensions?: boolean;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
filterRequest?: {
|
|
69
|
+
uris?: string[];
|
|
70
|
+
returnData?: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export declare interface RemoteConfig {
|
|
74
|
+
enable: boolean;
|
|
75
|
+
url: string;
|
|
76
|
+
}
|
|
77
|
+
export declare interface MainConfig {
|
|
78
|
+
protocol?: string;
|
|
79
|
+
indexPath: string;
|
|
80
|
+
options?: {};
|
|
81
|
+
takeover?: string;
|
|
82
|
+
loadingPage?: string;
|
|
83
|
+
channelSeparator?: string;
|
|
84
|
+
}
|
|
85
|
+
export declare interface ExceptionConfig {
|
|
86
|
+
mainExit?: boolean;
|
|
87
|
+
childExit?: boolean;
|
|
88
|
+
rendererExit?: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare interface JobConfig {
|
|
91
|
+
messageLog: boolean;
|
|
92
|
+
}
|
|
93
|
+
export declare interface CrossConfig {}
|
|
94
|
+
declare function config(): AppConfig;
|
|
95
|
+
export = config;
|
package/config/default_config.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppConfig,
|
|
3
|
+
WindowsConfig,
|
|
4
|
+
LoggerConfig,
|
|
5
|
+
SocketConfig,
|
|
6
|
+
HttpConfig,
|
|
7
|
+
RemoteConfig,
|
|
8
|
+
MainConfig,
|
|
9
|
+
ExceptionConfig,
|
|
10
|
+
JobConfig,
|
|
11
|
+
CrossConfig
|
|
12
|
+
} from "./default_config";
|
|
13
|
+
declare function loadConfig(): AppConfig;
|
|
14
|
+
declare function getConfig(): AppConfig;
|
|
15
|
+
export {
|
|
16
|
+
AppConfig,
|
|
17
|
+
WindowsConfig,
|
|
18
|
+
LoggerConfig,
|
|
19
|
+
SocketConfig,
|
|
20
|
+
HttpConfig,
|
|
21
|
+
RemoteConfig,
|
|
22
|
+
MainConfig,
|
|
23
|
+
ExceptionConfig,
|
|
24
|
+
JobConfig,
|
|
25
|
+
CrossConfig,
|
|
26
|
+
loadConfig,
|
|
27
|
+
getConfig
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare namespace Processes {
|
|
2
|
+
let showException: string;
|
|
3
|
+
let sendToMain: string;
|
|
4
|
+
}
|
|
5
|
+
export declare namespace SocketIO {
|
|
6
|
+
let partySoftware: string;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace Events {
|
|
9
|
+
let childProcessExit: string;
|
|
10
|
+
let childProcessError: string;
|
|
11
|
+
}
|
|
12
|
+
export declare namespace Receiver {
|
|
13
|
+
let childJob: string;
|
|
14
|
+
let forkProcess: string;
|
|
15
|
+
let all: string;
|
|
16
|
+
}
|
package/const/channel.js
CHANGED
package/core/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load files from directory to target object.
|
|
3
|
+
*/
|
|
4
|
+
export declare class FileLoader {
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
* @param {Object} options - options
|
|
8
|
+
* @param {String|Array} options.directory - directories to be loaded
|
|
9
|
+
* @param {Object} options.target - attach the target object from loaded files
|
|
10
|
+
* @param {String} options.match - match the files when load, support glob, default to all js files
|
|
11
|
+
* @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
|
|
12
|
+
* @param {Boolean} options.call - determine whether invoke when exports is function
|
|
13
|
+
* @param {Object} options.inject - an object that be the argument when invoke the function
|
|
14
|
+
* @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options: {
|
|
17
|
+
directory: string | any[];
|
|
18
|
+
target: any;
|
|
19
|
+
match: string;
|
|
20
|
+
initializer: Function;
|
|
21
|
+
call: boolean;
|
|
22
|
+
inject: any;
|
|
23
|
+
caseStyle: string | Function;
|
|
24
|
+
});
|
|
25
|
+
options: {
|
|
26
|
+
directory: any;
|
|
27
|
+
target: any;
|
|
28
|
+
match: any;
|
|
29
|
+
caseStyle: string;
|
|
30
|
+
initializer: any;
|
|
31
|
+
call: boolean;
|
|
32
|
+
inject: any;
|
|
33
|
+
} & {
|
|
34
|
+
directory: string | any[];
|
|
35
|
+
target: any;
|
|
36
|
+
match: string;
|
|
37
|
+
initializer: Function;
|
|
38
|
+
call: boolean;
|
|
39
|
+
inject: any;
|
|
40
|
+
caseStyle: string | Function;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* attach items to target object. Mapping the directory to properties.
|
|
44
|
+
* `xxx/group/repository.js` => `target.group.repository`
|
|
45
|
+
* @return {Object} target
|
|
46
|
+
*/
|
|
47
|
+
load(): any;
|
|
48
|
+
/**
|
|
49
|
+
* Parse files from given directories, then return an items list, each item contains properties and exports.
|
|
50
|
+
* For example, parse `controller/group/repository.js`
|
|
51
|
+
* It returns a item
|
|
52
|
+
* ```
|
|
53
|
+
* {
|
|
54
|
+
* fullpath: '',
|
|
55
|
+
* properties: [ 'group', 'repository' ],
|
|
56
|
+
* exports: { ... },
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
* `Properties` is an array that contains the directory of a filepath.
|
|
60
|
+
* `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.
|
|
61
|
+
* @return {Array} items
|
|
62
|
+
*/
|
|
63
|
+
parse(): any[];
|
|
64
|
+
}
|
|
65
|
+
export declare const EXPORTS: unique symbol;
|
|
66
|
+
export declare const FULLPATH: unique symbol;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const extensions: any;
|
|
2
|
+
export declare function loadFile(filepath: any): any;
|
|
3
|
+
export declare function callFn(fn: any, args: any, ctx: any): Promise<any>;
|
|
4
|
+
export declare function getResolvedFilename(filepath: any, baseDir: any): any;
|
|
5
|
+
/**
|
|
6
|
+
* 字节码类
|
|
7
|
+
*/
|
|
8
|
+
export declare function isBytecodeClass(exports: any): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 文件类型
|
|
11
|
+
*/
|
|
12
|
+
export declare function filePatterns(): string[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class Timing {
|
|
2
|
+
_enable: boolean;
|
|
3
|
+
init(): void;
|
|
4
|
+
start(name: any, start: any): {
|
|
5
|
+
name: any;
|
|
6
|
+
start: any;
|
|
7
|
+
end: any;
|
|
8
|
+
duration: any;
|
|
9
|
+
pid: number;
|
|
10
|
+
index: number;
|
|
11
|
+
};
|
|
12
|
+
end(name: any): any;
|
|
13
|
+
enable(): void;
|
|
14
|
+
disable(): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
toJSON(): any[];
|
|
17
|
+
[MAP]: Map<any, any>;
|
|
18
|
+
[LIST]: any[];
|
|
19
|
+
}
|
|
20
|
+
declare const MAP: unique symbol;
|
|
21
|
+
declare const LIST: unique symbol;
|
|
22
|
+
export {};
|
package/cross/cross.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { CrossProcess } from "./crossProcess";
|
|
3
|
+
import internal = require("stream");
|
|
4
|
+
export declare class Cross {
|
|
5
|
+
emitter: EventEmitter<[never]>;
|
|
6
|
+
children: {};
|
|
7
|
+
childrenMap: {};
|
|
8
|
+
create(): Promise<void>;
|
|
9
|
+
run(service: string, opt?: {}): Promise<CrossProcess>;
|
|
10
|
+
killAll(): void;
|
|
11
|
+
kill(pid: string|number): void;
|
|
12
|
+
killByName(name: string): void;
|
|
13
|
+
getUrl(name: string): string;
|
|
14
|
+
getProcByName(name: string): CrossProcess;
|
|
15
|
+
getProc(pid: string|number): CrossProcess;
|
|
16
|
+
getPids(): string[];
|
|
17
|
+
_initEventEmitter(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare let cross: Cross;
|
package/cross/cross.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
const { getConfig } = require('../config');
|
|
5
5
|
const { sleep, getValueFromArgv, replaceArgsValue } = require('../utils/helper');
|
|
6
|
-
const {
|
|
6
|
+
const { CrossProcess } = require('./crossProcess');
|
|
7
7
|
const { Events } = require('../const/channel');
|
|
8
8
|
const { extend } = require('../utils/extend');
|
|
9
9
|
const { getPort } = require('../utils/port');
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class Cross {
|
|
12
12
|
constructor() {
|
|
13
13
|
this.emitter = undefined;
|
|
14
14
|
|
|
@@ -62,7 +62,7 @@ class CrossProcess {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// 创建进程
|
|
65
|
-
const subProcess = new
|
|
65
|
+
const subProcess = new CrossProcess(this, { targetConf, port: confPort });
|
|
66
66
|
let uniqueName = targetConf.name;
|
|
67
67
|
if (this.childrenMap.hasOwnProperty(uniqueName)) {
|
|
68
68
|
uniqueName = uniqueName + "-" + String(subProcess.pid);
|
|
@@ -147,6 +147,6 @@ class CrossProcess {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
module.exports = {
|
|
150
|
-
|
|
151
|
-
cross: new
|
|
150
|
+
Cross,
|
|
151
|
+
cross: new Cross()
|
|
152
152
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import EventEmitter = require("events");
|
|
2
|
+
export declare class CrossProcess {
|
|
3
|
+
constructor(host: any, opt?: {});
|
|
4
|
+
emitter: EventEmitter<[never]>;
|
|
5
|
+
host: any;
|
|
6
|
+
child: any;
|
|
7
|
+
pid: number;
|
|
8
|
+
port: number;
|
|
9
|
+
name: string;
|
|
10
|
+
config: {};
|
|
11
|
+
/**
|
|
12
|
+
* 初始化子进程
|
|
13
|
+
*/
|
|
14
|
+
_init(options?: {}): void;
|
|
15
|
+
/**
|
|
16
|
+
* kill
|
|
17
|
+
*/
|
|
18
|
+
kill(timeout?: number): void;
|
|
19
|
+
getUrl(): string;
|
|
20
|
+
getArgsObj(): {
|
|
21
|
+
_: any[];
|
|
22
|
+
};
|
|
23
|
+
setPort(port: string|number): void;
|
|
24
|
+
_generateId(): string;
|
|
25
|
+
/**
|
|
26
|
+
* exit electron
|
|
27
|
+
*/
|
|
28
|
+
_exitElectron(timeout?: number): void;
|
|
29
|
+
}
|
|
@@ -10,8 +10,9 @@ const { getRandomString, getValueFromArgv } = require('../utils/helper');
|
|
|
10
10
|
const { is } = require('../utils');
|
|
11
11
|
const { parseArgv } = require('../utils/pargv');
|
|
12
12
|
const { app: electronApp } = require('electron');
|
|
13
|
+
const tkill = require('tree-kill');
|
|
13
14
|
|
|
14
|
-
class
|
|
15
|
+
class CrossProcess {
|
|
15
16
|
constructor(host, opt = {}) {
|
|
16
17
|
this.emitter = new EventEmitter();
|
|
17
18
|
this.host = host;
|
|
@@ -116,11 +117,15 @@ class SpawnProcess {
|
|
|
116
117
|
* kill
|
|
117
118
|
*/
|
|
118
119
|
kill(timeout = 1000) {
|
|
119
|
-
this.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
tkill(this.pid, 'SIGINT', (err) => {
|
|
121
|
+
if (err) {
|
|
122
|
+
coreLogger.error(`[ee-core] [corss/process] kill cross-process, error: ${err}, pid:${this.pid}`);
|
|
123
|
+
tkill(this.pid, 'SIGKILL');
|
|
124
|
+
}
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
this._exitElectron();
|
|
127
|
+
}, timeout)
|
|
128
|
+
})
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
getUrl() {
|
|
@@ -164,5 +169,5 @@ class SpawnProcess {
|
|
|
164
169
|
}
|
|
165
170
|
|
|
166
171
|
module.exports = {
|
|
167
|
-
|
|
172
|
+
CrossProcess
|
|
168
173
|
};
|
package/cross/index.d.ts
ADDED
package/cross/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getMainWindow(): any;
|
|
2
|
+
export declare function createMainWindow(): any;
|
|
3
|
+
export declare function restoreMainWindow(): void;
|
|
4
|
+
export declare function setCloseAndQuit(flag: any): void;
|
|
5
|
+
export declare function getCloseAndQuit(): boolean;
|
|
6
|
+
export declare function loadServer(): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Capture exceptions
|
|
2
|
+
export declare function loadException(): void;
|
|
3
|
+
// When an exception is thrown on a process without being caught, trigger the event and silence the exception
|
|
4
|
+
export declare function uncaughtExceptionHandler(): void;
|
|
5
|
+
// When the reject exception in the promise is not caught using catch in the synchronization task, it will trigger the event,
|
|
6
|
+
// Even if catch is used in asynchronous situations, it will trigger the event
|
|
7
|
+
export declare function unhandledRejectionHandler(): void;
|
|
8
|
+
// This event is triggered when an exception is thrown on the process without being caught.
|
|
9
|
+
export declare function uncaughtExceptionMonitorHandler(): void;
|
package/exception/index.js
CHANGED
|
@@ -5,17 +5,13 @@ const { isForkedChild, isRenderer, isDev, isMain } = require('../ps');
|
|
|
5
5
|
const { getConfig } = require('../config');
|
|
6
6
|
const { childMessage } = require('../message');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
* 捕获异常
|
|
10
|
-
*/
|
|
8
|
+
// 捕获异常
|
|
11
9
|
function loadException() {
|
|
12
10
|
uncaughtExceptionHandler();
|
|
13
11
|
unhandledRejectionHandler();
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
* 当进程上抛出异常而没有被捕获时触发该事件,并且使异常静默。
|
|
18
|
-
*/
|
|
14
|
+
// 当进程上抛出异常而没有被捕获时触发该事件,并且使异常静默。
|
|
19
15
|
function uncaughtExceptionHandler() {
|
|
20
16
|
process.on('uncaughtException', function(err) {
|
|
21
17
|
if (!(err instanceof Error)) {
|
|
@@ -34,9 +30,7 @@ function uncaughtExceptionHandler() {
|
|
|
34
30
|
});
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
* 当进程上抛出异常而没有被捕获时触发该事件。
|
|
39
|
-
*/
|
|
33
|
+
// 当进程上抛出异常而没有被捕获时触发该事件。
|
|
40
34
|
function uncaughtExceptionMonitorHandler() {
|
|
41
35
|
process.on('uncaughtExceptionMonitor', function(err, origin) {
|
|
42
36
|
if (!(err instanceof Error)) {
|
|
@@ -46,10 +40,8 @@ function uncaughtExceptionMonitorHandler() {
|
|
|
46
40
|
});
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* 即便是在异步情况下使用了catch也会触发该事件
|
|
52
|
-
*/
|
|
43
|
+
// 当promise中reject的异常在同步任务中没有使用catch捕获就会触发该事件,
|
|
44
|
+
// 即便是在异步情况下使用了catch也会触发该事件
|
|
53
45
|
function unhandledRejectionHandler() {
|
|
54
46
|
process.on('unhandledRejection', function(err) {
|
|
55
47
|
if (!(err instanceof Error)) {
|
|
@@ -71,18 +63,14 @@ function unhandledRejectionHandler() {
|
|
|
71
63
|
});
|
|
72
64
|
}
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
* 如果是子进程,发送错误到主进程控制台
|
|
76
|
-
*/
|
|
66
|
+
// 如果是子进程,发送错误到主进程控制台
|
|
77
67
|
function _devError (err) {
|
|
78
68
|
if (isForkedChild() && isDev()) {
|
|
79
69
|
childMessage.sendErrorToTerminal(err);
|
|
80
70
|
}
|
|
81
71
|
}
|
|
82
72
|
|
|
83
|
-
|
|
84
|
-
* 捕获异常后是否退出
|
|
85
|
-
*/
|
|
73
|
+
// 捕获异常后是否退出
|
|
86
74
|
function _exit () {
|
|
87
75
|
const { mainExit, childExit, rendererExit } = getConfig().exception;
|
|
88
76
|
|
|
@@ -97,9 +85,7 @@ function _exit () {
|
|
|
97
85
|
}
|
|
98
86
|
}
|
|
99
87
|
|
|
100
|
-
|
|
101
|
-
* 捕获异常后是否退出
|
|
102
|
-
*/
|
|
88
|
+
// 捕获异常后是否退出
|
|
103
89
|
function _delayExit() {
|
|
104
90
|
// 等待日志等异步写入完成
|
|
105
91
|
setTimeout(() => {
|
package/html/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getHtmlFilepath(name: string): string;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import EventEmitter = require("events");
|
|
2
|
+
import { JobProcess } from "./jobProcess";
|
|
3
|
+
export declare class ChildJob extends EventEmitter<[never]> {
|
|
4
|
+
constructor();
|
|
5
|
+
jobs: {};
|
|
6
|
+
config: any;
|
|
7
|
+
_initEvents(): void;
|
|
8
|
+
exec(filepath: string, params?: {}, opt?: {}): JobProcess;
|
|
9
|
+
createProcess(opt?: {}): JobProcess;
|
|
10
|
+
getPids(): string[];
|
|
11
|
+
execPromise(filepath: string, params?: {}, opt?: {}): Promise<JobProcess>;
|
|
12
|
+
}
|
|
13
|
+
|
package/jobs/child/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
|
-
const {
|
|
2
|
+
const { JobProcess } = require('./jobProcess');
|
|
3
3
|
const { getFullpath } = require('../../loader');
|
|
4
4
|
const { Events } = require('../../const/channel');
|
|
5
5
|
const { getConfig } = require('../../config');
|
|
@@ -53,7 +53,7 @@ class ChildJob extends EventEmitter {
|
|
|
53
53
|
type: 'childJob'
|
|
54
54
|
}
|
|
55
55
|
}, opt);
|
|
56
|
-
const proc = new
|
|
56
|
+
const proc = new JobProcess(this, options);
|
|
57
57
|
if (!proc) {
|
|
58
58
|
let errorMessage = `[ee-core] [jobs/child] Failed to obtain the child process !`
|
|
59
59
|
throw new Error(errorMessage);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { ChildProcess } from "child_process";
|
|
3
|
+
declare export class JobProcess {
|
|
4
|
+
constructor(host: any, opt?: {});
|
|
5
|
+
emitter: EventEmitter<[never]>;
|
|
6
|
+
host: any;
|
|
7
|
+
args: string[];
|
|
8
|
+
sleeping: boolean;
|
|
9
|
+
child: ChildProcess;
|
|
10
|
+
pid: number;
|
|
11
|
+
_init(): void;
|
|
12
|
+
_eventEmit(m: any): void;
|
|
13
|
+
dispatch(cmd: string, jobPath?: string, ...params: any[]): void;
|
|
14
|
+
callFunc(jobPath?: string, funcName?: string, ...params: any[]): void;
|
|
15
|
+
kill(timeout?: number): void;
|
|
16
|
+
}
|