long-git-cli
Version:
A CLI tool for Git tag management.
74 lines • 2.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.REMOTE_TYPES = void 0;
exports.detectRemoteType = detectRemoteType;
exports.showRemoteSpecificTips = showRemoteSpecificTips;
const simple_git_1 = require("simple-git");
const chalk_1 = __importDefault(require("chalk"));
exports.REMOTE_TYPES = {
GITHUB: 'github',
BITBUCKET: 'bitbucket',
GITLAB: 'gitlab',
UNKNOWN: 'unknown'
};
const git = (0, simple_git_1.simpleGit)();
/**
* 检测远程仓库类型(GitHub、Bitbucket、GitLab 等)
* @returns {Promise<RemoteInfo | null>} 远程仓库信息,如果没有配置远程仓库则返回 null
*/
async function detectRemoteType() {
try {
const remotes = await git.getRemotes(true);
if (remotes.length === 0) {
return null;
}
const origin = remotes.find(remote => remote.name === 'origin');
if (!origin) {
return null;
}
const url = origin.refs.push || origin.refs.fetch;
if (!url) {
return null;
}
let type = exports.REMOTE_TYPES.UNKNOWN;
if (url.includes('github.com')) {
type = exports.REMOTE_TYPES.GITHUB;
}
else if (url.includes('bitbucket.org') || url.includes('bitbucket.com')) {
type = exports.REMOTE_TYPES.BITBUCKET;
}
else if (url.includes('gitlab.com')) {
type = exports.REMOTE_TYPES.GITLAB;
}
return {
name: origin.name,
url,
type
};
}
catch (error) {
console.log(chalk_1.default.yellow('⚠️ 无法检测远程仓库类型'));
return null;
}
}
/**
* 根据远程仓库类型显示特定的提示信息
* @param {RemoteInfo['type']} remoteType - 远程仓库类型
*/
function showRemoteSpecificTips(remoteType) {
switch (remoteType) {
case exports.REMOTE_TYPES.BITBUCKET:
console.log(chalk_1.default.blue('💡 提示:在 Bitbucket 中,你可以在 "Tags" 或 "Commits" 页面查看'));
break;
case exports.REMOTE_TYPES.GITHUB:
console.log(chalk_1.default.blue('💡 提示:在 GitHub 中,你可以在 "Releases" 或 "Commits" 页面查看'));
break;
case exports.REMOTE_TYPES.GITLAB:
console.log(chalk_1.default.blue('💡 提示:在 GitLab 中,你可以在 "Repository > Tags" 或 "Commits" 页面查看'));
break;
}
}
//# sourceMappingURL=git-remote.js.map