diff --git a/packages/mask/.webpack/git-info.ts b/packages/mask/.webpack/git-info.ts index b0c9991e2ff2..3d4a12c0f2a8 100644 --- a/packages/mask/.webpack/git-info.ts +++ b/packages/mask/.webpack/git-info.ts @@ -1,31 +1,29 @@ -import emitFile from '@nice-labs/emit-file-webpack-plugin' +import { emitJSONFile } from '@nice-labs/emit-file-webpack-plugin' import git from '@nice-labs/git-rev' +interface GitInfoReport { + BUILD_DATE: string + VERSION: string + TAG_NAME: string + COMMIT_HASH: string + COMMIT_DATE: string + REMOTE_URL: string + BRANCH_NAME: string + DIRTY: boolean + TAG_DIRTY: boolean +} + export function emitGitInfo(reproducible: boolean) { - return emitFile({ + return emitJSONFile({ name: 'git-info.json', - content: () => JSON.stringify(getGitInfo(reproducible), null, 4), + content: getGitInfo(reproducible), + space: 4, }) } /** Get git info */ -export function getGitInfo(reproducible: boolean) { - try { - if (!reproducible && git.isRepository()) { - return { - BUILD_DATE: new Date().toISOString(), - VERSION: git.describe('--dirty'), - TAG_NAME: git.tag(), - COMMIT_HASH: git.commitHash(true), - COMMIT_DATE: git.commitDate().toISOString(), - REMOTE_URL: git.remoteURL(), - BRANCH_NAME: git.branchName(), - DIRTY: git.isDirty(), - TAG_DIRTY: git.isTagDirty(), - } - } - } catch {} - return { +export function getGitInfo(reproducible: boolean): GitInfoReport { + const report: GitInfoReport = { BUILD_DATE: new Date(0).toISOString(), VERSION: require('../package.json').version + '-reproducible', TAG_NAME: 'N/A', @@ -36,4 +34,19 @@ export function getGitInfo(reproducible: boolean) { DIRTY: false, TAG_DIRTY: false, } + try { + if (reproducible && !git.isRepository()) return report + report.BUILD_DATE = new Date().toISOString() + report.VERSION = git.describe('--dirty') + report.TAG_NAME = git.tag() + report.COMMIT_HASH = git.commitHash(true) + report.COMMIT_DATE = git.commitDate().toISOString() + report.REMOTE_URL = git.remoteURL() + report.BRANCH_NAME = git.branchName() + report.DIRTY = git.isDirty() + report.TAG_DIRTY = git.isTagDirty() + } catch { + // ignore + } + return report }