How to use the builder-util.exec 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 / test / src / helpers / wine.ts View on Github external
async prepareWine(wineDir: string) {
    await emptyDir(wineDir)
    //noinspection SpellCheckingInspection
    const env = {
      ...process.env,
      WINEDLLOVERRIDES: "winemenubuilder.exe=d",
      WINEPREFIX: wineDir,
    }

    await exec("wineboot", ["--init"], {env})

    // regedit often doesn't modify correctly
    let systemReg = await fs.readFile(path.join(wineDir, "system.reg"), "utf8")
    systemReg = systemReg.replace('"CSDVersion"="Service Pack 3"', '"CSDVersion"=" "')
    systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
    systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
    systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
    // noinspection SpellCheckingInspection
    systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
    await fs.writeFile(path.join(wineDir, "system.reg"), systemReg)

    // remove links to host OS
    const userDir = this.userDir!!
    const desktopDir = path.join(userDir, "Desktop")
    await Promise.all([
      unlinkIfExists(desktopDir),
github electron-userland / electron-builder / packages / electron-builder-squirrel-windows / src / squirrelPack.ts View on Github external
private async createEmbeddedArchiveFile(nupkgPath: string, dirToArchive: string) {
    const embeddedArchiveFile = await this.packager.getTempFile("setup.zip")
    await exec(path7za, compute7zCompressArgs("zip", {
      isRegularFile: true,
      compression: this.packager.compression,
    }).concat(embeddedArchiveFile, "."), {
      cwd: dirToArchive,
    })
    await exec(path7za, compute7zCompressArgs("zip", {
      isRegularFile: true,
      compression: "store" /* nupkg is already compressed */,
    }).concat(embeddedArchiveFile, nupkgPath))
    return embeddedArchiveFile
  }
}
github electron-userland / electron-builder / packages / app-builder-lib / src / vm / ParallelsVm.ts View on Github external
async exec(file: string, args: Array, options?: ExecFileOptions): Promise {
    await this.ensureThatVmStarted()
    // it is important to use "--current-user" to execute command under logged in user - to access certs.
    return await exec("prlctl", ["exec", this.vm.id, "--current-user", file.startsWith("/") ? macPathToParallelsWindows(file) : file].concat(args), options)
      .catch(error => this.handleExecuteError(error))
  }
github electron-userland / electron-builder / packages / dmg-builder / src / dmg.ts View on Github external
async function computeDmgEntries(specification: DmgOptions, volumePath: string, packager: MacPackager, asyncTaskManager: AsyncTaskManager): Promise {
  let result = ""
  for (const c of specification.contents!!) {
    if (c.path != null && c.path.endsWith(".app") && c.type !== "link") {
      log.warn({path: c.path, reason: "actual path to app will be used instead"}, "do not specify path for application")
    }

    const entryPath = c.path || `${packager.appInfo.productFilename}.app`
    const entryName = c.name || path.basename(entryPath)
    if (result.length !== 0) {
      result += ",\n"
    }
    result += `'${entryName}': (${c.x}, ${c.y})`

    if (c.type === "link") {
      asyncTaskManager.addTask(exec("ln", ["-s", `/${entryPath.startsWith("/") ? entryPath.substring(1) : entryPath}`, `${volumePath}/${entryName}`]))
    }
    // use c.path instead of entryPath (to be sure that this logic is not applied to .app bundle) https://github.com/electron-userland/electron-builder/issues/2147
    else if (!isEmptyOrSpaces(c.path) && (c.type === "file" || c.type === "dir")) {
      const source = await packager.getResource(c.path)
      if (source == null) {
        log.warn({entryPath, reason: "doesn't exist"}, "skipped DMG item copying")
        continue
      }

      const destination = `${volumePath}/${entryName}`
      asyncTaskManager.addTask(c.type === "dir" || (await stat(source)).isDirectory() ? copyDir(source, destination) : copyFile(source, destination))
    }
  }
  return result
}
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / archive.ts View on Github external
if (process.platform === "darwin") {
      lzipPath = path.join(await getLinuxToolsPath(), "bin", lzipPath)
    }
    await exec(lzipPath, [compression === "store" ? "-1" : "-9", "--keep" /* keep (don't delete) input files */, tarFile])
    // bloody lzip creates file in the same dir where input file with postfix `.lz`, option --output doesn't work
    await move(`${tarFile}.lz`, outFile)
    return
  }

  const args = compute7zCompressArgs(format === "tar.xz" ? "xz" : (format === "tar.bz2" ? "bzip2" : "gzip"), {
    isRegularFile: true,
    method: "DEFAULT",
    compression,
  })
  args.push(outFile, tarFile)
  await exec(path7za, args, {
    cwd: path.dirname(dirToArchive),
  }, debug7z.enabled)
}
github electron-userland / electron-builder / test / src / helpers / packTester.ts View on Github external
const checksumData = info.AsarIntegrity
  if (checksumData != null) {
    const data = JSON.parse(checksumData)
    const checksums = data.checksums
    for (const name of Object.keys(checksums)) {
      checksums[name] = "hash"
    }
    info.AsarIntegrity = JSON.stringify(data)
  }

  if (checkOptions.checkMacApp != null) {
    await checkOptions.checkMacApp(packedAppDir, info)
  }

  if (packagerOptions.config != null && (packagerOptions.config as Configuration).cscLink != null) {
    const result = await exec("codesign", ["--verify", packedAppDir])
    expect(result).not.toMatch(/is not signed at all/)
  }
}
github electron-userland / electron-builder / packages / app-builder-lib / src / vm / ParallelsVm.ts View on Github external
if (!this.isExitHookAdded) {
      this.isExitHookAdded = true
      require("async-exit-hook")((callback: (() => void) | null) => {
        const stopArgs = ["suspend", vmId]
        if (callback == null) {
          execFileSync("prlctl", stopArgs)
        }
        else {
          exec("prlctl", stopArgs)
            .then(callback)
            .catch(callback)
        }
      })
    }
    await exec("prlctl", ["start", vmId])
  }
github electron-userland / electron-builder / packages / dmg-builder / src / dmg.ts View on Github external
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 transformBackgroundFileIfNeed(file: string, tmpDir: TmpDir): Promise {
  if (file.endsWith(".tiff") || file.endsWith(".TIFF")) {
    return file
  }

  const retinaFile = file.replace(/\.([a-z]+)$/, "@2x.$1")
  if (await exists(retinaFile)) {
    const tiffFile = await tmpDir.getTempFile({suffix: ".tiff"})
    await exec("tiffutil", ["-cathidpicheck", file, retinaFile, "-out", tiffFile])
    return tiffFile
  }

  return file
}
github electron-userland / electron-builder / packages / dmg-builder / src / dmgUtil.ts View on Github external
export async function attachAndExecute(dmgPath: string, readWrite: boolean, task: () => Promise) {
  //noinspection SpellCheckingInspection
  const args = ["attach", "-noverify", "-noautoopen"]
  if (readWrite) {
    args.push("-readwrite")
  }

  args.push(dmgPath)
  const attachResult = await exec("hdiutil", args)
  const deviceResult = attachResult == null ? null : /^(\/dev\/\w+)/.exec(attachResult)
  const device = deviceResult == null || deviceResult.length !== 2 ? null : deviceResult[1]
  if (device == null) {
    throw new Error(`Cannot mount: ${attachResult}`)
  }

  return await executeFinally(task(), () => detach(device))
}