import type { EditorPackOptions, EditorPackStats } from "./ipc.js"; import type { EditorProjectYaml } from "./project-yaml.js"; export const DEFAULT_PACK_SUBDIR = "dist-pack"; export function defaultPackOutDir(root: string): string { return `${root}/${DEFAULT_PACK_SUBDIR}`; } export function dialogDefaultsFromProject( projectYaml: EditorProjectYaml | null, root: string, fallbackName: string, ): EditorPackOptions { return { name: projectYaml?.pack?.name ?? projectYaml?.name ?? fallbackName ?? "", icon: projectYaml?.icon ?? "", desktop: projectYaml?.pack?.installer === true, installer: projectYaml?.pack?.installer === true, mods: projectYaml?.pack?.mods === true, splitAssets: projectYaml?.pack?.splitAssets === true, outDir: defaultPackOutDir(root), }; } export function projectYamlFromPack( options: EditorPackOptions, prev: EditorProjectYaml | null, ): EditorProjectYaml { const result: EditorProjectYaml = { ...(prev ?? {}) }; const pack = { ...(result.pack ?? {}) }; const name = options.name.trim(); if (name !== "") pack.name = name; else delete pack.name; pack.installer = options.installer; pack.mods = options.mods; pack.splitAssets = options.splitAssets; result.pack = pack; const icon = options.icon.trim(); if (icon !== "") result.icon = icon; else delete result.icon; return result; } export interface EditorPackRequest { contentDir: string; outDir: string; desktop: boolean; installer: boolean; splitAssets: boolean; modsDir?: string; name?: string; } export function resolvePackRequest( root: string, options: EditorPackOptions, hasMods: boolean, ): EditorPackRequest { const request: EditorPackRequest = { contentDir: `${root}/content`, outDir: options.outDir.trim() !== "" ? options.outDir : defaultPackOutDir(root), desktop: options.installer || options.desktop, installer: options.installer, splitAssets: options.splitAssets, }; const name = options.name.trim(); if (name !== "") request.name = name; if (options.mods && hasMods) request.modsDir = `${root}/mods`; return request; } export function packHints(stats: EditorPackStats): string[] { const hints: string[] = ["site: serve the output folder statically and open index.html"]; if (stats.desktop) { hints.push('desktop: cd into the desktop folder, then run "npm install && npm start"'); } if (stats.installer) { hints.push('installer: run "npm install && npm run dist" in the desktop folder (Linux AppImage; NSIS needs a Windows host)'); } return hints; }