@zwa73/dev-utils 1.0.69 → 1.0.71

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.
@@ -1,19 +1,34 @@
1
- import { assertType } from "@zwa73/utils";
1
+ import { AllExtends, JToken, UtilFT } from "@zwa73/utils";
2
2
  import { IpcMainInvokeEvent, app } from "electron";
3
3
 
4
+ /**桥函数化 */
5
+ const bridgeify = <F extends (...args: any[]) => any>(func:F):
6
+ F extends (...args:infer IN)=>infer OUT
7
+ ? AllExtends<IN,JToken> extends true
8
+ ? OUT extends JToken|void|Promise<JToken|void>
9
+ ? (e:IpcMainInvokeEvent,...args:Parameters<F>)=>ReturnType<F>
10
+ : Error&"返回值无法序列化"
11
+ : Error&"传入值无法序列化"
12
+ : never =>
13
+ ((e:IpcMainInvokeEvent,...args:Parameters<F>):ReturnType<F>=>
14
+ (func as any)(...args)) as any;
15
+
4
16
  /**后端桥对象 */
5
17
  export const BridgeBackend = {
18
+ loadJsonFile :bridgeify(UtilFT.writeJSONFile),
19
+ writeJSONFile:bridgeify(UtilFT.writeJSONFile),
6
20
  getAppPath() {
7
21
  return app.getAppPath();
8
22
  },
9
23
  test(e: IpcMainInvokeEvent, text: string) {
10
- return text + " BridgeBackendTest";
24
+ return text + 0;
11
25
  },
12
26
  };
13
27
  export type BridgeBackend = typeof BridgeBackend;
14
28
 
15
29
  //断言确保桥符合类型
16
-
17
- assertType<{
18
- [key in string|number|symbol]: (arg1: IpcMainInvokeEvent, ...args: any[]) => any;
19
- } & { getBridgeKeys?: never }>(BridgeBackend);
30
+ const assertBridge = <
31
+ T extends {
32
+ [key in string|number|symbol]: (arg1: IpcMainInvokeEvent, ...args: any[]) => any;
33
+ } & { getBridgeKeys?: never } >(t:T) => undefined;
34
+ assertBridge(BridgeBackend);
@@ -84,7 +84,7 @@ type RemoveIpcEventArg<T> =
84
84
  /**前端桥对象定义 */
85
85
  export type BridgeDefine = {
86
86
  [P in keyof BridgeBackend]: BridgeBackend[P] extends (...args: infer Arg) => infer Out
87
- ? RemoveIpcEventArg<(...args: Arg) => Promise<Out>>
87
+ ? RemoveIpcEventArg<(...args: Arg) => Out extends Promise<any> ? Out : Promise<Out>>
88
88
  : never;
89
89
  };
90
90
  //#endregion
@@ -58,7 +58,7 @@ const CmdInitElectron = (program) => program
58
58
  utils_1.SLogger.info(`开始初始化设置当前目录 ${RouteInterface_1.PROJECT_PATH}`);
59
59
  await Promise.all([
60
60
  copyData(),
61
- utils_1.UtilFunc.exec(`npm install`, { outlvl: 'info', errlvl: 'warn' })
61
+ utils_1.UtilFunc.exec(`npm ci`, { outlvl: 'info', errlvl: 'warn' })
62
62
  ]);
63
63
  });
64
64
  exports.CmdInitElectron = CmdInitElectron;
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
8
  "release": "powershell scripts/release",
9
9
  "compile": "powershell scripts/compile",
10
- "watch": "powershell scripts/watch",
11
- "postinstall": "start node scripts/postinstall.js"
10
+ "watch": "powershell scripts/watch"
12
11
  },
13
12
  "keywords": [
14
13
  "schema"
@@ -37,6 +37,6 @@ export const CmdInitElectron = (program:Command)=>program
37
37
  SLogger.info(`开始初始化设置当前目录 ${PROJECT_PATH}`);
38
38
  await Promise.all([
39
39
  copyData(),
40
- UtilFunc.exec(`npm install`,{outlvl:'info',errlvl:'warn'})
40
+ UtilFunc.exec(`npm ci`,{outlvl:'info',errlvl:'warn'})
41
41
  ]);
42
42
  });