mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
// 生成并传递 workspace 共享构建标识
|
|
|
|
import { randomBytes } from "node:crypto";
|
|
import { spawnSync } from "node:child_process";
|
|
import { resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { readRootPackageVersion } from "./package-version.mjs";
|
|
|
|
const workspaceDir = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
|
|
const packageManager = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
|
|
/** 运行带有 workspace 级构建 hash 的 pnpm 命令。 */
|
|
const runWorkspaceCommand = () => {
|
|
const commandArguments = process.argv.slice(2);
|
|
if (commandArguments.length === 0) {
|
|
console.error("A pnpm command is required");
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
const buildHash = randomBytes(8).toString("hex");
|
|
const packageVersion = readRootPackageVersion(workspaceDir);
|
|
console.info(`Build hash: ${buildHash}`);
|
|
|
|
const result = spawnSync(packageManager, commandArguments, {
|
|
cwd: workspaceDir,
|
|
env: {
|
|
...process.env,
|
|
BUILD_HASH: buildHash,
|
|
TMC_PACKAGE_VERSION: packageVersion,
|
|
},
|
|
stdio: "inherit",
|
|
});
|
|
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0) process.exitCode = result.status ?? 1;
|
|
};
|
|
|
|
runWorkspaceCommand();
|