Log CLI version and git commit hash (v2) (#6176)

This commit is contained in:
owenofbrien
2025-08-14 05:12:26 -05:00
committed by GitHub
parent 3e004048cf
commit dd55a82a28
4 changed files with 34 additions and 5 deletions

View File

@@ -21,16 +21,24 @@ import { execSync } from 'child_process';
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { dirname, join, relative } from 'path';
import { fileURLToPath } from 'url';
import { readPackageUp } from 'read-package-up';
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = join(__dirname, '..');
const scriptPath = relative(root, fileURLToPath(import.meta.url));
const generatedDir = join(root, 'packages/cli/src/generated');
const gitCommitFile = join(generatedDir, 'git-commit.ts');
const generatedCliDir = join(root, 'packages/cli/src/generated');
const cliGitCommitFile = join(generatedCliDir, 'git-commit.ts');
const generatedCoreDir = join(root, 'packages/core/src/generated');
const coreGitCommitFile = join(generatedCoreDir, 'git-commit.ts');
let gitCommitInfo = 'N/A';
let cliVersion = 'UNKNOWN';
if (!existsSync(generatedDir)) {
mkdirSync(generatedDir, { recursive: true });
if (!existsSync(generatedCliDir)) {
mkdirSync(generatedCliDir, { recursive: true });
}
if (!existsSync(generatedCoreDir)) {
mkdirSync(generatedCoreDir, { recursive: true });
}
try {
@@ -40,6 +48,9 @@ try {
if (gitHash) {
gitCommitInfo = gitHash;
}
const result = await readPackageUp();
cliVersion = result?.packageJson?.version ?? 'UNKNOWN';
} catch {
// ignore
}
@@ -53,6 +64,8 @@ const fileContent = `/**
// This file is auto-generated by the build script (${scriptPath})
// Do not edit this file manually.
export const GIT_COMMIT_INFO = '${gitCommitInfo}';
export const CLI_VERSION = '${cliVersion}';
`;
writeFileSync(gitCommitFile, fileContent);
writeFileSync(cliGitCommitFile, fileContent);
writeFileSync(coreGitCommitFile, fileContent);