feat: 更新 @kevisual/router 依赖至 0.1.2,增强 git 路径解析功能并优化项目搜索逻辑
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user