fix: fix hot-api for not build in bun app.mjs

This commit is contained in:
2025-12-05 20:53:25 +08:00
parent 94e331e376
commit ee33208e6c
9 changed files with 95 additions and 38 deletions

View File

@@ -6,6 +6,7 @@ import fs from 'node:fs';
// bun run src/index.ts --
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const external = ['pm2', '@kevisual/hot-api'];
/**
*
* @param {string} p
@@ -20,11 +21,10 @@ await Bun.build({
naming: {
entry: 'assistant.js',
},
external: ['pm2'],
external,
define: {
ENVISION_VERSION: JSON.stringify(pkg.version),
},
env: 'ENVISION_*',
});
await Bun.build({
@@ -38,8 +38,7 @@ await Bun.build({
define: {
ENVISION_VERSION: JSON.stringify(pkg.version),
},
external: ['pm2'],
env: 'ENVISION_*',
external,
});
// const copyDist = ['dist', 'bin'];
const copyDist = ['dist'];

View File

@@ -20,8 +20,8 @@
],
"scripts": {
"dev": "bun run src/run.ts ",
"dev:server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/run-server.ts --home ",
"dev:share": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 bun --watch src/test/remote-app.ts ",
"dev:server": "bun --watch src/run-server.ts ",
"dev:share": "bun --watch src/test/remote-app.ts ",
"build:lib": "bun run bun-lib.config.mjs",
"postbuild:lib": "dts -i src/lib.ts -o assistant-lib.d.ts -d libs -t",
"build": "rimraf dist && bun run bun.config.mjs",
@@ -45,7 +45,7 @@
"@kevisual/load": "^0.0.6",
"@kevisual/local-app-manager": "^0.1.32",
"@kevisual/logger": "^0.0.4",
"@kevisual/query": "0.0.30",
"@kevisual/query": "0.0.31",
"@kevisual/query-login": "0.0.7",
"@kevisual/router": "^0.0.33",
"@kevisual/types": "^0.0.10",
@@ -75,7 +75,7 @@
"access": "public"
},
"dependencies": {
"@kevisual/hot-api": "^0.0.2",
"@kevisual/hot-api": "^0.0.3",
"@nut-tree-fork/nut-js": "^4.2.6",
"eventemitter3": "^5.0.1",
"lowdb": "^7.0.1",

View File

@@ -4,10 +4,10 @@ import { spawnSync } from 'node:child_process';
const command = new Command('server')
.description('启动服务')
.option('-d, --daemon', '是否以守护进程方式运行')
.option('-n, --name <name>', '服务名称')
.option('-n, --name <name>', '服务名称', 'assistant-server')
.option('-p, --port <port>', '服务端口')
.option('-s, --start', '是否启动服务')
.option('-i, --home', '是否以home方式运行')
.option('-e, --interpreter <interpreter>', '指定使用的解释器', 'bun')
.action((options) => {
const { port } = options;
const [_interpreter, execPath] = process.argv;
@@ -24,8 +24,8 @@ const command = new Command('server')
if (port) {
shellCommands.push(`-p ${port}`);
}
if (options.home) {
shellCommands.push('--home');
if (options.interpreter) {
shellCommands.push(`-e ${options.interpreter}`);
}
const basename = _interpreter.split('/').pop();

View File

@@ -0,0 +1,19 @@
import { app } from '@/app.ts';
import { Hotkeys } from '@kevisual/hot-api';
import { useContextKey } from '@kevisual/context';
app.route({
path: 'key-sender',
middleware: ['admin-auth']
}).define(async (ctx) => {
let keys = ctx.query.keys;
if (keys.includes(' ')) {
keys = keys.replace(/\s+/g, '+');
}
const hotKeys: Hotkeys = useContextKey('hotkeys', () => new Hotkeys());
if (typeof keys === 'string') {
await hotKeys.pressHotkey({
hotkey: keys,
});
}
ctx.body = 'ok';
}).addTo(app);

View File

@@ -2,8 +2,10 @@ import { app, assistantConfig } from '../app.ts';
import './config/index.ts';
import './shop-install/index.ts';
import './ai/index.ts';
import './light-code/index.ts';
// TODO:
// import './light-code/index.ts';
import './user/index.ts';
import './hot-api/key-sender/index.ts';
import os from 'node:os';
import { authCache } from '@/module/cache/auth.ts';

View File

@@ -1,11 +1,12 @@
import { app, assistantConfig } from '@/app.ts';
import { AppDownload } from '@/services/app/index.ts';
import { AssistantApp } from '@/module/assistant/index.ts';
import { shopDefine } from './define.ts';
app
.route({
...shopDefine.get('getRegistry'),
middleware: ['admin-auth'],
path: 'shop',
key: 'get-registry',
description: '获取应用商店注册表信息',
middleware: ['admin-auth'],
metadata: {
admin: true,
}
@@ -19,7 +20,9 @@ app
app
.route({
...shopDefine.get('listInstalled'),
path: 'shop',
key: 'list-installed',
description: '列出当前已安装的所有应用',
middleware: ['admin-auth'],
metadata: {
admin: true,
@@ -35,7 +38,9 @@ app
app
.route({
...shopDefine.get('install'),
path: 'shop',
key: 'install',
description: '安装指定的应用,可以指定 id、type、force 和 yes 参数',
middleware: ['admin-auth'],
metadata: {
admin: true,
@@ -60,7 +65,9 @@ app
app
.route({
...shopDefine.get('uninstall'),
path: 'shop',
key: 'uninstall',
description: '卸载指定的应用,可以指定 id 和 type 参数',
middleware: ['admin-auth'],
metadata: {
admin: true,

View File

@@ -7,7 +7,7 @@ app.route({
}).define(async (ctx) => {
const { username, password } = ctx.query;
const query = assistantConfig.query;
const auth = assistantConfig.getConfig().auth;
const auth = assistantConfig.getConfig().auth || {};
const res = await query.post({
path: 'user',
key: 'login',
@@ -25,7 +25,7 @@ app.route({
}
if (!auth.username) {
// 初始管理员账号
auth.username = 'admin';
auth.username = loginUser;
assistantConfig.setConfig({ auth });
}
// 保存配置