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,EAA2D,SAAS,uBAAT,CAAiC,YAAjC,EAA+C,MAA/C,EAAuD,IAAvD,EAA6D,KAA7D,CAA3D;AAxDuC;AAyDxC;;AAvL2C;;;;AA0L9C,SAAA,0BAAA,CAAoC,GAApC,EAA2G;AACzG,MAAI,OAAO,IAAX,EAAiB;AACf,WAAO,IAAP;AACD;;AAED,QAAM,SAAc,EAApB;;AACA,OAAK,MAAM,IAAX,IAAoB,MAAM,OAAN,CAAc,GAAd,IAAqB,GAArB,GAA2B,CAAC,GAAD,CAA/C,EAAuD;AACrD,QAAI,OAAO,IAAP,KAAgB,QAApB,EAA8B;AAC5B,aAAO,IAAP,IAAe,IAAf;AACD,KAFD,MAGK;AACH,aAAO,MAAP,CAAc,MAAd,EAAsB,IAAtB;AACD;AACF;;AACD,SAAO,MAAP;AACD,C","sourcesContent":["import { Arch, executeAppBuilder, replaceDefault as _replaceDefault, serializeToYaml, toLinuxArchString } from \"builder-util\"\nimport { asArray } from \"builder-util-runtime\"\nimport { outputFile } from \"fs-extra-p\"\nimport * as path from \"path\"\nimport * as semver from \"semver\"\nimport { SnapOptions } from \"..\"\nimport { Target } from \"../core\"\nimport { LinuxPackager, toAppImageOrSnapArch } from \"../linuxPackager\"\nimport { PlugDescriptor } from \"../options/SnapOptions\"\nimport { LinuxTargetHelper } from \"./LinuxTargetHelper\"\nimport { createStageDirPath } from \"./targetUtil\"\n\n// libxss1, libasound2, gconf2 - was \"error while loading shared libraries: libXss.so.1\" on Xubuntu 16.04\nconst defaultStagePackages = [\"libasound2\", \"libgconf2-4\", \"libnotify4\", \"libnspr4\", \"libnss3\", \"libpcre3\", \"libpulse0\", \"libxss1\", \"libxtst6\", \"libappindicator1\"]\nconst defaultPlugs = [\"desktop\", \"desktop-legacy\", \"home\", \"x11\", \"unity7\", \"browser-support\", \"network\", \"gsettings\", \"pulseaudio\", \"opengl\"]\n\nexport default class SnapTarget extends Target {\n readonly options: SnapOptions = {...this.packager.platformSpecificBuildOptions, ...(this.packager.config as any)[this.name]}\n\n public isUseTemplateApp = false\n\n constructor(name: string, private readonly packager: LinuxPackager, private readonly helper: LinuxTargetHelper, readonly outDir: string) {\n super(name)\n }\n\n private replaceDefault(inList: Array<string> | null | undefined, defaultList: Array<string>) {\n const result = _replaceDefault(inList, defaultList)\n if (result !== defaultList) {\n this.isUseTemplateApp = false\n }\n return result\n }\n\n private get isElectron2(): boolean {\n return semver.gte(this.packager.config.electronVersion || \"1.8.3\", \"2.0.0-beta.1\")\n }\n\n private createDescriptor(arch: Arch): any {\n const appInfo = this.packager.appInfo\n const snapName = this.packager.executableName.toLowerCase()\n const options = this.options\n const linuxArchName = toAppImageOrSnapArch(arch)\n\n const plugs = normalizePlugConfiguration(options.plugs)\n const plugNames = this.replaceDefault(plugs == null ? null : Object.getOwnPropertyNames(plugs), defaultPlugs)\n const desktopPart = this.isElectron2 ? \"desktop-gtk3\" : \"desktop-gtk2\"\n\n const buildPackages = asArray(options.buildPackages)\n this.isUseTemplateApp = this.options.useTemplateApp !== false && arch === Arch.x64 && buildPackages.length === 0 && this.isElectron2\n\n const appDescriptor: any = {\n command: `command.sh`,\n environment: {\n TMPDIR: \"$XDG_RUNTIME_DIR\",\n PATH: \"$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH\",\n LD_LIBRARY_PATH: [\n \"$SNAP_LIBRARY_PATH\",\n \"$SNAP/usr/lib/\" + linuxArchName + \"-linux-gnu:$SNAP/usr/lib/\" + linuxArchName + \"-linux-gnu/pulseaudio\",\n \"$SNAP/usr/lib/\" + linuxArchName + \"-linux-gnu/mesa-egl\",\n \"$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/\" + linuxArchName + \"-linux-gnu:$SNAP/usr/lib/\" + linuxArchName + \"-linux-gnu\",\n \"$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib\",\n \"$SNAP/lib/\" + linuxArchName + \"-linux-gnu:$SNAP/usr/lib/\" + linuxArchName + \"-linux-gnu\"\n ].join(\":\"),\n ...options.environment,\n },\n plugs: plugNames,\n }\n const snap: any = {\n name: snapName,\n version: appInfo.version,\n summary: options.summary || appInfo.productName,\n description: this.helper.getDescription(options),\n confinement: options.confinement || \"strict\",\n grade: options.grade || \"stable\",\n architectures: [toLinuxArchString(arch)],\n apps: {\n [snapName]: appDescriptor\n },\n parts: {\n app: {\n plugin: \"nil\",\n \"stage-packages\": this.replaceDefault(options.stagePackages, defaultStagePackages),\n after: this.replaceDefault(options.after, [desktopPart]),\n }\n },\n }\n\n if (!this.isUseTemplateApp) {\n appDescriptor.adapter = \"none\"\n }\n\n if (buildPackages.length > 0) {\n snap.parts.app[\"build-packages\"] = buildPackages\n }\n\n if (plugs != null) {\n for (const plugName of plugNames) {\n const plugOptions = plugs[plugName]\n if (plugOptions == null) {\n continue\n }\n\n if (snap.plugs == null) {\n snap.plugs = {}\n }\n snap.plugs[plugName] = plugOptions\n }\n }\n\n if (options.assumes != null) {\n snap.assumes = asArray(options.assumes)\n }\n\n if (!this.isUseTemplateApp && snap.parts.app.after.includes(desktopPart)) {\n // call super build (snapcraftctl build) otherwise /bin/desktop not created\n const desktopPartOverride: any = {\n \"override-build\": `set -x\nsnapcraftctl build\nexport XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share\nupdate-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime\n\nfor dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do\n if [ -f $dir/index.theme ]; then\n if which gtk-update-icon-cache-3.0 &> /dev/null; then\n gtk-update-icon-cache-3.0 -q $dir\n elif which gtk-update-icon-cache &> /dev/null; then\n gtk-update-icon-cache -q $dir\n fi\n fi\ndone`\n }\n\n if (appDescriptor.plugs.includes(\"desktop\") || appDescriptor.plugs.includes(\"desktop-legacy\")) {\n desktopPartOverride.stage = [\"-./usr/share/fonts/**\"]\n }\n\n snap.parts[desktopPart] = desktopPartOverride\n }\n\n return snap\n }\n\n async build(appOutDir: string, arch: Arch): Promise<any> {\n const packager = this.packager\n const options = this.options\n // tslint:disable-next-line:no-invalid-template-strings\n const artifactName = packager.expandArtifactNamePattern(this.options, \"snap\", arch, \"${name}_${version}_${arch}.${ext}\", false)\n const artifactPath = path.join(this.outDir, artifactName)\n this.logBuilding(\"snap\", artifactPath, arch)\n\n const snap: any = this.createDescriptor(arch)\n if (this.isUseTemplateApp) {\n delete snap.parts\n }\n\n const stageDir = await createStageDirPath(this, packager, arch)\n // snapcraft.yaml inside a snap directory\n const snapMetaDir = path.join(stageDir, this.isUseTemplateApp ? \"meta\" : \"snap\")\n\n const args = [\n \"snap\",\n \"--app\", appOutDir,\n \"--stage\", stageDir,\n \"--arch\", toLinuxArchString(arch),\n \"--output\", artifactPath,\n \"--executable\", this.packager.executableName,\n \"--docker-image\", \"electronuserland/builder:latest\",\n ]\n\n await this.helper.icons\n if (this.helper.maxIconPath != null) {\n if (!this.isUseTemplateApp) {\n snap.icon = \"snap/gui/icon.png\"\n }\n args.push(\"--icon\", this.helper.maxIconPath)\n }\n\n const desktopFile = path.join(snapMetaDir, \"gui\", `${snap.name}.desktop`)\n await this.helper.writeDesktopEntry(this.options, packager.executableName, desktopFile, {\n // tslint:disable:no-invalid-template-strings\n Icon: \"${SNAP}/meta/gui/icon.png\"\n })\n\n if (packager.packagerOptions.effectiveOptionComputed != null && await packager.packagerOptions.effectiveOptionComputed({snap, desktopFile})) {\n return\n }\n\n await outputFile(path.join(snapMetaDir, this.isUseTemplateApp ? \"snap.yaml\" : \"snapcraft.yaml\"), serializeToYaml(snap))\n\n const hooksDir = await packager.getResource(options.hooks, \"snap-hooks\")\n if (hooksDir != null) {\n args.push(\"--hooks\", hooksDir)\n }\n\n if (this.isUseTemplateApp) {\n args.push(\"--template-url\", \"electron2\")\n }\n await executeAppBuilder(args)\n packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, \"snap\", arch, false))\n }\n}\n\nfunction normalizePlugConfiguration(raw: Array<string | PlugDescriptor> | PlugDescriptor | null | undefined): { [key: string]: PlugDescriptor | null } | null {\n if (raw == null) {\n return null\n }\n\n const result: any = {}\n for (const item of (Array.isArray(raw) ? raw : [raw])) {\n if (typeof item === \"string\") {\n result[item] = null\n }\n else {\n Object.assign(result, item)\n }\n }\n return result\n}\n"],"sourceRoot":""}