How to use the builder-util.AsyncTaskManager 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 / nsis / NsisTarget.ts View on Github external
private async computeFinalScript(originalScript: string, isInstaller: boolean) {
    const packager = this.packager
    const options = this.options
    const langConfigurator = new LangConfigurator(options)

    const scriptGenerator = new NsisScriptGenerator()
    const taskManager = new AsyncTaskManager(packager.info.cancellationToken)

    if (isInstaller) {
      // http://stackoverflow.com/questions/997456/nsis-license-file-based-on-language-selection
      taskManager.add(() => computeLicensePage(packager, options, scriptGenerator, langConfigurator.langs))
    }

    await taskManager.awaitTasks()

    if (this.isPortable) {
      return scriptGenerator.build() + originalScript
    }

    const preCompressedFileExtensions = this.getPreCompressedFileExtensions()
    if (preCompressedFileExtensions != null && preCompressedFileExtensions.length !== 0) {
      for (const [arch, dir] of this.archs.entries()) {
        await generateForPreCompressed(preCompressedFileExtensions, dir, arch, scriptGenerator)
github electron-userland / electron-builder / packages / app-builder-lib / src / util / appFileCopier.ts View on Github external
export async function copyAppFiles(fileSet: ResolvedFileSet, packager: Packager, transformer: FileTransformer) {
  const metadata = fileSet.metadata
  // search auto unpacked dir
  const taskManager = new AsyncTaskManager(packager.cancellationToken)
  const createdParentDirs = new Set()

  const fileCopier = new FileCopier(file => {
    // https://github.com/electron-userland/electron-builder/issues/3038
    return !(isLibOrExe(file) || file.endsWith(".node"))
  }, transformer)
  const links: Array = []
  for (let i = 0, n = fileSet.files.length; i < n; i++) {
    const sourceFile = fileSet.files[i]
    const stat = metadata.get(sourceFile)
    if (stat == null) {
      // dir
      continue
    }

    const destinationFile = getDestinationPath(sourceFile, fileSet)
github electron-userland / electron-builder / packages / app-builder-lib / src / linuxPackager.ts View on Github external
const target = new targetClass(name, this, getHelper(), outDir)
        if (process.platform === "win32" || process.env._REMOTE_BUILD) {
          if (remoteBuilder == null) {
            remoteBuilder = new RemoteBuilder(this)
          }
          // return remoteBuilder.buildTarget(this, arch, appOutDir, this.packager)
          return new RemoteTarget(target, remoteBuilder)
        }
        return target
      })
    }
  }
}

class RemoteTarget extends Target {
  private buildTaskManager = new AsyncTaskManager(this.remoteBuilder.packager.info.cancellationToken)

  get options(): TargetSpecificOptions | null | undefined {
    return this.target.options
  }

  get outDir(): string {
    return this.target.outDir
  }

  constructor(private readonly target: Target, private readonly remoteBuilder: RemoteBuilder) {
    super(target.name, true /* all must be scheduled in time (so, on finishBuild RemoteBuilder will have all targets added - so, we must set isAsyncSupported to true (resolved promise is returned)) */)
  }

  async finishBuild() {
    await this.buildTaskManager.awaitTasks()
    await this.remoteBuilder.build()
github electron-userland / electron-builder / packages / app-builder-lib / src / asar / asarUtil.ts View on Github external
const correctDirNodeUnpackedFlag = async (filePathInArchive: string, dirNode: Node) => {
      for (const dir of unpackedDirs) {
        if (filePathInArchive.length > (dir.length + 2) && filePathInArchive[dir.length] === path.sep && filePathInArchive.startsWith(dir)) {
          dirNode.unpacked = true
          unpackedDirs.add(filePathInArchive)
          // not all dirs marked as unpacked after first iteration - because node module dir can be marked as unpacked after processing node module dir content
          // e.g. node-notifier/example/advanced.js processed, but only on process vendor/terminal-notifier.app module will be marked as unpacked
          await ensureDir(path.join(this.unpackedDest, filePathInArchive))
          break
        }
      }
    }

    const transformedFiles = fileSet.transformedFiles
    const taskManager = new AsyncTaskManager(packager.cancellationToken)
    const fileCopier = new FileCopier()

    let currentDirNode: Node | null = null
    let currentDirPath: string | null = null

    const unpackedFileIndexSet = new Set()

    for (let i = 0, n = fileSet.files.length; i < n; i++) {
      const file = fileSet.files[i]
      const stat = metadata.get(file)
      if (stat == null) {
        continue
      }

      const pathInArchive = path.relative(rootForAppFilesWithoutAsar, getDestinationPath(file, fileSet))
github electron-userland / electron-builder / packages / dmg-builder / src / dmg.ts View on Github external
}
    if (env.windowHeight == null) {
      env.windowHeight = data.backgroundHeight.toString()
    }

    if (env.windowX == null) {
      env.windowX = 400
    }
    if (env.windowY == null) {
      env.windowY = Math.round((1440 - env.windowHeight) / 2).toString()
    }
  }

  Object.assign(env, data)

  const asyncTaskManager = new AsyncTaskManager(packager.info.cancellationToken)
  env.iconLocations = await computeDmgEntries(specification, volumePath, packager, asyncTaskManager)
  await asyncTaskManager.awaitTasks()

  await exec("/usr/bin/python", [path.join(getDmgVendorPath(), "dmgbuild/core.py")], {
    cwd: getDmgVendorPath(),
    env
  })
  return packager.packagerOptions.effectiveOptionComputed == null || !(await packager.packagerOptions.effectiveOptionComputed({volumePath, specification, packager}))
}
github electron-userland / electron-builder / packages / dmg-builder / src / dmg.ts View on Github external
async function computeAssetSize(cancellationToken: CancellationToken, dmgFile: string, specification: DmgOptions, backgroundFile: string | null | undefined) {
  const asyncTaskManager = new AsyncTaskManager(cancellationToken)
  asyncTaskManager.addTask(stat(dmgFile))

  if (specification.icon != null) {
    asyncTaskManager.addTask(statOrNull(specification.icon))
  }

  if (backgroundFile != null) {
    asyncTaskManager.addTask(stat(backgroundFile))
  }

  let result = 32 * 1024
  for (const stat of await asyncTaskManager.awaitTasks()) {
    if (stat != null) {
      result += stat.size
    }
  }
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / nsis / NsisTarget.ts View on Github external
protected configureDefines(oneClick: boolean, defines: any): Promise {
    const packager = this.packager
    const options = this.options

    const asyncTaskManager = new AsyncTaskManager(packager.info.cancellationToken)

    if (oneClick) {
      defines.ONE_CLICK = null

      if (options.runAfterFinish !== false) {
        defines.RUN_AFTER_FINISH = null
      }

      asyncTaskManager.add(async () => {
        const installerHeaderIcon = await packager.getResource(options.installerHeaderIcon, "installerHeaderIcon.ico")
        if (installerHeaderIcon != null) {
          defines.HEADER_ICO = installerHeaderIcon
        }
      })
    }
    else {