-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild-layout.cjs
More file actions
72 lines (63 loc) · 2.33 KB
/
build-layout.cjs
File metadata and controls
72 lines (63 loc) · 2.33 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Windows electron-builder layout:
* - Staging: releases/builder/build_MMDDYYYY_HHMM/eb-output/ (deleted after cleanup)
* - Final: releases/builder/build_MMDDYYYY_HHMM/<productSlug from package.json>Installer_<stamp>.exe
* releases/builder/build_MMDDYYYY_HHMM/<RELEASE_BUILD_DEV_DIRNAME>/ (zip, yml, unpacked, etc.)
* - BUILD_STAMP matches the folder id (required by package.json nsis.artifactName).
*/
const fs = require("fs");
const path = require("path");
/** Non-installer artifacts live here (same name for builder + Forge; CI expects this path). */
const RELEASE_BUILD_DEV_DIRNAME = "dev";
const pad = (n) => String(n).padStart(2, "0");
function makeDefaultBuildName(d = new Date()) {
return (
"build_" +
pad(d.getMonth() + 1) +
pad(d.getDate()) +
d.getFullYear() +
"_" +
pad(d.getHours()) +
pad(d.getMinutes())
);
}
/** build_03292026_1938 -> 03292026_1938 */
function stampFromBuildName(buildName) {
if (!/^build_\d{8}_\d{4}$/.test(buildName)) return null;
return buildName.slice("build_".length);
}
/**
* @param {string} appDir - path to app/ (directory with package.json)
* @returns {{ buildName: string, buildStamp: string, buildDir: string, ebOutputDir: string }}
*/
function resolveBuildLayout(appDir) {
const envBuildId = process.env.RELEASE_BUILD_ID?.trim();
const buildName =
envBuildId && /^build_\d{8}_\d{4}$/.test(envBuildId) ? envBuildId : makeDefaultBuildName();
const buildStamp = process.env.BUILD_STAMP?.trim() || stampFromBuildName(buildName);
if (!buildStamp) {
throw new Error(`[build-layout] could not derive BUILD_STAMP for buildName=${buildName}`);
}
const releasesDir = path.join(appDir, "releases");
const buildDir = path.join(releasesDir, "builder", buildName);
const ebOutputDir = path.join(buildDir, "eb-output");
return { buildName, buildStamp, releasesDir, buildDir, ebOutputDir };
}
function ensureCleanEbOutput(ebOutputDir) {
try {
if (fs.existsSync(ebOutputDir)) {
fs.rmSync(ebOutputDir, { recursive: true, force: true });
}
fs.mkdirSync(ebOutputDir, { recursive: true });
} catch (e) {
console.warn("[build-layout] ensureCleanEbOutput:", e?.message || e);
throw e;
}
}
module.exports = {
RELEASE_BUILD_DEV_DIRNAME,
resolveBuildLayout,
ensureCleanEbOutput,
makeDefaultBuildName,
stampFromBuildName,
};