chore: cmd config

This commit is contained in:
gaoshuaixing
2024-12-23 20:52:09 +08:00
parent f2813e6dae
commit 48f3c86aa2
6 changed files with 187 additions and 18 deletions

162
cmd/bin.js Normal file
View File

@@ -0,0 +1,162 @@
/**
* ee-bin 配置
* 仅适用于开发环境
*/
module.exports = {
/**
* development serve ("frontend" "electron" )
* ee-bin dev
*/
dev: {
frontend: {
directory: './frontend',
cmd: 'npm',
args: ['run', 'dev'],
protocol: 'http://',
hostname: 'localhost',
port: 8080,
indexPath: 'index.html',
},
electron: {
directory: './',
cmd: 'electron',
args: ['.', '--env=local'],
loadingPage: '/public/html/loading.html',
}
},
/**
* 构建
* ee-bin build
*/
build: {
frontend: {
directory: './frontend',
cmd: 'npm',
args: ['run', 'build'],
},
go_w: {
directory: './go',
cmd: 'go',
args: ['build', '-o=../build/extraResources/goapp.exe'],
},
go_m: {
directory: './go',
cmd: 'go',
args: ['build', '-o=../build/extraResources/goapp'],
},
go_l: {
directory: './go',
cmd: 'go',
args: ['build', '-o=../build/extraResources/goapp'],
},
python: {
directory: './python',
cmd: 'python',
args: ['./setup.py', 'build'],
},
},
/**
* 移动资源
* ee-bin move
*/
move: {
frontend_dist: {
dist: './frontend/dist',
target: './public/ui'
},
go_static: {
dist: './frontend/dist',
target: './go/public/dist'
},
go_config: {
dist: './go/config',
target: './go/public/config'
},
go_package: {
dist: './package.json',
target: './go/public/package.json'
},
go_images: {
dist: './public/images',
target: './go/public/images'
},
python_dist: {
dist: './python/dist',
target: './build/extraResources/py'
},
},
/**
* 预发布模式prod
* ee-bin start
*/
start: {
directory: './',
cmd: 'electron',
args: ['.', '--env=prod']
},
/**
* 加密
*/
encrypt: {
type: 'confusion',
files: [
'electron/**/*.(js|json)',
'!electron/config/encrypt.js',
'!electron/config/nodemon.json',
'!electron/config/builder.json',
'!electron/config/bin.js',
],
fileExt: ['.js'],
confusionOptions: {
compact: true,
stringArray: true,
stringArrayEncoding: ['none'],
deadCodeInjection: false,
}
},
/**
* 执行自定义命令
* ee-bin exec
*/
exec: {
node_v: {
directory: './',
cmd: 'node',
args: ['-v'],
},
npm_v: {
directory: './',
cmd: 'npm',
args: ['-v'],
},
// 单独调试air 实现 go 热重载
go: {
directory: './go',
cmd: 'air',
args: ['-c=config/.air.toml' ],
},
// windows 单独调试air 实现 go 热重载
go_w: {
directory: './go',
cmd: 'air',
args: ['-c=config/.air.windows.toml' ],
},
// 单独调试,以基础方式启动 go
go2: {
directory: './go',
cmd: 'go',
args: ['run', './main.go', '--env=dev','--basedir=../', '--port=7073'],
},
python: {
directory: './python',
cmd: 'python',
args: ['./main.py', '--port=7074'],
stdio: "inherit", // ignore
},
},
};

View File

@@ -8,8 +8,9 @@ const path = require('path');
module.exports = (appInfo) => {
return {
openDevTools: false,
singleLock: true,
windowsOption: {
title: 'electron-egg1',
title: 'electron-egg',
width: 980,
height: 650,
minWidth: 400,
@@ -21,7 +22,7 @@ module.exports = (appInfo) => {
//preload: path.join(appInfo.electronDir, 'preload', 'bridge.js'),
},
frame: true,
show: false,
show: true,
icon: path.join(appInfo.baseDir, 'public', 'images', 'logo-32.png'),
},
logger: {
@@ -31,7 +32,7 @@ module.exports = (appInfo) => {
coreLogName: 'ee-core.log',
errorLogName: 'ee-error.log'
},
remoteUrl: {
remote: {
enable: false,
url: 'http://electron-egg.kaka996.com/'
},

View File

@@ -3,6 +3,8 @@ const Lifecycle = require('./preload/lifecycle');
const app = new ElectronEgg();
const lifecycle = new Lifecycle();
app.register("ready", lifecycle.ready());
app.register("ready", lifecycle.ready);
app.register("electron-app-ready", lifecycle.electronAppReady);
app.register("window-ready", lifecycle.windowReady);
app.register("before-close", lifecycle.beforeClose);
app.run();

View File

@@ -1,7 +1,7 @@
/*************************************************
** preload为预加载模块该文件将会在程序启动时加载 **
*************************************************/
const Addon = require('ee-core/addon');
/**
* 预加载模块入口
@@ -9,6 +9,5 @@ const Addon = require('ee-core/addon');
module.exports = async () => {
// 示例功能模块,可选择性使用和修改
Addon.get('tray').create();
Addon.get('security').create();
}

View File

@@ -1,5 +1,8 @@
'use strict';
const { getConfig } = require('ee-core/config');
const { getMainWindow } = require('ee-core/electron');
class Lifecycle {
constructor() {
@@ -9,26 +12,28 @@ class Lifecycle {
/**
* core app have been loaded
*/
async ready () {
async ready() {
// do some things
console.log('------------lifecycle ready');
}
/**
* electron app ready
*/
async electronAppReady () {
async electronAppReady() {
// do some things
console.log('-----------lifecycle electron-app-ready');
}
/**
* main window have been loaded
*/
async windowReady () {
// do some things
async windowReady() {
console.log('-------------lifecycle window-ready');
// 延迟加载,无白屏
const winOpt = this.config.windowsOption;
if (winOpt.show == false) {
const win = this.electron.mainWindow;
const { windowsOption } = getConfig();
if (windowsOption.show == false) {
const win = getMainWindow();
win.once('ready-to-show', () => {
win.show();
win.focus();
@@ -39,9 +44,8 @@ class Lifecycle {
/**
* before app close
*/
async beforeClose () {
// do some things
async beforeClose() {
console.log('-----------lifecycle before-close');
}
}

View File

@@ -53,6 +53,7 @@
"electron-builder": "^25.1.8"
},
"dependencies": {
"axios": "^1.7.9",
"dayjs": "^1.11.13",
"ee-core": "file:.yalc/ee-core",
"electron-updater": "^6.3.8"