UNPKG

release-checker

Version:
89 lines (88 loc) 3.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var exec_sync_1 = require("../../utils/exec-sync"); function gitIsInstalled() { try { exec_sync_1.execOrThrow('git --version'); return true; } catch (error) { return false; } } exports.gitIsInstalled = gitIsInstalled; function headIsDetached() { var currentBranch = getCurrentBranch(); return currentBranch.includes('HEAD detached'); } exports.headIsDetached = headIsDetached; function headIsNotDetached() { return headIsDetached() === false; } exports.headIsNotDetached = headIsNotDetached; function getCurrentBranch() { var gitExecutionResult = exec_sync_1.exec('git branch --no-color'); var currentBranch = gitExecutionResult .split(/\n|\r/) .map(function (line) { return line.replace(/[\t]/g, ' '); }) .map(function (line) { return line.trim(); }) .filter(function (line) { return line && line.length > 0; }) .filter(function (line) { return line.startsWith('*'); }) .map(function (line) { return line.replace('*', '').trim(); }); if (currentBranch.length === 0) { throw new Error(gitExecutionResult); } return currentBranch[0]; } exports.getCurrentBranch = getCurrentBranch; function getUntrackedFiles() { var gitExecutionResult = exec_sync_1.exec('git status --untracked-files --porcelain'); var untrackedFiles = gitExecutionResult .split(/\n|\r/) .map(function (line) { return line.replace(/[\t]/g, ' '); }) .map(function (line) { return line.trim(); }) .filter(function (line) { return line && line.length > 0; }) .filter(function (line) { return line.startsWith('??'); }) .map(function (line) { return line.replace('??', '').trim(); }); return untrackedFiles; } exports.getUntrackedFiles = getUntrackedFiles; function getUncommitedFiles() { var gitExecutionResult = exec_sync_1.exec('git status --porcelain'); var uncommitedFiles = gitExecutionResult .split(/\n|\r/) .map(function (line) { return line.replace(/[\t]/g, ' '); }) .map(function (line) { return line.trim(); }) .filter(function (line) { return line && line.length > 0; }) .filter(function (line) { return line.startsWith('A ') || line.startsWith('C ') || line.startsWith('D ') || line.startsWith('M ') || line.startsWith('R ') || line.startsWith('U '); }) .map(function (line) { return line.replace(/^A\s/, '%%').trim(); }) .map(function (line) { return line.replace(/^C\s/, '%%').trim(); }) .map(function (line) { return line.replace(/^D\s/, '%%').trim(); }) .map(function (line) { return line.replace(/^M\s/, '%%').trim(); }) .map(function (line) { return line.replace(/^R\s/, '%%').trim(); }) .map(function (line) { return line.replace(/^U\s/, '%%').trim(); }) .map(function (line) { return line.replace('%%', '').trim(); }); return uncommitedFiles; } exports.getUncommitedFiles = getUncommitedFiles; function getLatestTag() { var latestTaggedCommit = getLatestTaggedCommit(); if (latestTaggedCommit === '') { throw new Error('no git tag found'); } var gitExecutionResult = exec_sync_1.exec("git describe --tags " + latestTaggedCommit); return gitExecutionResult.replace(/[\t,\n,\r]/g, ''); } exports.getLatestTag = getLatestTag; function getLatestTaggedCommit() { var gitExecutionResult = exec_sync_1.exec('git rev-list --tags --max-count=1'); return gitExecutionResult.replace(/[\t,\n,\r]/g, ''); } exports.getLatestTaggedCommit = getLatestTaggedCommit;