2024-06-24 13:14:07 +00:00
|
|
|
import { replaceInFileSync } from "replace-in-file";
|
2024-06-08 22:12:50 +00:00
|
|
|
import childProcess from "child_process";
|
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
2020-11-19 23:23:38 +00:00
|
|
|
|
2023-05-30 20:24:43 +00:00
|
|
|
let buildDate = new Date().toISOString();
|
2024-06-08 22:12:50 +00:00
|
|
|
let versionNumber = process.env["npm_package_version"] ?? "";
|
|
|
|
let versionChannel = process.env["CFG_RELEASE_CHANNEL"] || "nightly";
|
2023-05-30 20:24:43 +00:00
|
|
|
const firefoxExtensionId =
|
2024-06-08 22:12:50 +00:00
|
|
|
process.env["FIREFOX_EXTENSION_ID"] || "ruffle@ruffle.rs";
|
2020-11-19 23:23:38 +00:00
|
|
|
|
|
|
|
let commitHash = "unknown";
|
|
|
|
|
|
|
|
try {
|
|
|
|
commitHash = childProcess.execSync("git rev-parse HEAD").toString().trim();
|
|
|
|
} catch {
|
|
|
|
console.log("Couldn't fetch latest git commit...");
|
|
|
|
}
|
|
|
|
|
2023-05-30 20:24:43 +00:00
|
|
|
let versionName =
|
|
|
|
versionChannel === "nightly"
|
|
|
|
? `nightly ${buildDate.substr(0, 10)}`
|
2024-07-15 10:58:03 +00:00
|
|
|
: versionNumber;
|
2020-11-19 23:23:38 +00:00
|
|
|
|
2024-06-08 22:12:50 +00:00
|
|
|
interface VersionInformation {
|
|
|
|
version_number: string;
|
|
|
|
version_name: string;
|
|
|
|
version_channel: string;
|
|
|
|
build_date: string;
|
|
|
|
commitHash: string;
|
|
|
|
build_id: string;
|
|
|
|
firefox_extension_id: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
let versionSeal: VersionInformation;
|
2023-01-21 01:22:29 +00:00
|
|
|
|
2024-06-08 22:12:50 +00:00
|
|
|
if (process.env["ENABLE_VERSION_SEAL"] === "true") {
|
2024-02-16 05:35:00 +00:00
|
|
|
const sealFile = path.resolve(__dirname, "../../../version_seal.json");
|
|
|
|
if (fs.existsSync(sealFile)) {
|
|
|
|
console.log("Using version seal");
|
2023-03-25 06:50:35 +00:00
|
|
|
// Using the version seal stored previously.
|
2024-06-08 22:12:50 +00:00
|
|
|
versionSeal = JSON.parse(
|
|
|
|
fs.readFileSync(sealFile, { encoding: "utf8" }),
|
|
|
|
) as VersionInformation;
|
2023-01-19 04:33:58 +00:00
|
|
|
|
2023-05-30 20:24:43 +00:00
|
|
|
versionNumber = versionSeal.version_number;
|
|
|
|
versionName = versionSeal.version_name;
|
|
|
|
versionChannel = versionSeal.version_channel;
|
|
|
|
buildDate = versionSeal.build_date;
|
|
|
|
commitHash = versionSeal.commitHash;
|
2023-01-19 04:33:58 +00:00
|
|
|
} else {
|
2024-02-16 05:35:00 +00:00
|
|
|
console.log("Creating version seal");
|
2023-05-30 20:24:43 +00:00
|
|
|
versionSeal = {
|
|
|
|
version_number: versionNumber,
|
|
|
|
version_name: versionName,
|
|
|
|
version_channel: versionChannel,
|
|
|
|
build_date: buildDate,
|
2023-01-21 01:22:29 +00:00
|
|
|
commitHash: commitHash,
|
2024-06-08 22:12:50 +00:00
|
|
|
build_id: process.env["BUILD_ID"] ?? "",
|
2023-05-30 20:24:43 +00:00
|
|
|
firefox_extension_id: firefoxExtensionId,
|
2023-01-21 01:22:29 +00:00
|
|
|
};
|
2023-01-19 04:33:58 +00:00
|
|
|
|
2024-02-16 05:35:00 +00:00
|
|
|
fs.writeFileSync(sealFile, JSON.stringify(versionSeal));
|
2023-01-19 04:33:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:23:38 +00:00
|
|
|
const options = {
|
2023-02-23 11:14:34 +00:00
|
|
|
files: "dist/**",
|
2020-11-19 23:23:38 +00:00
|
|
|
from: [
|
|
|
|
/%VERSION_NUMBER%/g,
|
|
|
|
/%VERSION_NAME%/g,
|
|
|
|
/%VERSION_CHANNEL%/g,
|
|
|
|
/%BUILD_DATE%/g,
|
|
|
|
/%COMMIT_HASH%/g,
|
|
|
|
],
|
2023-05-30 20:24:43 +00:00
|
|
|
to: [versionNumber, versionName, versionChannel, buildDate, commitHash],
|
2020-11-19 23:23:38 +00:00
|
|
|
};
|
|
|
|
|
2024-06-24 13:14:07 +00:00
|
|
|
replaceInFileSync(options);
|