How to use the builder-util.asArray function in builder-util

To help you get started, we’ve selected a few builder-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electron-userland / electron-builder / packages / app-builder-lib / src / targets / targetFactory.ts View on Github external
}

  const defaultArchs: Array = raw.size === 0 ? [platform === Platform.MAC ? "x64" : process.arch as ArchType] : Array.from(raw.keys()).map(it => Arch[it] as ArchType)
  const result = new Map(raw)
  for (const target of asArray(platformPackager.platformSpecificBuildOptions.target).map(it => typeof it === "string" ? {target: it} : it)) {
    let name = target.target
    let archs = target.arch
    const suffixPos = name.lastIndexOf(":")
    if (suffixPos > 0) {
      name = target.target.substring(0, suffixPos)
      if (archs == null) {
        archs = target.target.substring(suffixPos + 1) as ArchType
      }
    }

    for (const arch of archs == null ? defaultArchs : asArray(archs)) {
      addValue(result, archFromString(arch), name)
    }
  }

  if (result.size === 0) {
    const defaultTarget = platformPackager.defaultTarget
    if (raw.size === 0 && platform === Platform.LINUX && (process.platform === "darwin" || process.platform === "win32")) {
      result.set(Arch.x64, defaultTarget)
      // cannot enable arm because of native dependencies - e.g. keytar doesn't provide pre-builds for arm
      // result.set(Arch.armv7l, ["snap"])
    }
    else {
      for (const arch of defaultArchs) {
        result.set(archFromString(arch), defaultTarget)
      }
    }
github electron-userland / electron-builder / packages / app-builder-lib / src / electron / electronMac.ts View on Github external
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
      const extensions = asArray(fileAssociation.ext).map(normalizeExt)
      const customIcon = await packager.getResource(getPlatformIconFileName(fileAssociation.icon, true), `${extensions[0]}.icns`)
      let iconFile = appPlist.CFBundleIconFile
      if (customIcon != null) {
        iconFile = path.basename(customIcon)
        await copyOrLinkFile(customIcon, path.join(path.join(contentsPath, "Resources"), iconFile))
      }

      const result = {
        CFBundleTypeExtensions: extensions,
        CFBundleTypeName: fileAssociation.name || extensions[0],
        CFBundleTypeRole: fileAssociation.role || "Editor",
        CFBundleTypeIconFile: iconFile
      } as any

      if (fileAssociation.isPackage) {
        result.LSTypeIsPackage = true
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / nsis / NsisTarget.ts View on Github external
installedIconPath = `$INSTDIR\\resources\\${path.basename(customIcon)}`
              registerFileAssociationsScript.file(installedIconPath, customIcon)
            }

            const icon = `"${installedIconPath}"`
            const commandText = `"Open with ${packager.appInfo.productName}"`
            const command = '"$appExe $\\"%1$\\""'
            registerFileAssociationsScript.insertMacro("APP_ASSOCIATE", `"${ext}" "${item.name || ext}" "${item.description || ""}" ${icon} ${commandText} ${command}`)
          }
        }
        scriptGenerator.macro("registerFileAssociations", registerFileAssociationsScript)
      }
      else {
        const unregisterFileAssociationsScript = new NsisScriptGenerator()
        for (const item of fileAssociations) {
          for (const ext of asArray(item.ext)) {
            unregisterFileAssociationsScript.insertMacro("APP_UNASSOCIATE", `"${normalizeExt(ext)}" "${item.name || ext}"`)
          }
        }
        scriptGenerator.macro("unregisterFileAssociations", unregisterFileAssociationsScript)
      }
    }

    return scriptGenerator.build() + originalScript
  }
}
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / AppxTarget.ts View on Github external
private getExtensions(executable: string, displayName: string): string {
    const uriSchemes = asArray(this.packager.config.protocols)
      .concat(asArray(this.packager.platformSpecificBuildOptions.protocols))

    const fileAssociations = asArray(this.packager.config.fileAssociations)
      .concat(asArray(this.packager.platformSpecificBuildOptions.fileAssociations))

    let isAddAutoLaunchExtension = this.options.addAutoLaunchExtension
    if (isAddAutoLaunchExtension === undefined) {
      const deps = this.packager.info.metadata.dependencies
      isAddAutoLaunchExtension = deps != null && deps["electron-winstore-auto-launch"] != null
    }

    if (!isAddAutoLaunchExtension && uriSchemes.length === 0 && fileAssociations.length === 0) {
      return ""
    }

    let extensions = ""

    if (isAddAutoLaunchExtension) {
      extensions += `
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / AppxTarget.ts View on Github external
private getExtensions(executable: string, displayName: string): string {
    const uriSchemes = asArray(this.packager.config.protocols)
      .concat(asArray(this.packager.platformSpecificBuildOptions.protocols))

    const fileAssociations = asArray(this.packager.config.fileAssociations)
      .concat(asArray(this.packager.platformSpecificBuildOptions.fileAssociations))

    let isAddAutoLaunchExtension = this.options.addAutoLaunchExtension
    if (isAddAutoLaunchExtension === undefined) {
      const deps = this.packager.info.metadata.dependencies
      isAddAutoLaunchExtension = deps != null && deps["electron-winstore-auto-launch"] != null
    }

    if (!isAddAutoLaunchExtension && uriSchemes.length === 0 && fileAssociations.length === 0) {
      return ""
    }

    let extensions = ""
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / nsis / NsisTarget.ts View on Github external
const preCompressedFileExtensions = this.getPreCompressedFileExtensions()
    if (preCompressedFileExtensions != null && preCompressedFileExtensions.length !== 0) {
      for (const [arch, dir] of this.archs.entries()) {
        await generateForPreCompressed(preCompressedFileExtensions, dir, arch, scriptGenerator)
      }
    }

    const fileAssociations = packager.fileAssociations
    if (fileAssociations.length !== 0) {

      scriptGenerator.include(path.join(path.join(nsisTemplatesDir, "include"), "FileAssociation.nsh"))
      if (isInstaller) {
        const registerFileAssociationsScript = new NsisScriptGenerator()
        for (const item of fileAssociations) {
          const extensions = asArray(item.ext).map(normalizeExt)
          for (const ext of extensions) {
            const customIcon = await packager.getResource(getPlatformIconFileName(item.icon, false), `${extensions[0]}.ico`)
            let installedIconPath = "$appExe,0"
            if (customIcon != null) {
              installedIconPath = `$INSTDIR\\resources\\${path.basename(customIcon)}`
              registerFileAssociationsScript.file(installedIconPath, customIcon)
            }

            const icon = `"${installedIconPath}"`
            const commandText = `"Open with ${packager.appInfo.productName}"`
            const command = '"$appExe $\\"%1$\\""'
            registerFileAssociationsScript.insertMacro("APP_ASSOCIATE", `"${ext}" "${item.name || ext}" "${item.description || ""}" ${icon} ${commandText} ${command}`)
          }
        }
        scriptGenerator.macro("registerFileAssociations", registerFileAssociationsScript)
      }
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / LinuxTargetHelper.ts View on Github external
...targetSpecificOptions.desktop,
    }

    const description = this.getDescription(targetSpecificOptions)
    if (!isEmptyOrSpaces(description)) {
      desktopMeta.Comment = description
    }

    const mimeTypes: Array = asArray(targetSpecificOptions.mimeTypes)
    for (const fileAssociation of packager.fileAssociations) {
      if (fileAssociation.mimeType != null) {
        mimeTypes.push(fileAssociation.mimeType)
      }
    }

    for (const protocol of asArray(packager.config.protocols).concat(asArray(packager.platformSpecificBuildOptions.protocols))) {
      for (const scheme of asArray(protocol.schemes)) {
        mimeTypes.push(`x-scheme-handler/${scheme}`)
      }
    }

    if (mimeTypes.length !== 0) {
      desktopMeta.MimeType = mimeTypes.join(";") + ";"
    }

    let category = targetSpecificOptions.category
    if (isEmptyOrSpaces(category)) {
      const macCategory = (packager.config.mac || {}).category
      if (macCategory != null) {
        category = macToLinuxCategory[macCategory]
      }
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / AppxTarget.ts View on Github external
return "assets\\Square44x44Logo.png"

          case "lockScreen":
            return lockScreenTag(userAssets)

          case "defaultTile":
            return defaultTileTag(userAssets, options.showNameOnTiles || false)

          case "splashScreen":
            return splashScreenTag(userAssets)

          case "arch":
            return arch === Arch.ia32 ? "x86" : (arch === Arch.arm64 ? "arm64" : "x64")

          case "resourceLanguages":
            return resourceLanguageTag(asArray(options.languages))

          case "extensions":
            return this.getExtensions(executable, displayName)

          default:
            throw new Error(`Macro ${p1} is not defined`)
        }
      })
    await writeFile(outFile, manifest)
github electron-userland / electron-builder / packages / app-builder-lib / src / publish / PublishManager.ts View on Github external
else if (!isEmptyOrSpaces(process.env.BT_TOKEN)) {
      serviceName = "bintray"
    }

    if (serviceName != null) {
      log.debug(null, `detect ${serviceName} as publish provider`)
      return [(await getResolvedPublishConfig(platformPackager, packager, {provider: serviceName}, arch, errorIfCannot))!]
    }
  }

  if (publishers == null) {
    return []
  }

  debug(`Explicit publish provider: ${safeStringifyJson(publishers)}`)
  return await (BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(platformPackager, packager, typeof it === "string" ? {provider: it} : it, arch, errorIfCannot)) as Promise>)
}
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / AppxTarget.ts View on Github external
if (!isAddAutoLaunchExtension && uriSchemes.length === 0 && fileAssociations.length === 0) {
      return ""
    }

    let extensions = ""

    if (isAddAutoLaunchExtension) {
      extensions += `
        
          
        `
    }

    for (const protocol of uriSchemes) {
      for (const scheme of asArray(protocol.schemes)) {
        extensions += `
          
            
               ${protocol.name}
             
          `
      }
    }

    for (const fileAssociation of fileAssociations) {
      for (const ext of asArray(fileAssociation.ext)) {
        extensions += `
          
            
              
                .${ext}