forked from lessweb/deepcode-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-git-commit-info.js
More file actions
46 lines (37 loc) · 1.37 KB
/
Copy pathgenerate-git-commit-info.js
File metadata and controls
46 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { execSync } from "node:child_process";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join, relative } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = join(__dirname, "..");
const scriptPath = relative(root, fileURLToPath(import.meta.url));
const generatedCliDir = join(root, "packages", "cli", "src", "generated");
const cliGitCommitFile = join(generatedCliDir, "git-commit.ts");
let gitCommitInfo = "N/A";
let cliVersion = "UNKNOWN";
if (!existsSync(generatedCliDir)) {
mkdirSync(generatedCliDir, { recursive: true });
}
try {
const gitHash = execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();
if (gitHash) {
gitCommitInfo = gitHash;
}
const pkg = JSON.parse(readFileSync(join(root, "packages", "cli", "package.json"), "utf-8"));
cliVersion = pkg.version ?? "UNKNOWN";
} catch {
// ignore
}
const fileContent = [
"/**",
" * @license",
` * Copyright ${new Date().getFullYear()} @vegamo deepcode`,
" */",
"",
`// Auto-generated by ${scriptPath}. Do not edit.`,
`export const GIT_COMMIT_INFO = "${gitCommitInfo}";`,
`export const CLI_VERSION = "${cliVersion}";`,
"",
].join("\n");
writeFileSync(cliGitCommitFile, fileContent);
console.log(`Generated version info: ${cliVersion} (${gitCommitInfo})`);