How to use the builder-util/out/fs.unlinkIfExists 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
// 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),
      unlinkIfExists(path.join(userDir, "My Documents")),
      unlinkIfExists(path.join(userDir, "My Music")),
      unlinkIfExists(path.join(userDir, "My Pictures")),
      unlinkIfExists(path.join(userDir, "My Videos")),
    ])

    await ensureDir(desktopDir)
    return env
  }
}
github electron-userland / electron-builder / test / src / helpers / wine.ts View on Github external
// 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),
      unlinkIfExists(path.join(userDir, "My Documents")),
      unlinkIfExists(path.join(userDir, "My Music")),
      unlinkIfExists(path.join(userDir, "My Pictures")),
      unlinkIfExists(path.join(userDir, "My Videos")),
    ])

    await ensureDir(desktopDir)
    return env
  }
}
github electron-userland / electron-builder / test / src / helpers / wine.ts View on Github external
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),
      unlinkIfExists(path.join(userDir, "My Documents")),
      unlinkIfExists(path.join(userDir, "My Music")),
      unlinkIfExists(path.join(userDir, "My Pictures")),
      unlinkIfExists(path.join(userDir, "My Videos")),
    ])

    await ensureDir(desktopDir)
    return env
  }
}
github electron-userland / electron-builder / packages / app-builder-lib / src / macPackager.ts View on Github external
async applyCommonInfo(appPlist: any, contentsPath: string) {
    const appInfo = this.appInfo
    const appFilename = appInfo.productFilename

    // https://github.com/electron-userland/electron-builder/issues/1278
    appPlist.CFBundleExecutable = appFilename.endsWith(" Helper") ? appFilename.substring(0, appFilename.length - " Helper".length) : appFilename

    const icon = await this.getIconPath()
    if (icon != null) {
      const oldIcon = appPlist.CFBundleIconFile
      const resourcesPath = path.join(contentsPath, "Resources")
      if (oldIcon != null) {
        await unlinkIfExists(path.join(resourcesPath, oldIcon))
      }
      const iconFileName = `${appFilename}.icns`
      appPlist.CFBundleIconFile = iconFileName
      await copyFile(icon, path.join(resourcesPath, iconFileName))
    }
    appPlist.CFBundleName = appInfo.productName
    appPlist.CFBundleDisplayName = appInfo.productName

    const minimumSystemVersion = this.platformSpecificBuildOptions.minimumSystemVersion
    if (minimumSystemVersion != null) {
      appPlist.LSMinimumSystemVersion = minimumSystemVersion
    }

    appPlist.CFBundleIdentifier = appInfo.macBundleIdentifier

    appPlist.CFBundleShortVersionString = this.platformSpecificBuildOptions.bundleShortVersion || appInfo.version
github electron-userland / electron-builder / packages / app-builder-lib / src / electron / electronMac.ts View on Github external
}
  if (helperPluginPlist != null) {
    plistDataToWrite[helperPluginPlistFilename] = helperPluginPlist
  }
  if (helperGPUPlist != null) {
    plistDataToWrite[helperGPUPlistFilename] = helperGPUPlist
  }
  if (helperLoginPlist != null) {
    plistDataToWrite[helperLoginPlistFilename] = helperLoginPlist
  }

  await Promise.all([
    executeAppBuilderAndWriteJson(["encode-plist"], plistDataToWrite),
    doRename(path.join(contentsPath, "MacOS"), "Electron", appPlist.CFBundleExecutable),
    unlinkIfExists(path.join(appOutDir, "LICENSE")),
    unlinkIfExists(path.join(appOutDir, "LICENSES.chromium.html")),
  ])

  await moveHelpers(getAvailableHelperSuffixes(helperEHPlist, helperNPPlist, helperRendererPlist, helperPluginPlist, helperGPUPlist), frameworksPath, appFilename, "Electron")

  if (helperLoginPlist != null) {
    const prefix = "Electron"
    const suffix = " Login Helper"
    const executableBasePath = path.join(loginItemPath, `${prefix}${suffix}.app`, "Contents", "MacOS")
    await doRename(executableBasePath, `${prefix}${suffix}`, appFilename + suffix)
      .then(() => doRename(loginItemPath, `${prefix}${suffix}.app`, `${appFilename}${suffix}.app`))
  }

  const appPath = path.join(appOutDir, `${appFilename}.app`)
  await rename(path.dirname(contentsPath), appPath)
  // https://github.com/electron-userland/electron-builder/issues/840
  const now = Date.now() / 1000
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / archive.ts View on Github external
export async function archive(format: string, outFile: string, dirToArchive: string, options: ArchiveOptions = {}): Promise {
  const args = compute7zCompressArgs(format, options)
  // remove file before - 7z doesn't overwrite file, but update
  await unlinkIfExists(outFile)

  args.push(outFile, options.withoutDir ? "." : path.basename(dirToArchive))
  if (options.excluded != null) {
    for (const mask of options.excluded) {
      args.push(`-xr!${mask}`)
    }
  }

  try {
    await exec(path7za, args, {
      cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive),
    }, debug7z.enabled)
  }
  catch (e) {
    if (e.code === "ENOENT" && !(await exists(dirToArchive))) {
      throw new Error(`Cannot create archive: "${dirToArchive}" doesn't exist`)
github electron-userland / electron-builder / packages / app-builder-lib / src / electron / ElectronFramework.ts View on Github external
function cleanupAfterUnpack(prepareOptions: PrepareApplicationStageDirectoryOptions, distMacOsAppName: string, isFullCleanup: boolean) {
  const out = prepareOptions.appOutDir
  const isMac = prepareOptions.packager.platform === Platform.MAC
  const resourcesPath = isMac ? path.join(out, distMacOsAppName, "Contents", "Resources") : path.join(out, "resources")

  return Promise.all([
    isFullCleanup ? unlinkIfExists(path.join(resourcesPath, "default_app.asar")) : Promise.resolve(),
    isFullCleanup ? unlinkIfExists(path.join(out, "version")) : Promise.resolve(),
    isMac ? Promise.resolve() : rename(path.join(out, "LICENSE"), path.join(out, "LICENSE.electron.txt")).catch(() => {/* ignore */}),
  ])
}
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / archive.ts View on Github external
export async function tar(compression: CompressionLevel | any | any, format: string, outFile: string, dirToArchive: string, isMacApp: boolean, tempDirManager: TmpDir): Promise {
  const tarFile = await tempDirManager.getTempFile({suffix: ".tar"})
  const tarArgs = debug7zArgs("a")
  tarArgs.push(tarFile)
  tarArgs.push(path.basename(dirToArchive))

  await Promise.all([
    exec(path7za, tarArgs, {cwd: path.dirname(dirToArchive)}),
    // remove file before - 7z doesn't overwrite file, but update
    unlinkIfExists(outFile),
  ])

  if (!isMacApp) {
    await exec(path7za, ["rn", tarFile, path.basename(dirToArchive), path.basename(outFile, `.${format}`)])
  }

  if (format === "tar.lz") {
    // noinspection SpellCheckingInspection
    let lzipPath = "lzip"
    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
github electron-userland / electron-builder / packages / electron-builder / src / cli / create-self-signed-cert.ts View on Github external
const tmpDir = new TmpDir("create-self-signed-cert")
  const targetDir = process.cwd()
  const tempPrefix = path.join(await tmpDir.getTempDir({prefix: "self-signed-cert-creator"}), sanitizeFileName(publisher))
  const cer = `${tempPrefix}.cer`
  const pvk = `${tempPrefix}.pvk`

  log.info(chalk.bold('When asked to enter a password ("Create Private Key Password"), please select "None".'))

  try {
    await ensureDir(path.dirname(tempPrefix))
    const vendorPath = path.join(await getSignVendorPath(), "windows-10", process.arch)
    await exec(path.join(vendorPath, "makecert.exe"),
      ["-r", "-h", "0", "-n", `CN=${quoteString(publisher)}`, "-eku", "1.3.6.1.5.5.7.3.3", "-pe", "-sv", pvk, cer])

    const pfx = path.join(targetDir, `${sanitizeFileName(publisher)}.pfx`)
    await unlinkIfExists(pfx)
    await exec(path.join(vendorPath, "pvk2pfx.exe"), ["-pvk", pvk, "-spc", cer, "-pfx", pfx])
    log.info({file: pfx}, `created. Please see https://electron.build/code-signing how to use it to sign.`)

    const certLocation = "Cert:\\LocalMachine\\TrustedPeople"
    log.info({file: pfx, certLocation}, `importing. Operation will be succeed only if runned from root. Otherwise import file manually.`)
    await spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "Import-PfxCertificate", "-FilePath", `"${pfx}"`, "-CertStoreLocation", ""])
  }
  finally {
    await tmpDir.cleanup()
  }
}