"use strict"; const fs = require("node:fs"); const path = require("node:path"); const { LicenseAcceptance } = require("../src/main/legal/licenseAcceptance"); const { GUIDANCE_FILES } = require("../src/main/legal/guidanceDocuments"); const root = path.join(__dirname, ".."); const repositoryLicense = path.join(root, "..", "LICENSE"); if (fs.existsSync(repositoryLicense)) fs.copyFileSync(repositoryLicense, path.join(root, "LICENSE")); for (const name of Object.values(GUIDANCE_FILES)) { const source = path.join(root, "..", "docs", name); if (fs.existsSync(source)) fs.copyFileSync(source, path.join(root, "docs", name)); if (!fs.statSync(path.join(root, "docs", name), { throwIfNoEntry: false })?.isFile()) throw new Error(`Missing documentation: ${name}`); } const legal = new LicenseAcceptance({ storageRoot: root, licensePath: path.join(root, "LICENSE"), appVersion: "validation", buildId: "validation" }); fs.mkdirSync(path.join(root, "build"), { recursive: true }); fs.copyFileSync(path.join(root, "LICENSE"), path.join(root, "build", "license.txt")); // NSIS and macOS SLA support RTF Unicode escapes. DMG plain-text licenses use // legacy Mac Roman encoding, which cannot represent the licensor's name. const licenseText = fs.readFileSync(path.join(root, "LICENSE"), "utf8"); function toRtf(text) { const rtfText = text.split("").map(character => { if (character === "\n") return "\\par\n"; if (character === "\r") return ""; if ("\\{}".includes(character)) return `\\${character}`; const code = character.charCodeAt(0); return code > 127 ? `\\u${code > 32767 ? code - 65536 : code}?` : character; }).join(""); return `{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0 Arial;}}\\uc1\\f0\\fs20\n${rtfText}}\n`; } fs.writeFileSync(path.join(root, "build", "license.rtf"), toRtf(licenseText), "ascii"); const installationText = "CH-J Server Manager — Before installation / Před instalací / Vor der Installation\n\n" + "The following guidance is informational, non-binding and separate from the Software License. The agreement control applies only to the license in the final section.\n" + "Následující pokyny jsou informativní, nezávazné a oddělené od licence. Souhlas se vztahuje pouze na licenci v závěrečné části.\n" + "Die folgenden Hinweise sind informativ, unverbindlich und von der Lizenz getrennt. Die Zustimmung gilt nur für die Lizenz im letzten Abschnitt.\n\n" + Object.values(legal.guidance).join("\n\n---\n\n") + "\n\n---\n\nAPPLICATION LICENSE — AGREEMENT APPLIES ONLY TO THIS SECTION\n\n" + licenseText; fs.writeFileSync(path.join(root, "build", "installation.rtf"), toRtf(installationText), "ascii"); for (const [language, text] of Object.entries(legal.guidance)) { fs.writeFileSync(path.join(root, "build", `guidance-${language}.txt`), "\ufeff" + text.replace(/\r?\n/g, "\r\n"), "utf16le"); } console.log("Prepared CH-J Proprietary Software License 1.14 and operational guidance.");