Compare commits
2 Commits
f3f1a1d058
...
48f2695367
| Author | SHA1 | Date | |
|---|---|---|---|
| 48f2695367 | |||
| 7d4bc37c09 |
@@ -1,6 +1,6 @@
|
|||||||
export type ProxyInfo = {
|
export type ProxyInfo = {
|
||||||
/**
|
/**
|
||||||
* 代理路径, 比如/root/center, 匹配的路径
|
* 代理路径, 比如/root/home, 匹配的路径
|
||||||
*/
|
*/
|
||||||
path?: string;
|
path?: string;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export type ProxyInfo = {
|
export type ProxyInfo = {
|
||||||
/**
|
/**
|
||||||
* 代理路径, 比如/root/center, 匹配的路径
|
* 代理路径, 比如/root/home, 匹配的路径
|
||||||
*/
|
*/
|
||||||
path?: string;
|
path?: string;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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: {
|
||||||
|
|||||||
@@ -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, // 首页路径
|
||||||
|
|||||||
@@ -79,10 +79,10 @@ const showMe = async (show = true) => {
|
|||||||
const localToken = storage.getItem('token');
|
const localToken = storage.getItem('token');
|
||||||
if (!token && !localToken) {
|
if (!token && !localToken) {
|
||||||
console.log('请先登录');
|
console.log('请先登录');
|
||||||
return;
|
return { code: 40400, message: '请先登录' };
|
||||||
}
|
}
|
||||||
let me = await queryLogin.getMe(token);
|
let me = await queryLogin.getMe(token);
|
||||||
if (me.code === 401) {
|
if (me?.code === 401) {
|
||||||
me = await queryLogin.getMe();
|
me = await queryLogin.getMe();
|
||||||
}
|
}
|
||||||
if (show) {
|
if (show) {
|
||||||
@@ -113,6 +113,9 @@ const command = new Command('me')
|
|||||||
res = await showMe(false);
|
res = await showMe(false);
|
||||||
isRefresh = true;
|
isRefresh = true;
|
||||||
}
|
}
|
||||||
|
if (res.code === 40400) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
console.log(chalk.green('refresh token success'), '\n');
|
console.log(chalk.green('refresh token success'), '\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user