0.1.2 • Published 3 years ago
repoinf v0.1.2
repoinf
Library for getting basic information about a Git repository for versioning purposes.
Usage
This library is available via npm:
npm i --save repoinfTwo functions are available: getRepoInfo(), which returns information about a repository, and getPlatformInfo(), which returns some basic information about the system. Both return a Promise that resolves to an object.
To use getRepoInfo(), the git command line utility needs to be available.
Reference
Function:
getRepoInfo(repoRoot[, isContainer, gitCmd])Parameters:
repoRootString\ Path to the repository to return information for.isContainerBoolean: true\ Whether therepoRootpath contains the .git directory (as opposed to being the .git directory).gitCmdString: "git"\ Name of or path to the Git executable, if it's not"git".
Returns:
isRepoBoolean\ Whether the given path is a valid repository. If not, onlyisRepoandhasCommitswill be returned, both false.hasCommitsBoolean\ Whether the repository has any commits. Without commits, only the branch name can be determined and all other data is empty.branchString\ Name of the currently active branch.hashString\ Short 7-character hash.hashFullString\ Full 40-character hash.lastCommitDate\ Date of the last commit.commitsNumber\ Number of commits on this branch.versionString\ Formatted string representing the repository's state, e.g."main-423 [97a65b1]".versionDashedString\ Formatted string separated only by dashes, e.g."main-423-97a65b1".
Example:
const data = await getRepoInfo(`/path/to/project`) // path containing a .git directory
console.log(data)
// {
// isRepo: true,
// hasCommits: true,
// branch: 'main',
// hash: '97a65b1',
// hashFull: '97a65b155b21b334975736d70d5eb20e58003cb1',
// commits: 423,
// lastCommit: 2021-11-14T14:11:53.000Z,
// versionDashed: 'main-423-97a65b1',
// version: 'main-423 [97a65b1]'
// }Function:
getPlatformInfo()Parameters:
- (None.)
Returns:
versionString\ Full string identifying the kernel version.uptimeNumber\ Number of seconds that the system has been up.platformString\ OS platform name (aix,darwin,freebsd,linux,openbsd,sunos, orwin32).typeString\ OS name (Linux,DarwinorWindows_NT).releaseString\ OS version.hostnameString\ System hostname.archString\ CPU architecture for which Node was compiled.bootTimeDate\ Date object based on the current time anduptime.
Example:
const data = await getPlatformInfo()
console.log(data)
// {
// version: 'Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64',
// uptime: 23457,
// platform: 'darwin',
// type: 'Darwin',
// release: '18.7.0',
// hostname: 'Vesuvius.local',
// arch: 'x64',
// bootTime: 2021-12-10T10:52:15.000Z
// }License
© MIT license.