-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
240 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
// Application Version | ||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
export interface AppVersion | ||
{ | ||
name : string; | ||
version : { | ||
full : string; | ||
short : string; | ||
}; | ||
environment : string; | ||
build : { | ||
commitHash : string; | ||
commitRef : string; | ||
date : string; | ||
release : string; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// Git Utils | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
import { isModuleInstalled } from './modules.js'; | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
export interface GitInfo | ||
{ | ||
shortHash : string; | ||
hash : string; | ||
branch : string; | ||
commitDate : string; | ||
tags : string[]; | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
export async function getGitInfo() : Promise<GitInfo> | ||
{ | ||
const commit : GitInfo = { | ||
shortHash: process.env.COMMIT_SHA ?? 'unknown', | ||
hash: process.env.COMMIT_SHA ?? 'unknown', | ||
branch: process.env.COMMIT_REF ?? 'unknown', | ||
commitDate: process.env.BUILD_DATE ?? (new Date()).toISOString(), | ||
tags: [], | ||
}; | ||
|
||
if(isModuleInstalled('git-last-commit')) | ||
{ | ||
const git = await import('git-last-commit'); | ||
|
||
await new Promise((resolve) => | ||
{ | ||
git.getLastCommit((err, cmt) => | ||
{ | ||
if(!err && cmt) | ||
{ | ||
let commitDate; | ||
if(cmt.committedOn) | ||
{ | ||
commitDate = (new Date(parseInt(cmt.committedOn) * 1000)).toISOString(); | ||
} | ||
|
||
commit.shortHash = cmt.shortHash ? cmt.shortHash : commit.shortHash; | ||
commit.hash = cmt.hash ? cmt.hash : commit.hash; | ||
commit.branch = cmt.branch ? cmt.branch : commit.branch; | ||
commit.commitDate = commitDate ? commitDate : commit.commitDate; | ||
commit.tags = cmt.tags ?? ([]) as string[]; | ||
} | ||
|
||
resolve(undefined); | ||
}); | ||
}); | ||
} | ||
|
||
return commit; | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
// Module Utils | ||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
import { resolve } from 'node:path'; | ||
import { existsSync } from 'node:fs'; | ||
import { packageDirectorySync } from 'pkg-dir'; | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- | ||
|
||
export function isModuleInstalled(modulePath : string) : boolean | ||
{ | ||
try | ||
{ | ||
const pkgPath = packageDirectorySync(); | ||
if(!pkgPath) | ||
{ | ||
return false; | ||
} | ||
|
||
const resolvedPath = resolve(pkgPath, 'node_modules', modulePath); | ||
return existsSync(resolvedPath); | ||
} | ||
catch (_error) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// --------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters