Files
Termix/packaging/build/after-pack.cjs
T

77 lines
2.2 KiB
JavaScript
Raw Normal View History

2026-06-21 15:55:41 -05:00
const fs = require("fs");
const path = require("path");
+17
2026-09-20 14:56:39 -05:00
const { chmodSpawnHelpers } = require("../../scripts/patch-node-pty.cjs");
2026-06-21 15:55:41 -05:00
2026-10-01 16:20:16 -05:00
const repoRoot = path.resolve(__dirname, "..", "..");
/**
* The SDK is a workspace package, so electron-builder skips it, yet core and
* every plugin import it at runtime. Ship its package.json and dist the way
* the Docker image does.
*/
function copyPluginSdk(resourcesDir, sdkDir = path.join(repoRoot, "packages", "plugin-sdk")) {
const target = path.join(
resourcesDir,
"app.asar.unpacked",
"node_modules",
2026-10-10 14:58:27 -05:00
"@termix-ssh",
2026-10-01 16:20:16 -05:00
"plugin-sdk",
);
const dist = path.join(sdkDir, "dist");
if (!fs.existsSync(dist)) {
throw new Error(`Plugin SDK is not built (${dist}). Run: npm run build:sdk`);
}
fs.rmSync(target, { recursive: true, force: true });
fs.mkdirSync(target, { recursive: true });
fs.copyFileSync(path.join(sdkDir, "package.json"), path.join(target, "package.json"));
fs.cpSync(dist, path.join(target, "dist"), { recursive: true });
return target;
}
exports.copyPluginSdk = copyPluginSdk;
2026-10-04 15:11:41 -05:00
/** Mac App Store builds report "mas", not "darwin", but are still .app bundles. */
function resourcesDirFor({ electronPlatformName, appOutDir, packager }) {
return ["darwin", "mas"].includes(electronPlatformName)
? path.join(
appOutDir,
`${packager.appInfo.productFilename}.app`,
"Contents",
"Resources",
)
: path.join(appOutDir, "resources");
}
exports.resourcesDirFor = resourcesDirFor;
2026-06-21 15:55:41 -05:00
exports.default = async function afterPack(context) {
const { targets, appOutDir } = context;
const isDir = targets.some((t) => t.name === "dir");
+17
2026-09-20 14:56:39 -05:00
if (isDir) {
const markerPath = path.join(appOutDir, ".portable");
fs.writeFileSync(markerPath, "");
}
2026-06-21 15:55:41 -05:00
2026-10-04 15:11:41 -05:00
const resourcesDir = resourcesDirFor(context);
+17
2026-09-20 14:56:39 -05:00
2026-10-01 16:20:16 -05:00
copyPluginSdk(resourcesDir);
if (context.electronPlatformName === "win32") {
return;
}
+17
2026-09-20 14:56:39 -05:00
const nodePtyDir = path.join(
resourcesDir,
"app.asar.unpacked",
"node_modules",
"node-pty",
);
const fixed = chmodSpawnHelpers(nodePtyDir);
if (fixed > 0) {
console.log(
`[afterPack] Restored execute bit on ${fixed} packaged spawn-helper binary(ies)`,
);
}
2026-06-21 15:55:41 -05:00
};