This commit is contained in:
2025-12-15 23:02:06 +08:00
parent f3f1a1d058
commit 7d4bc37c09
5 changed files with 43 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
export type ProxyInfo = { export type ProxyInfo = {
/** /**
* 代理路径, 比如/root/center, 匹配的路径 * 代理路径, 比如/root/home, 匹配的路径
*/ */
path?: string; path?: string;
/** /**

View File

@@ -2,7 +2,7 @@ import { LocalProxy, LocalProxyOpts } from './index.ts';
import http from 'node:http'; import http from 'node:http';
import { fileProxy } from './proxy/file-proxy.ts'; import { fileProxy } from './proxy/file-proxy.ts';
const localProxy = new LocalProxy({}); const localProxy = new LocalProxy({});
let home = '/root/center'; let home = '/root/home';
export const initProxy = (data: LocalProxyOpts & { home?: string }) => { export const initProxy = (data: LocalProxyOpts & { home?: string }) => {
localProxy.pagesDir = data.pagesDir || ''; localProxy.pagesDir = data.pagesDir || '';
localProxy.watch = data.watch ?? false; localProxy.watch = data.watch ?? false;

View File

@@ -1,6 +1,6 @@
export type ProxyInfo = { export type ProxyInfo = {
/** /**
* 代理路径, 比如/root/center, 匹配的路径 * 代理路径, 比如/root/home, 匹配的路径
*/ */
path?: string; path?: string;
/** /**

View File

@@ -10,6 +10,7 @@ export type AssistantInitOptions = {
path?: string; path?: string;
init?: boolean; init?: boolean;
}; };
const randomId = () => Math.random().toString(36).substring(2, 8);
/** /**
* 助手初始化类 * 助手初始化类
* @class AssistantInit * @class AssistantInit
@@ -41,6 +42,7 @@ export class AssistantInit extends AssistantConfig {
this.createEnvConfig(); this.createEnvConfig();
this.createOtherConfig(); this.createOtherConfig();
this.initPnpm(); this.initPnpm();
this.initIgnore();
} }
get query() { get query() {
if (!this.#query) { if (!this.#query) {
@@ -153,10 +155,46 @@ export class AssistantInit extends AssistantConfig {
create, create,
}; };
} }
initIgnore() {
const gitignorePath = path.join(this.configDir, '.gitignore');
let content = '';
if (checkFileExists(gitignorePath, true)) {
content = fs.readFileSync(gitignorePath, 'utf-8');
}
const ignoreLines = [
'node_modules',
'.DS_Store',
'dist',
'pack-dist',
'cache-file',
'build',
'apps/**/node_modules/',
'pages/**/node_modules/',
'.env',
'!.env*development',
'.pnpm-store',
'.vite',
'.astro'
];
let updated = false;
ignoreLines.forEach((line) => {
if (!content.includes(line)) {
content += `\n${line}`;
updated = true;
}
});
if (updated) {
fs.writeFileSync(gitignorePath, content.trim() + '\n');
console.log(chalk.green('.gitignore 文件更新成功'));
}
}
protected getDefaultInitAssistantConfig() { protected getDefaultInitAssistantConfig() {
const id = randomId();
return { return {
id,
description: '助手配置文件', description: '助手配置文件',
home: '/root/center', docs: "https://kevisual.cn/root/cli-docs/",
home: '/root/home',
proxy: [], proxy: [],
apiProxyList: [], apiProxyList: [],
share: { share: {

View File

@@ -58,7 +58,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
return res.end(`Not Found [${proxyApi.path}] rootPath`); return res.end(`Not Found [${proxyApi.path}] rootPath`);
} }
return fileProxy(req, res, { return fileProxy(req, res, {
path: proxyApi.path, // 代理路径, 比如/root/center path: proxyApi.path, // 代理路径, 比如/root/home
rootPath: proxyApi.rootPath, rootPath: proxyApi.rootPath,
...proxyApi, ...proxyApi,
indexPath: _indexPath, // 首页路径 indexPath: _indexPath, // 首页路径