feat: 更新 @kevisual/router 依赖至 0.1.2,增强 git 路径解析功能并优化项目搜索逻辑

This commit is contained in:
xiongxiao
2026-03-15 20:57:40 +08:00
committed by cnb
parent 609a0987e9
commit 2de68a9960
4 changed files with 81 additions and 11 deletions

View File

@@ -1,18 +1,20 @@
import { execSync } from 'node:child_process'
import path from 'node:path';
export const getPathnameFromGitUrl = (url: string): string => {
export const getPathnameFromGitUrl = (url: string): { pathname: string, filename: string } => {
const _url = new URL(url.replace(/\.git$/, ''));
const pathname = _url.pathname.replace(/^\/+/, '').replace(/\/+$/, ''); // 去除开头和结尾的斜杠
return pathname;
const _pathname = _url.pathname;
const pathname = _pathname.replace(/^\/+/, '').replace(/\/+$/, ''); // 去除开头和结尾的斜杠
const filename = path.basename(_pathname);
return { pathname, filename };
}
export const getGitPathname = (repoPath: string): { url: string, pathname: string } | null => {
export const getGitPathname = (repoPath: string): { url: string, pathname: string, filename: string } | null => {
try {
const url = execSync('git config --get remote.origin.url', { cwd: repoPath, encoding: 'utf-8' }).trim();
if (url) {
return {
url,
pathname: getPathnameFromGitUrl(url),
...getPathnameFromGitUrl(url),
}
}
return null;