@zwa73/dev-utils 1.0.64 → 1.0.66
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/data/CreateElectronFrame/src/Backend/BridgeBackend.ts +19 -0
- package/data/CreateElectronFrame/src/Backend/index.ts +1 -0
- package/data/CreateElectronFrame/src/Frontend/ContextProxy.ts +14 -0
- package/data/CreateElectronFrame/src/Frontend/index.ts +2 -0
- package/data/CreateElectronFrame/src/app.tsx +1 -2
- package/data/CreateElectronFrame/src/index.ts +19 -15
- package/data/CreateElectronFrame/src/preload.ts +14 -2
- package/data/CreateElectronFrame/tsconfig.json +2 -2
- package/dist/Command/InitElectron.js +0 -4
- package/dist/UtilDevTool.js +0 -3
- package/package.json +1 -1
- package/scripts/postinstall.js +4 -14
- package/src/Command/InitElectron.ts +0 -7
- package/src/UtilDevTool.ts +0 -3
- package/data/CreateElectronFrame/src/Component/index.ts +0 -1
- package/data/CreateElectronFrame/src/Static/index.ts +0 -14
- /package/data/CreateElectronFrame/src/{Component → Frontend}/Base.tsx +0 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
import { IpcMainInvokeEvent, app } from "electron";
|
2
|
+
|
3
|
+
/**后端桥对象 */
|
4
|
+
export const BridgeBackend = {
|
5
|
+
getAppPath() {
|
6
|
+
return app.getAppPath();
|
7
|
+
},
|
8
|
+
test(e: IpcMainInvokeEvent, text: string) {
|
9
|
+
return text + 0;
|
10
|
+
},
|
11
|
+
};
|
12
|
+
export type BridgeBackend = typeof BridgeBackend;
|
13
|
+
|
14
|
+
//断言确保桥符合类型
|
15
|
+
const assertBridge = <
|
16
|
+
T extends {
|
17
|
+
[key in string|number|symbol]: (arg1: IpcMainInvokeEvent, ...args: any[]) => any;
|
18
|
+
} & { getBridgeKeys?: never } >(t:T) => undefined;
|
19
|
+
assertBridge(BridgeBackend);
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './BridgeBackend';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { webUtils } from "electron";
|
2
|
+
import type { BridgeDefine } from "@";
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
/**前端桥对象 */
|
7
|
+
export type BridgeProxy = BridgeDefine;
|
8
|
+
export const BridgeProxy:BridgeProxy = new Proxy({},{
|
9
|
+
get: (target, prop) => async (...args:any) =>
|
10
|
+
(await (window as any).bridge)[prop](...args)
|
11
|
+
}) as any;
|
12
|
+
|
13
|
+
/**代理webUtils */
|
14
|
+
export const WebUtilsProxy:typeof webUtils = (window as any).webUtils;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { app, BrowserWindow, ipcMain, IpcMainInvokeEvent, nativeTheme } from "electron";
|
2
|
-
import {
|
2
|
+
import { BridgeBackend } from "./Backend";
|
3
3
|
// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
|
4
4
|
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
|
5
5
|
// whether you're running in development or production).
|
@@ -52,20 +52,6 @@ const createWindow = (): void => {
|
|
52
52
|
// Some APIs can only be used after this event occurs.
|
53
53
|
app.on("ready", createWindow);
|
54
54
|
|
55
|
-
//#region function define
|
56
|
-
Object.entries(FuncObj).forEach(([k, v]) => ipcMain.handle(k, v));
|
57
|
-
|
58
|
-
type RemoveFirstArg<T> = T extends (arg1: IpcMainInvokeEvent, ...args: infer Rest) => infer R
|
59
|
-
? (...args: Rest) => R
|
60
|
-
: T;
|
61
|
-
|
62
|
-
export type Bridge = {
|
63
|
-
[P in keyof FuncObj]: FuncObj[P] extends (...args: infer Arg) => infer Out
|
64
|
-
? RemoveFirstArg<(...args: Arg) => Promise<Out>>
|
65
|
-
: never;
|
66
|
-
};
|
67
|
-
//#endregion
|
68
|
-
|
69
55
|
// Quit when all windows are closed, except on macOS. There, it's common
|
70
56
|
// for applications and their menu bar to stay active until the user quits
|
71
57
|
// explicitly with Cmd + Q.
|
@@ -84,3 +70,21 @@ app.on("activate", () => {
|
|
84
70
|
|
85
71
|
// In this file you can include the rest of your app's specific main process
|
86
72
|
// code. You can also put them in separate files and import them here.
|
73
|
+
|
74
|
+
|
75
|
+
//#region function define
|
76
|
+
//链接IPC与后端桥对象
|
77
|
+
Object.entries(BridgeBackend).forEach(([k, v]) => ipcMain.handle(k, v));
|
78
|
+
ipcMain.handle('getBridgeKeys', () => Object.keys(BridgeBackend));
|
79
|
+
|
80
|
+
type RemoveIpcEventArg<T> =
|
81
|
+
T extends (arg1: IpcMainInvokeEvent, ...args: infer Rest) => infer R
|
82
|
+
? (...args: Rest) => R : T;
|
83
|
+
|
84
|
+
/**前端桥对象定义 */
|
85
|
+
export type BridgeDefine = {
|
86
|
+
[P in keyof BridgeBackend]: BridgeBackend[P] extends (...args: infer Arg) => infer Out
|
87
|
+
? RemoveIpcEventArg<(...args: Arg) => Promise<Out>>
|
88
|
+
: never;
|
89
|
+
};
|
90
|
+
//#endregion
|
@@ -1,2 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { contextBridge, ipcRenderer, webUtils } from 'electron';
|
2
|
+
import type { BridgeDefine } from './index';
|
3
|
+
|
4
|
+
/**预加载后端桥对象 */
|
5
|
+
const BridgePreload = new Promise(async (resolve) =>
|
6
|
+
resolve(((await ipcRenderer.invoke("getBridgeKeys")) as string[])
|
7
|
+
.map((k) => [k, async (...args: any) => await ipcRenderer.invoke(k, ...args)] as const)
|
8
|
+
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {} as any as BridgeDefine)));
|
9
|
+
|
10
|
+
//暴露后端桥对象
|
11
|
+
contextBridge.exposeInMainWorld('bridge', BridgePreload);
|
12
|
+
|
13
|
+
//暴露webUtils
|
14
|
+
contextBridge.exposeInMainWorld('webUtils', webUtils);
|
@@ -32,10 +32,6 @@ const pathe_1 = __importDefault(require("pathe"));
|
|
32
32
|
const utils_1 = require("@zwa73/utils");
|
33
33
|
const RouteInterface_1 = require("./RouteInterface");
|
34
34
|
const InitDataPath = pathe_1.default.join(RouteInterface_1.DATA_PATH, 'CreateElectronFrame');
|
35
|
-
(async () => {
|
36
|
-
const filelist = await fs.promises.readdir(InitDataPath);
|
37
|
-
console.log(filelist);
|
38
|
-
})();
|
39
35
|
/**复制基础文件 */
|
40
36
|
async function copyData() {
|
41
37
|
const filelist = await fs.promises.readdir(InitDataPath);
|
package/dist/UtilDevTool.js
CHANGED
@@ -70,13 +70,10 @@ var UtilDT;
|
|
70
70
|
.addSourceFileAtPath(fp)
|
71
71
|
.getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)
|
72
72
|
.map(d => d.getName())).flat();
|
73
|
-
//console.log(types)
|
74
73
|
const list = gener.getUserSymbols()
|
75
74
|
.filter(t => types.some(i => i === t))
|
76
75
|
.filter(t => it.some(i => i.test(t)))
|
77
76
|
.filter(t => !et.some(i => i.test(t)));
|
78
|
-
//console.log(list)
|
79
|
-
//await UtilFT.writeJSONFile('testout',list);
|
80
77
|
const schema = gener.getSchemaForSymbols(list);
|
81
78
|
const outDir = opt?.outDir ?? pathe_1.default.join(process.cwd(), 'schema');
|
82
79
|
const schemasPath = pathe_1.default.join(outDir, 'schemas.json');
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
const path = require('path');
|
2
|
-
const { UtilFT
|
3
|
-
const readline = require('readline');
|
2
|
+
const { UtilFT } = require("@zwa73/utils");
|
4
3
|
|
5
4
|
const PACKAGE_PATH = path.join(__dirname,'..','package.json');
|
6
5
|
const VERSION_PATH = path.join(__dirname,"..","..","version.json");
|
@@ -26,11 +25,10 @@ function showUpgradeMessages(prevVersion, currentVersion) {
|
|
26
25
|
// 遍历infoTable中的所有版本
|
27
26
|
for (const version in INFO_TABLE) {
|
28
27
|
const versionNumber = versionToNumber(version);
|
29
|
-
//console.log(versionNumber,prevVersionNumber,currentVersionNumber)
|
30
28
|
// 如果用户的上一个版本低于这个版本,而当前版本高于或等于这个版本
|
31
29
|
if (versionNumber > prevVersionNumber && versionNumber <= currentVersionNumber) {
|
32
30
|
// 显示这个版本的提示信息
|
33
|
-
|
31
|
+
process.stdout.write(INFO_TABLE[version]);
|
34
32
|
hasOut=true;
|
35
33
|
}
|
36
34
|
}
|
@@ -43,21 +41,13 @@ async function main(){
|
|
43
41
|
const currentVersion = packageTable.version;
|
44
42
|
await UtilFT.ensurePathExists(VERSION_PATH);
|
45
43
|
const versionTable = await UtilFT.loadJSONFile(VERSION_PATH,{default:{}});
|
46
|
-
const prevVersion = versionTable[PKG_NAME]?.version ?? "
|
44
|
+
const prevVersion = versionTable[PKG_NAME]?.version ?? "10000.0.0";
|
47
45
|
|
48
|
-
|
46
|
+
process.stdout.write(`${currentVersion} 版本已安装`);
|
49
47
|
// 使用这个函数来显示升级信息
|
50
48
|
const hasOut = showUpgradeMessages(prevVersion, currentVersion);
|
51
49
|
|
52
50
|
const ntable = Object.assign({},versionTable,{[PKG_NAME]:{version:currentVersion}});
|
53
51
|
await UtilFT.writeJSONFile(VERSION_PATH, ntable);
|
54
|
-
|
55
|
-
if(!hasOut) return;
|
56
|
-
const rl = readline.createInterface({
|
57
|
-
input: process.stdin,
|
58
|
-
output: process.stdout
|
59
|
-
});
|
60
|
-
setTimeout(()=>rl.close(),5000);
|
61
|
-
rl.question('按任意键继续...', () => rl.close());
|
62
52
|
}
|
63
53
|
main()
|
@@ -9,13 +9,6 @@ import { checkProject, DATA_PATH, MIRROR_SOURCE, PROJECT_PATH } from './RouteInt
|
|
9
9
|
|
10
10
|
const InitDataPath = path.join(DATA_PATH,'CreateElectronFrame');
|
11
11
|
|
12
|
-
(async ()=>{
|
13
|
-
|
14
|
-
|
15
|
-
const filelist = await fs.promises.readdir(InitDataPath);
|
16
|
-
console.log(filelist);
|
17
|
-
})();
|
18
|
-
|
19
12
|
/**复制基础文件 */
|
20
13
|
async function copyData() {
|
21
14
|
const filelist = await fs.promises.readdir(InitDataPath);
|
package/src/UtilDevTool.ts
CHANGED
@@ -74,13 +74,10 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
|
|
74
74
|
.getDescendantsOfKind(SyntaxKind.TypeAliasDeclaration)
|
75
75
|
.map(d=>d.getName())
|
76
76
|
).flat();
|
77
|
-
//console.log(types)
|
78
77
|
const list = gener.getUserSymbols()
|
79
78
|
.filter(t=>types.some(i=>i===t))
|
80
79
|
.filter(t=>it.some(i=>i.test(t)))
|
81
80
|
.filter(t=>!et.some(i=>i.test(t)));
|
82
|
-
//console.log(list)
|
83
|
-
//await UtilFT.writeJSONFile('testout',list);
|
84
81
|
const schema = gener.getSchemaForSymbols(list) as JObject;
|
85
82
|
const outDir = opt?.outDir ?? path.join(process.cwd(),'schema');
|
86
83
|
const schemasPath = path.join(outDir,'schemas.json');
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './Base';
|
File without changes
|