async function deleteOldElectronVersion(): Promise<any> {
  if (!process.env.CI) {
    return
  }

  const cacheDir = path.join(require("os").homedir(), ".electron")
  try {
    const deletePromises: Array<Promise<any>> = []
    for (let file of (await readdir(cacheDir))) {
      if (file.endsWith(".zip") && !file.includes(electronVersion)) {
        console.log("Remove old electron " + file)
        deletePromises.push(unlink(path.join(cacheDir, file)))
      }
    }
    return BluebirdPromise.all(deletePromises)
  }
  catch (e) {
    if (e.code === "ENOENT") {
      return []
    }
    else {
      throw e
    }
  }
}
async function deleteOldElectronVersion(): Promise<any> {
  if (!isCi) {
    return
  }

  const cacheDir = require("env-paths")("electron", {suffix: ""}).cache
  try {
    const deletePromises: Array<Promise<any>> = []
    for (const file of (await readdir(cacheDir))) {
      if (file.endsWith(".zip") && !file.includes(ELECTRON_VERSION)) {
        console.log(`Remove old electron ${file}`)
        deletePromises.push(unlink(path.join(cacheDir, file)))
      }
    }
    return await BluebirdPromise.all(deletePromises)
  }
  catch (e) {
    if (e.code === "ENOENT") {
      return []
    }
    else {
      throw e
    }
  }
}
 return BluebirdPromise.map(readdir(cacheDir), (file): any => {
   if (file.endsWith(".zip") && !file.includes(ELECTRON_VERSION)) {
     console.log(`Remove old electron ${file}`)
     return unlink(path.join(cacheDir, file))
   }
   return null
 })
export async function modifyPackageJson(projectDir: string, task: (data: any) => void, isApp = false): Promise<any> {
  const file = isApp ? path.join(projectDir, "app", "package.json") : path.join(projectDir, "package.json")
  const data = await readJson(file)
  task(data)
  // because copied as hard link
  await unlink(file)
  return await writeJson(file, data)
}
Exemple #5
0
 .then(it => {
   const deletePromises: Array<Promise<any>> = []
   for (let file of it) {
     if (file.endsWith(".zip") && !file.includes(electronVersion)) {
       console.log("Remove old electron " + file)
       deletePromises.push(fs.unlink(path.join(cacheDir, file)))
     }
   }
   return BluebirdPromise.all(deletePromises)
 })
async function msi(options: SquirrelOptions, nupkgPath: string, setupPath: string, outputDirectory: string, outFile: string) {
  const args = [
    "--createMsi", nupkgPath,
    "--bootstrapperExe", setupPath
  ]
  await exec(process.platform === "win32" ? path.join(options.vendorPath, "Update.com") : "mono", prepareArgs(args, path.join(options.vendorPath, "Update-Mono.exe")))
  //noinspection SpellCheckingInspection
  await exec(path.join(options.vendorPath, "candle.exe"), ["-nologo", "-ext", "WixNetFxExtension", "-out", "Setup.wixobj", "Setup.wxs"], {
    cwd: outputDirectory,
  })
  //noinspection SpellCheckingInspection
  await exec(path.join(options.vendorPath, "light.exe"), ["-ext", "WixNetFxExtension", "-sval", "-out", outFile, "Setup.wixobj"], {
    cwd: outputDirectory,
  })

  //noinspection SpellCheckingInspection
  await BluebirdPromise.all([
    unlink(path.join(outputDirectory, "Setup.wxs")),
    unlink(path.join(outputDirectory, "Setup.wixobj")),
    unlink(path.join(outputDirectory, outFile.replace(".msi", ".wixpdb"))).catch(e => debug(e.toString())),
  ])
}
    projectDirCreated: async projectDir => {
      const resourceDir = path.join(projectDir, "build")
      await copyFile(path.join(getDmgTemplatePath(), "background.tiff"), path.join(resourceDir, "background.tiff"))

      async function extractPng(index: number, suffix: string) {
        await exec("tiffutil", ["-extract", index.toString(), path.join(getDmgTemplatePath(), "background.tiff")], {
          cwd: projectDir
        })
        await exec("sips", ["-s", "format", "png", "out.tiff", "--out", `background${suffix}.png`], {
          cwd: projectDir
        })
      }

      await extractPng(0, "")
      await extractPng(1, "@2x")
      await unlink(path.join(resourceDir, "background.tiff"))
    },
      task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {
        const packageInfo = fileInfo.packageInfo
        const isWebInstaller = packageInfo != null && packageFile != null
        if (isWebInstaller || await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider)) {
          await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)
        }

        const signatureVerificationStatus = await this.verifySignature(destinationFile)
        if (signatureVerificationStatus != null) {
          await removeTempDirIfAny()
          // noinspection ThrowInsideFinallyBlockJS
          throw newError(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, "ERR_UPDATER_INVALID_SIGNATURE")
        }

        if (isWebInstaller) {
          if (await this.differentialDownloadWebPackage(packageInfo!!, packageFile!!, provider)) {
            try {
              await this.httpExecutor.download(new URL(packageInfo!!.path), packageFile!!, {
                headers: downloadUpdateOptions.requestHeaders,
                cancellationToken: downloadUpdateOptions.cancellationToken,
                sha512: packageInfo!!.sha512,
              })
            }
            catch (e) {
              try {
                await unlink(packageFile!!)
              }
              catch (ignored) {
                // ignore
              }

              throw e
            }
          }
        }
      },
 projectDirCreated: projectDir => Promise.all([
   unlink(path.join(projectDir, "build", "icon.ico")),
   remove(path.join(projectDir, "build", "icons")),
 ]),
 projectDirCreated: async projectDir => {
   const file = path.join(projectDir, "build", "icon.ico")
   // because we use hardlinks
   await unlink(file)
   await writeFile(file, "foo")
 }