forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-manifest.js
35 lines (28 loc) · 924 Bytes
/
generate-manifest.js
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
// @ts-check
import { execSync } from "child_process";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { join } from "path";
import { fileURLToPath } from "url";
const root = fileURLToPath(new URL("..", import.meta.url).href);
const distDir = join(root, "dist");
const manifestTarget = join(distDir, "manifest.js");
function loadPackageJson() {
const packageJsonPath = join(root, "package.json");
return JSON.parse(readFileSync(packageJsonPath, "utf-8"));
}
function getCommit() {
return execSync("git rev-parse HEAD").toString().trim();
}
function main() {
const pkg = loadPackageJson();
const manifest = {
version: pkg.version,
commit: getCommit(),
};
if (!existsSync(distDir)) {
mkdirSync(distDir, { recursive: true });
}
const manifestJs = `export default ${JSON.stringify(manifest, null, 2)};`;
writeFileSync(manifestTarget, manifestJs);
}
main();