chore: update project version to 0.0.11 and enhance project management features

- Added new project initialization route to register git projects from a specified root directory.
- Enhanced project management to support project status (active, inactive, unlive) and conditional listening.
- Updated project listener to handle non-existent paths gracefully.
- Improved project store to manage project documents with optional fields.
- Refactored git utility functions for better pathname extraction from URLs.
- Added command-line interface support for project management.
- Updated project routes to handle new project types and improved error handling.
This commit is contained in:
xiongxiao
2026-03-14 17:22:00 +08:00
committed by cnb
parent 1aa46b92c0
commit df616df952
10 changed files with 372 additions and 58 deletions

View File

@@ -1,16 +1,23 @@
import { execSync } from 'node:child_process'
import path from 'node:path';
export const getGitPathname = (repoPath: string): string | null => {
export const getPathnameFromGitUrl = (url: string): string => {
const _url = new URL(url.replace(/\.git$/, ''));
const pathname = _url.pathname.replace(/^\/+/, '').replace(/\/+$/, ''); // 去除开头和结尾的斜杠
return pathname;
}
export const getGitPathname = (repoPath: string): { url: string, pathname: string } | null => {
try {
const url = execSync('git config --get remote.origin.url', { cwd: repoPath, encoding: 'utf-8' }).trim();
if (url) {
const _url = new URL(url.replace(/\.git$/, ''));
const pathname = _url.pathname.replace(/^\/+/, '').replace(/\/+$/, ''); // 去除开头和结尾的斜杠
return pathname;
return {
url,
pathname: getPathnameFromGitUrl(url),
}
}
return null;
} catch (err) {
console.warn(`[getGitPathname] Failed to get git remote url for ${repoPath}:`);
console.warn(`[getGitPathname] Failed to get git remote url for ${repoPath}:`, err);
return null;
}
};