@zwa73/dev-utils 1.0.59 → 1.0.62

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 (29) hide show
  1. package/data/CreateElectronFrame/.eslintrc.js +41 -0
  2. package/data/CreateElectronFrame/forge.config.ts +52 -0
  3. package/data/CreateElectronFrame/package-lock.json +23687 -0
  4. package/data/CreateElectronFrame/package.json +59 -0
  5. package/data/CreateElectronFrame/src/Component/Base.tsx +8 -0
  6. package/data/CreateElectronFrame/src/Component/index.ts +1 -0
  7. package/data/CreateElectronFrame/src/Static/index.ts +14 -0
  8. package/data/CreateElectronFrame/src/app.tsx +7 -0
  9. package/data/CreateElectronFrame/src/index.html +20 -0
  10. package/data/CreateElectronFrame/src/index.ts +86 -0
  11. package/data/CreateElectronFrame/src/preload.ts +2 -0
  12. package/data/CreateElectronFrame/src/renderer.ts +2 -0
  13. package/data/CreateElectronFrame/webpack.main.config.ts +20 -0
  14. package/data/CreateElectronFrame/webpack.plugins.ts +9 -0
  15. package/data/CreateElectronFrame/webpack.renderer.config.ts +23 -0
  16. package/data/CreateElectronFrame/webpack.rules.ts +41 -0
  17. package/dist/Command/CreateElectronFrame.d.ts +3 -0
  18. package/dist/Command/CreateElectronFrame.js +63 -0
  19. package/dist/Command/Init.js +3 -2
  20. package/dist/Command/Route.js +2 -0
  21. package/package.json +1 -1
  22. package/src/Command/CreateElectronFrame.ts +40 -0
  23. package/src/Command/Init.ts +8 -2
  24. package/src/Command/Route.ts +2 -0
  25. /package/data/{index.d.ts → init/index.d.ts} +0 -0
  26. /package/data/{index.js → init/index.js} +0 -0
  27. /package/data/{scripts → init/scripts}/compile.ps1 +0 -0
  28. /package/data/{scripts → init/scripts}/watch.ps1 +0 -0
  29. /package/data/{src → init/src}/index.ts +0 -0
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "client",
3
+ "productName": "client",
4
+ "version": "1.0.0",
5
+ "description": "My Electron application description",
6
+ "main": ".webpack/main",
7
+ "scripts": {
8
+ "start": "electron-forge start",
9
+ "package": "electron-forge package",
10
+ "make": "electron-forge make",
11
+ "publish": "electron-forge publish",
12
+ "lint": "eslint --ext .ts,.tsx ."
13
+ },
14
+ "devDependencies": {
15
+ "@babel/core": "^7.25.2",
16
+ "@babel/preset-react": "^7.24.7",
17
+ "@electron-forge/cli": "^7.4.0",
18
+ "@electron-forge/maker-deb": "^7.4.0",
19
+ "@electron-forge/maker-rpm": "^7.4.0",
20
+ "@electron-forge/maker-squirrel": "^7.4.0",
21
+ "@electron-forge/maker-zip": "^7.4.0",
22
+ "@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
23
+ "@electron-forge/plugin-fuses": "^7.4.0",
24
+ "@electron-forge/plugin-webpack": "^7.4.0",
25
+ "@electron/fuses": "^1.8.0",
26
+ "@types/node": "^22.5.2",
27
+ "@types/react": "^18.3.5",
28
+ "@types/react-dom": "^18.3.0",
29
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
30
+ "@typescript-eslint/parser": "^5.62.0",
31
+ "@vercel/webpack-asset-relocator-loader": "^1.7.3",
32
+ "babel-loader": "^9.1.3",
33
+ "css-loader": "^6.11.0",
34
+ "electron": "*",
35
+ "eslint": "^8.57.0",
36
+ "eslint-plugin-import": "^2.29.1",
37
+ "fork-ts-checker-webpack-plugin": "^7.3.0",
38
+ "node-loader": "^2.0.0",
39
+ "style-loader": "^3.3.4",
40
+ "ts-loader": "^9.5.1",
41
+ "ts-node": "^10.9.2",
42
+ "tsconfig-paths-webpack-plugin": "^4.1.0",
43
+ "typescript": "~4.5.4",
44
+ "typescript-eslint": "^8.5.0"
45
+ },
46
+ "keywords": [],
47
+ "author": {
48
+ "name": "zwa73"
49
+ },
50
+ "license": "MIT",
51
+ "dependencies": {
52
+ "@zwa73/react-utils": "*",
53
+ "@zwa73/utils": "*",
54
+ "electron-squirrel-startup": "^1.0.1",
55
+ "react": "^18.3.1",
56
+ "react-dom": "^18.3.1",
57
+ "styled-components": "^6.1.13"
58
+ }
59
+ }
@@ -0,0 +1,8 @@
1
+ import { FC } from "react";
2
+
3
+
4
+
5
+
6
+ export const Base:FC = ()=>{
7
+ return <div>Hello from React!</div>;
8
+ };
@@ -0,0 +1 @@
1
+ export * from './Base';
@@ -0,0 +1,14 @@
1
+ import { app } from "electron";
2
+
3
+
4
+
5
+
6
+ export const FuncObj = {
7
+ getAppPath() {
8
+ return app.getAppPath();
9
+ },
10
+ test(){
11
+ return 0;
12
+ },
13
+ };
14
+ export type FuncObj = typeof FuncObj;
@@ -0,0 +1,7 @@
1
+ import { createRoot } from 'react-dom/client';
2
+ import { Base } from 'Component';
3
+
4
+
5
+
6
+ const root = createRoot(document.body);
7
+ root.render(<Base/>);
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <title>Client</title>
7
+ <style>
8
+ html,
9
+ body {
10
+ overflow: hidden;
11
+ margin: 0;
12
+ padding: 0;
13
+ width: 100%;
14
+ height: 100%;
15
+ background-color: var(--background-color-1);
16
+ }
17
+ </style>
18
+ </head>
19
+
20
+ </html>
@@ -0,0 +1,86 @@
1
+ import { app, BrowserWindow, ipcMain, IpcMainInvokeEvent, nativeTheme } from "electron";
2
+ import { FuncObj } from "./Static";
3
+ // This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
4
+ // plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
5
+ // whether you're running in development or production).
6
+ declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
7
+ declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
8
+
9
+ // Handle creating/removing shortcuts on Windows when installing/uninstalling.
10
+ if (require("electron-squirrel-startup")) {
11
+ app.quit();
12
+ }
13
+
14
+ const createWindow = (): void => {
15
+ // Create the browser window.
16
+ const mainWindow = new BrowserWindow({
17
+ height: 600,
18
+ width: 800,
19
+ webPreferences: {
20
+ preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
21
+ webSecurity: false,
22
+ allowRunningInsecureContent: true,
23
+ },
24
+ });
25
+
26
+ mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
27
+ callback({
28
+ responseHeaders: {
29
+ ...details.responseHeaders,
30
+ "Content-Security-Policy": [],
31
+ },
32
+ });
33
+ });
34
+
35
+ // and load the index.html of the app.
36
+ void mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
37
+
38
+ // Open the DevTools.
39
+ mainWindow.webContents.openDevTools();
40
+ mainWindow.webContents.on("devtools-opened", () => {
41
+ // First, set the theme to 'light'
42
+ nativeTheme.themeSource = "light";
43
+ // After a short delay, set it to 'dark'
44
+ setTimeout(() => {
45
+ nativeTheme.themeSource = "system";
46
+ }, 100); // 100ms delay; adjust if necessary
47
+ });
48
+ };
49
+
50
+ // This method will be called when Electron has finished
51
+ // initialization and is ready to create browser windows.
52
+ // Some APIs can only be used after this event occurs.
53
+ app.on("ready", createWindow);
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
+ // Quit when all windows are closed, except on macOS. There, it's common
70
+ // for applications and their menu bar to stay active until the user quits
71
+ // explicitly with Cmd + Q.
72
+ app.on("window-all-closed", () => {
73
+ if (process.platform !== "darwin") {
74
+ app.quit();
75
+ }
76
+ });
77
+
78
+ app.on("activate", () => {
79
+ // On OS X it's common to re-create a window in the app when the
80
+ // dock icon is clicked and there are no other windows open.
81
+ if (BrowserWindow.getAllWindows().length === 0)
82
+ createWindow();
83
+ });
84
+
85
+ // In this file you can include the rest of your app's specific main process
86
+ // code. You can also put them in separate files and import them here.
@@ -0,0 +1,2 @@
1
+ // See the Electron documentation for details on how to use preload scripts:
2
+ // https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
@@ -0,0 +1,2 @@
1
+ // Add this to the end of the existing file
2
+ import './app.tsx';
@@ -0,0 +1,20 @@
1
+ import type { Configuration } from 'webpack';
2
+
3
+ import { rules } from './webpack.rules';
4
+ import { plugins } from './webpack.plugins';
5
+
6
+ export const mainConfig: Configuration = {
7
+ /**
8
+ * This is the main entry point for your application, it's the first file
9
+ * that runs in the main process.
10
+ */
11
+ entry: './src/index.ts',
12
+ // Put your normal webpack config below here
13
+ module: {
14
+ rules,
15
+ },
16
+ plugins,
17
+ resolve: {
18
+ extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
19
+ },
20
+ };
@@ -0,0 +1,9 @@
1
+ import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
2
+
3
+ const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
4
+
5
+ export const plugins = [
6
+ new ForkTsCheckerWebpackPlugin({
7
+ logger: 'webpack-infrastructure',
8
+ }),
9
+ ];
@@ -0,0 +1,23 @@
1
+ import type { Configuration } from 'webpack';
2
+
3
+ import { rules } from './webpack.rules';
4
+ import { plugins } from './webpack.plugins';
5
+ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
6
+
7
+ rules.push({
8
+ test: /\.css$/,
9
+ use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
10
+ });
11
+
12
+ export const rendererConfig: Configuration = {
13
+ module: {
14
+ rules,
15
+ },
16
+ plugins,
17
+ resolve: {
18
+ plugins:[new TsconfigPathsPlugin({
19
+ configFile: './tsconfig.json'
20
+ })],
21
+ extensions: ['.js', '.ts', '.jsx', '.tsx', '.css'],
22
+ },
23
+ };
@@ -0,0 +1,41 @@
1
+ import type { ModuleOptions } from 'webpack';
2
+
3
+ export const rules: Required<ModuleOptions>['rules'] = [
4
+ // Add support for native node modules
5
+ {
6
+ // We're specifying native_modules in the test because the asset relocator loader generates a
7
+ // "fake" .node file which is really a cjs file.
8
+ test: /native_modules[/\\].+\.node$/,
9
+ use: 'node-loader',
10
+ },
11
+ {
12
+ test: /[/\\]node_modules[/\\].+\.(m?js|node)$/,
13
+ parser: { amd: false },
14
+ use: {
15
+ loader: '@vercel/webpack-asset-relocator-loader',
16
+ options: {
17
+ outputAssetBase: 'native_modules',
18
+ },
19
+ },
20
+ },
21
+ {
22
+ test: /\.tsx?$/,
23
+ exclude: /(node_modules|\.webpack)/,
24
+ use: {
25
+ loader: 'ts-loader',
26
+ options: {
27
+ transpileOnly: true,
28
+ },
29
+ },
30
+ },
31
+ {
32
+ test: /\.jsx?$/,
33
+ use: {
34
+ loader: 'babel-loader',
35
+ options: {
36
+ exclude: /node_modules/,
37
+ presets: ['@babel/preset-react']
38
+ }
39
+ }
40
+ }
41
+ ];
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ /**对项目进行初始化 */
3
+ export declare const CmdCreateElectronFrame: (program: Command) => Command;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.CmdCreateElectronFrame = void 0;
30
+ const fs = __importStar(require("fs"));
31
+ const pathe_1 = __importDefault(require("pathe"));
32
+ const utils_1 = require("@zwa73/utils");
33
+ const RouteInterface_1 = require("./RouteInterface");
34
+ const InitDataPath = pathe_1.default.join(RouteInterface_1.DATA_PATH, 'CreateElectronFrame');
35
+ /**复制基础文件 */
36
+ async function copyData() {
37
+ const filelist = await fs.promises.readdir(InitDataPath);
38
+ const plist = filelist.map(async (fileName) => {
39
+ utils_1.SLogger.info(`正在复制 ${fileName}`);
40
+ const filePath = pathe_1.default.join(InitDataPath, fileName);
41
+ const targetPath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, fileName);
42
+ if (!await utils_1.UtilFT.pathExists(targetPath))
43
+ await fs.promises.cp(filePath, targetPath, { recursive: true });
44
+ else
45
+ utils_1.SLogger.info(`${fileName} 已存在 跳过`);
46
+ return null;
47
+ });
48
+ await Promise.all(plist);
49
+ }
50
+ /**对项目进行初始化 */
51
+ const CmdCreateElectronFrame = (program) => program
52
+ .command('CreateElectronFrame')
53
+ .command('createelectronframe')
54
+ .description('对当前目录进行项目初始化,创建Electron基础环境')
55
+ .action(async (opt) => {
56
+ (0, RouteInterface_1.checkProject)();
57
+ utils_1.SLogger.info(`开始初始化设置当前目录 ${RouteInterface_1.PROJECT_PATH}`);
58
+ await Promise.all([
59
+ copyData(),
60
+ utils_1.UtilFunc.exec(`npm install --registry ${RouteInterface_1.MIRROR_SOURCE}`)
61
+ ]);
62
+ });
63
+ exports.CmdCreateElectronFrame = CmdCreateElectronFrame;
@@ -31,12 +31,13 @@ const fs = __importStar(require("fs"));
31
31
  const pathe_1 = __importDefault(require("pathe"));
32
32
  const utils_1 = require("@zwa73/utils");
33
33
  const RouteInterface_1 = require("./RouteInterface");
34
+ const InitDataPath = pathe_1.default.join(RouteInterface_1.DATA_PATH, 'init');
34
35
  /**复制基础文件 */
35
36
  async function copyData() {
36
- const filelist = await fs.promises.readdir(RouteInterface_1.DATA_PATH);
37
+ const filelist = await fs.promises.readdir(InitDataPath);
37
38
  const plist = filelist.map(async (fileName) => {
38
39
  utils_1.SLogger.info(`正在复制 ${fileName}`);
39
- const filePath = pathe_1.default.join(RouteInterface_1.DATA_PATH, fileName);
40
+ const filePath = pathe_1.default.join(InitDataPath, fileName);
40
41
  const targetPath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, fileName);
41
42
  if (!await utils_1.UtilFT.pathExists(targetPath))
42
43
  await fs.promises.cp(filePath, targetPath, { recursive: true });
@@ -10,6 +10,7 @@ const ScanDups_1 = require("./ScanDups");
10
10
  const GenSchema_1 = require("./GenSchema");
11
11
  const ExpandMacro_1 = require("./ExpandMacro");
12
12
  const GenI18n_1 = require("./GenI18n");
13
+ const CreateElectronFrame_1 = require("./CreateElectronFrame");
13
14
  async function cliRoute() {
14
15
  (0, Init_1.CmdInit)(commander_1.program);
15
16
  (0, Node_1.CmdNode)(commander_1.program);
@@ -19,5 +20,6 @@ async function cliRoute() {
19
20
  (0, GenSchema_1.CmdGenSchema)(commander_1.program);
20
21
  (0, ExpandMacro_1.CmdExpandMacro)(commander_1.program);
21
22
  (0, GenI18n_1.CmdGenI18n)(commander_1.program);
23
+ (0, CreateElectronFrame_1.CmdCreateElectronFrame)(commander_1.program);
22
24
  commander_1.program.parse(process.argv);
23
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.59",
3
+ "version": "1.0.62",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,40 @@
1
+ import { Command } from 'commander';
2
+ import * as fs from 'fs';
3
+ import path from 'pathe';
4
+
5
+ import { SLogger, UtilFT, UtilFunc } from '@zwa73/utils';
6
+
7
+ import { checkProject, DATA_PATH, MIRROR_SOURCE, PROJECT_PATH } from './RouteInterface';
8
+
9
+
10
+ const InitDataPath = path.join(DATA_PATH,'CreateElectronFrame');
11
+
12
+ /**复制基础文件 */
13
+ async function copyData() {
14
+ const filelist = await fs.promises.readdir(InitDataPath);
15
+ const plist = filelist.map(async (fileName)=>{
16
+ SLogger.info(`正在复制 ${fileName}`);
17
+ const filePath = path.join(InitDataPath,fileName);
18
+ const targetPath = path.join(PROJECT_PATH,fileName);
19
+ if(!await UtilFT.pathExists(targetPath))
20
+ await fs.promises.cp(filePath,targetPath,{recursive:true});
21
+ else
22
+ SLogger.info(`${fileName} 已存在 跳过`);
23
+ return null;
24
+ })
25
+ await Promise.all(plist);
26
+ }
27
+
28
+ /**对项目进行初始化 */
29
+ export const CmdCreateElectronFrame = (program:Command)=>program
30
+ .command('CreateElectronFrame')
31
+ .command('createelectronframe')
32
+ .description('对当前目录进行项目初始化,创建Electron基础环境')
33
+ .action(async (opt) => {
34
+ checkProject();
35
+ SLogger.info(`开始初始化设置当前目录 ${PROJECT_PATH}`);
36
+ await Promise.all([
37
+ copyData(),
38
+ UtilFunc.exec(`npm install --registry ${MIRROR_SOURCE}`)
39
+ ]);
40
+ });
@@ -6,12 +6,18 @@ import { SLogger, UtilFT, UtilFunc } from '@zwa73/utils';
6
6
 
7
7
  import { checkProject, DATA_PATH, MIRROR_SOURCE, PROJECT_PATH } from './RouteInterface';
8
8
 
9
+
10
+
11
+
12
+
13
+ const InitDataPath = path.join(DATA_PATH,'init');
14
+
9
15
  /**复制基础文件 */
10
16
  async function copyData() {
11
- const filelist = await fs.promises.readdir(DATA_PATH);
17
+ const filelist = await fs.promises.readdir(InitDataPath);
12
18
  const plist = filelist.map(async (fileName)=>{
13
19
  SLogger.info(`正在复制 ${fileName}`);
14
- const filePath = path.join(DATA_PATH,fileName);
20
+ const filePath = path.join(InitDataPath,fileName);
15
21
  const targetPath = path.join(PROJECT_PATH,fileName);
16
22
  if(!await UtilFT.pathExists(targetPath))
17
23
  await fs.promises.cp(filePath,targetPath,{recursive:true});
@@ -8,6 +8,7 @@ import { CmdScanDups } from './ScanDups';
8
8
  import { CmdGenSchema } from './GenSchema';
9
9
  import { CmdExpandMacro } from './ExpandMacro';
10
10
  import { CmdGenI18n } from './GenI18n';
11
+ import { CmdCreateElectronFrame } from './CreateElectronFrame';
11
12
 
12
13
  export async function cliRoute(){
13
14
  CmdInit(program);
@@ -18,5 +19,6 @@ export async function cliRoute(){
18
19
  CmdGenSchema(program);
19
20
  CmdExpandMacro(program);
20
21
  CmdGenI18n(program);
22
+ CmdCreateElectronFrame(program);
21
23
  program.parse(process.argv);
22
24
  }
File without changes
File without changes
File without changes
File without changes
File without changes