update
This commit is contained in:
1 parent
7a3db27ffa
commit
1ba3147ed2
96 files changed
+9400
-6269
No files matched your search
@@ -1,14 +1,21 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const packageJsonPath = join(__dirname, "..", "package.json");
|
||||
const releaseDir = join(__dirname, "..", "build", "release");
|
||||
const buildDir = join(__dirname, "..", "build");
|
||||
const releaseDir = join(buildDir, "release");
|
||||
const runtimeConfigPath = join(buildDir, "electron-builder.runtime.json");
|
||||
|
||||
const extraArgs = process.argv.slice(2);
|
||||
const env = { ...process.env };
|
||||
const hasMacSigningMaterial = Boolean(
|
||||
env.CSC_LINK?.trim() ||
|
||||
env.CSC_NAME?.trim() ||
|
||||
env.APPLE_API_KEY?.trim(),
|
||||
);
|
||||
|
||||
function bumpPatchVersion(currentVersion) {
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(currentVersion);
|
||||
@@ -19,21 +26,53 @@ function bumpPatchVersion(currentVersion) {
|
||||
return `${major}.${minor}.${Number.parseInt(patch, 10) + 1}`;
|
||||
}
|
||||
|
||||
async function prepareBuildVersion() {
|
||||
async function resolveBuildVersion() {
|
||||
const raw = await readFile(packageJsonPath, "utf8");
|
||||
const pkg = JSON.parse(raw);
|
||||
const nextVersion = bumpPatchVersion(pkg.version);
|
||||
pkg.version = nextVersion;
|
||||
await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
async function writeRuntimeConfig(buildVersion) {
|
||||
const runtimeConfig = {
|
||||
extends: join(__dirname, "..", "electron-builder.yml"),
|
||||
directories: {
|
||||
output: releaseDir,
|
||||
},
|
||||
extraMetadata: {
|
||||
version: buildVersion,
|
||||
},
|
||||
};
|
||||
if (process.platform === "darwin" && !hasMacSigningMaterial && env.AGENTCOMPANY_ENABLE_LOCAL_DMG !== "true") {
|
||||
runtimeConfig.mac = {
|
||||
target: ["zip"],
|
||||
hardenedRuntime: false,
|
||||
};
|
||||
} else if (process.platform === "darwin") {
|
||||
runtimeConfig.mac = {
|
||||
hardenedRuntime: true,
|
||||
};
|
||||
}
|
||||
await writeFile(runtimeConfigPath, `${JSON.stringify(runtimeConfig, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
if (env.CSC_IDENTITY_AUTO_DISCOVERY === undefined) {
|
||||
env.CSC_IDENTITY_AUTO_DISCOVERY = "false";
|
||||
}
|
||||
|
||||
const allowedPublishModes = new Set(["always", "never", "onTag", "onTagOrDraft"]);
|
||||
const explicitPublishArg = extraArgs.some((arg) => arg === "--publish" || arg.startsWith("--publish="));
|
||||
const explicitPlatformArg = extraArgs.some((arg) =>
|
||||
arg === "--mac" ||
|
||||
arg === "--win" ||
|
||||
arg === "--linux" ||
|
||||
arg === "-m" ||
|
||||
arg === "-w" ||
|
||||
arg === "-l" ||
|
||||
arg.startsWith("--mac=") ||
|
||||
arg.startsWith("--win=") ||
|
||||
arg.startsWith("--linux="),
|
||||
);
|
||||
const requestedPublishMode = env.AGENTCOMPANY_ELECTRON_PUBLISH?.trim();
|
||||
let publishMode = "never";
|
||||
|
||||
@@ -48,17 +87,22 @@ if (requestedPublishMode) {
|
||||
}
|
||||
}
|
||||
|
||||
const builderArgs = ["exec", "electron-builder", "--config", "electron-builder.yml"];
|
||||
const builderArgs = ["exec", "electron-builder", "--config", runtimeConfigPath];
|
||||
if (!explicitPublishArg) {
|
||||
builderArgs.push("--publish", publishMode);
|
||||
}
|
||||
if (process.platform === "darwin" && !hasMacSigningMaterial && env.AGENTCOMPANY_ENABLE_LOCAL_DMG !== "true" && !explicitPlatformArg) {
|
||||
builderArgs.push("--mac", "zip");
|
||||
}
|
||||
builderArgs.push(...extraArgs);
|
||||
|
||||
await rm(releaseDir, { recursive: true, force: true });
|
||||
const buildVersion = env.AGENTCOMPANY_BUILD_VERSION?.trim() || await prepareBuildVersion();
|
||||
await rm(buildDir, { recursive: true, force: true });
|
||||
await mkdir(buildDir, { recursive: true });
|
||||
const buildVersion = env.AGENTCOMPANY_BUILD_VERSION?.trim() || await resolveBuildVersion();
|
||||
await writeRuntimeConfig(buildVersion);
|
||||
env.AGENTCOMPANY_BUILD_VERSION = buildVersion;
|
||||
env.npm_package_version = buildVersion;
|
||||
console.log(`[build-desktop] Cleaned build output and bumped package version to ${buildVersion}.`);
|
||||
console.log(`[build-desktop] Cleaned ${buildDir} and staged non-mutating build version ${buildVersion}.`);
|
||||
|
||||
const child = spawn("pnpm", builderArgs, {
|
||||
stdio: "inherit",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const patchScriptPath = join(__dirname, "patch-electron-name.sh");
|
||||
|
||||
if (process.platform !== "darwin") {
|
||||
console.log("[postinstall] Skipping macOS Electron plist patch on non-darwin host.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!existsSync(patchScriptPath)) {
|
||||
console.log("[postinstall] No Electron name patch script found.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const result = spawnSync("bash", [patchScriptPath], {
|
||||
cwd: dirname(__dirname),
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
console.warn(`[postinstall] Electron name patch failed: ${result.error.message}`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if ((result.status ?? 0) !== 0) {
|
||||
console.warn(`[postinstall] Electron name patch exited with status ${result.status}. Continuing install.`);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
Reference in new issue
Block a user