{"version":3,"file":"mac.mjs","names":["copyFile","mkdir","readFile","stat","writeFile","join","pathJoin","basename","dirname","fsLstatExists","Plist","ValueDict","ValueString","trimExtension","machoTypesFile","machoAppLauncher","ProjectorOttoMac","BundleOtto","BundleOttoMac","constructor","path","flat","projector","_createProjector","extension","_getLauncherName","_getProjectorPathNested","projName","_getProjectorPath","_writeLauncher","appContents","appMacOS","appResources","appInfoPlist","appPkgInfo","plist","fromXml","infoPlistPath","dict","getValue","castAs","projBinaryPath","binaryPath","projBinaryTypes","projIconName","value","projIconPath","iconPath","projPkgInfoPath","pkgInfoPath","launcherName","launcherPath","recursive","mode","pathIcon","set","toXml"],"sources":["../../../src/bundle/otto/mac.ts"],"sourcesContent":["import {copyFile, mkdir, readFile, stat, writeFile} from 'node:fs/promises';\nimport {join as pathJoin, basename, dirname} from 'node:path';\n\nimport {fsLstatExists} from '@shockpkg/archive-files';\nimport {Plist, ValueDict, ValueString} from '@shockpkg/plist-dom';\n\nimport {trimExtension} from '../../util.ts';\nimport {machoTypesFile, machoAppLauncher} from '../../util/mac.ts';\nimport {ProjectorOttoMac} from '../../projector/otto/mac.ts';\nimport {BundleOtto} from '../otto.ts';\n\n/**\n * BundleOttoMac object.\n */\nexport class BundleOttoMac extends BundleOtto {\n\t/**\n\t * ProjectorOttoMac instance.\n\t */\n\tpublic readonly projector: ProjectorOttoMac;\n\n\t/**\n\t * BundleOttoMac constructor.\n\t *\n\t * @param path Output path for the main application.\n\t * @param flat Flat bundle.\n\t */\n\tconstructor(path: string, flat = false) {\n\t\tsuper(path, flat);\n\n\t\tthis.projector = this._createProjector();\n\t}\n\n\t/**\n\t * @inheritdoc\n\t */\n\tpublic get extension() {\n\t\treturn '.app';\n\t}\n\n\t/**\n\t * Get the launcher name.\n\t *\n\t * @returns Launcher name.\n\t */\n\tprotected _getLauncherName() {\n\t\treturn trimExtension(basename(this.path), this.extension, true);\n\t}\n\n\t/**\n\t * @inheritdoc\n\t */\n\tprotected _getProjectorPathNested(): string {\n\t\tconst projName = `${this._getLauncherName()}${this.extension}`;\n\t\treturn pathJoin(this.path, 'Contents', 'Resources', projName);\n\t}\n\n\t/**\n\t * @inheritdoc\n\t */\n\tprotected _createProjector() {\n\t\treturn new ProjectorOttoMac(this._getProjectorPath());\n\t}\n\n\t/**\n\t * @inheritdoc\n\t */\n\tprotected async _writeLauncher() {\n\t\tconst {path, projector} = this;\n\n\t\t// Create paths to things to create.\n\t\tconst appContents = pathJoin(path, 'Contents');\n\t\tconst appMacOS = pathJoin(appContents, 'MacOS');\n\t\tconst appResources = pathJoin(appContents, 'Resources');\n\t\tconst appInfoPlist = pathJoin(appContents, 'Info.plist');\n\t\tconst appPkgInfo = pathJoin(appContents, 'PkgInfo');\n\n\t\t// Read the projector Info.plist.\n\t\tconst plist = new Plist();\n\t\tplist.fromXml(await readFile(projector.infoPlistPath, 'utf8'));\n\t\tconst dict = plist.getValue().castAs(ValueDict);\n\n\t\t// Get the binary path and read the types.\n\t\tconst projBinaryPath = projector.binaryPath;\n\t\tconst projBinaryTypes = await machoTypesFile(projBinaryPath);\n\n\t\t// Get the icon path.\n\t\tconst projIconName = dict\n\t\t\t.getValue('CFBundleIconFile')\n\t\t\t.castAs(ValueString).value;\n\t\tconst projIconPath = projector.iconPath;\n\n\t\t// Get the PkgInfo path.\n\t\tconst projPkgInfoPath = projector.pkgInfoPath;\n\n\t\t// Create the launcher binary with the same types and mode.\n\t\tconst launcherName = this._getLauncherName();\n\t\tconst launcherPath = pathJoin(appMacOS, launcherName);\n\t\tawait mkdir(dirname(launcherPath), {recursive: true});\n\t\tawait writeFile(launcherPath, await machoAppLauncher(projBinaryTypes), {\n\t\t\tmode: (await stat(projBinaryPath)).mode\n\t\t});\n\n\t\t// Copy the projector icon if present.\n\t\tconst pathIcon = pathJoin(appResources, projIconName);\n\t\tif (await fsLstatExists(projIconPath)) {\n\t\t\tawait copyFile(projIconPath, pathIcon);\n\t\t}\n\n\t\t// Copy PkgInfo if present.\n\t\tif (await fsLstatExists(projPkgInfoPath)) {\n\t\t\tawait copyFile(projPkgInfoPath, appPkgInfo);\n\t\t}\n\n\t\t// Update the executable name in the plist for the launcher.\n\t\tdict.set('CFBundleExecutable', new ValueString(launcherName));\n\n\t\t// Write the updated Info.plist.\n\t\tawait mkdir(dirname(appInfoPlist), {recursive: true});\n\t\tawait writeFile(appInfoPlist, plist.toXml(), 'utf8');\n\t}\n}\n"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,SAAS,QAAO,kBAAkB;AAC3E,SAAQC,IAAI,IAAIC,QAAQ,EAAEC,QAAQ,EAAEC,OAAO,QAAO,WAAW;AAE7D,SAAQC,aAAa,QAAO,yBAAyB;AACrD,SAAQC,KAAK,EAAEC,SAAS,EAAEC,WAAW,QAAO,qBAAqB;AAEjE,SAAQC,aAAa,QAAO,gBAAe;AAC3C,SAAQC,cAAc,EAAEC,gBAAgB,QAAO,oBAAmB;AAClE,SAAQC,gBAAgB,QAAO,8BAA6B;AAC5D,SAAQC,UAAU,QAAO,aAAY;;AAErC;AACA;AACA;AACA,OAAO,MAAMC,aAAa,SAASD,UAAU,CAAC;EAC7C;AACD;AACA;;EAGC;AACD;AACA;AACA;AACA;AACA;EACCE,WAAWA,CAACC,IAAY,EAAEC,IAAI,GAAG,KAAK,EAAE;IACvC,KAAK,CAACD,IAAI,EAAEC,IAAI,CAAC;IAEjB,IAAI,CAACC,SAAS,GAAG,IAAI,CAACC,gBAAgB,CAAC,CAAC;EACzC;;EAEA;AACD;AACA;EACC,IAAWC,SAASA,CAAA,EAAG;IACtB,OAAO,MAAM;EACd;;EAEA;AACD;AACA;AACA;AACA;EACWC,gBAAgBA,CAAA,EAAG;IAC5B,OAAOZ,aAAa,CAACN,QAAQ,CAAC,IAAI,CAACa,IAAI,CAAC,EAAE,IAAI,CAACI,SAAS,EAAE,IAAI,CAAC;EAChE;;EAEA;AACD;AACA;EACWE,uBAAuBA,CAAA,EAAW;I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