-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.config.ts
More file actions
45 lines (44 loc) · 1.17 KB
/
Copy pathbuild.config.ts
File metadata and controls
45 lines (44 loc) · 1.17 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
import childProcess from "node:child_process";
import fs from "node:fs/promises";
import { defineBuildConfig, type MkdistBuildEntry } from "unbuild";
import tsConfig from "./tsconfig.json";
export default defineBuildConfig({
entries: (["esm", "cjs"] as const).map(
(format): MkdistBuildEntry => ({
builder: "mkdist",
input: "./src",
format,
ext: (
{
esm: "mjs",
cjs: "cjs",
} as const
)[format],
declaration: true,
addRelativeDeclarationExtensions: true,
typescript: {
compilerOptions: tsConfig.compilerOptions,
},
}),
),
hooks: {
"mkdist:entry:build": async (_ctx, _entry, output) => {
const rev = await new Promise<string>((resolve, reject) =>
childProcess.exec(
"git describe --dirty --tags --match js-v* --first-parent",
(error, stdout) => (error ? reject(error) : resolve(stdout)),
),
);
const userAgent = `portone-server-sdk-js/${rev.trim()}`;
await Promise.all(
output.writtenFiles.map(async (file) => {
const content = await fs.readFile(file, { encoding: "utf-8" });
return fs.writeFile(
file,
content.replace("__USER_AGENT__", userAgent),
);
}),
);
},
},
});