@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
52 lines (48 loc) • 1.37 kB
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
import {
findLastIndex
} from "./chunk-4UPMMVYW.mjs";
import "./chunk-NYLAFCGV.mjs";
// src/git.ts
async function getCurrentGitBranch() {
return await execCommand("git", ["tag", "--points-at", "HEAD"]) || await execCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
}
async function getTags() {
const tags = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]).then(
(r) => r.split("\n")
);
return tags;
}
async function getLastGitTag(delta = 0) {
const tags = await getTags();
return tags[tags.length + delta - 1];
}
async function getAppVersion(pkgName) {
const tags = await getTags();
const tag = findLastIndex(tags, (tag2) => tag2.startsWith(pkgName));
if (tag === -1) {
throw new Error("Your app(s) doesnt have any tag");
}
const version = tags[tag].split("@")[1];
return version;
}
async function getLastGitCommitHash() {
const commitHash = await execCommand("git", ["rev-parse", "--short", "HEAD"]);
return commitHash;
}
async function execCommand(cmd, args) {
const { execa } = await import("./execa-CZYTJPTU.mjs");
const res = await execa(cmd, args);
return res.stdout.trim();
}
export {
getAppVersion,
getCurrentGitBranch,
getLastGitCommitHash,
getLastGitTag,
getTags
};