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:
@@ -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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user