当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript builder-util-runtime.newError函数代码示例

本文整理汇总了TypeScript中builder-util-runtime.newError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript newError函数的具体用法?TypeScript newError怎么用?TypeScript newError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了newError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getLatestVersion

  async getLatestVersion(): Promise<PrivateGitHubUpdateInfo> {
    const basePath = this.basePath
    const cancellationToken = new CancellationToken()
    const channelFile = getChannelFilename(getDefaultChannelName())

    const releaseInfo = await this.getLatestVersionInfo(basePath, cancellationToken)
    const asset = releaseInfo.assets.find(it => it.name === channelFile)
    if (asset == null) {
      // html_url must be always, but just to be sure
      throw newError(`Cannot find ${channelFile} in the release ${releaseInfo.html_url || releaseInfo.name}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
    }

    const url = new URL(asset.url)
    let result: any
    try {
      result = safeLoad((await this.httpRequest(url, this.configureHeaders("application/octet-stream"), cancellationToken))!!)
    }
    catch (e) {
      if (e instanceof HttpError && e.statusCode === 404) {
        throw newError(`Cannot find ${channelFile} in the latest release artifacts (${url}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
      }
      throw e
    }

    (result as PrivateGitHubUpdateInfo).assets = releaseInfo.assets
    return result
  }
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:27,代码来源:PrivateGitHubProvider.ts

示例2: getLatestVersion

  async getLatestVersion(): Promise<UpdateInfo> {
    const cancellationToken = new CancellationToken()

    const feedXml: string = (await this.httpRequest(newUrlFromBase(`${this.basePath}.atom`, this.baseUrl), {
      accept: "application/xml, application/atom+xml, text/xml, */*",
    }, cancellationToken))!

    const feed = parseXml(feedXml)
    let latestRelease = feed.element("entry", false, `No published versions on GitHub`)
    let version: string | null
    try {
      if (this.updater.allowPrerelease) {
        // noinspection TypeScriptValidateJSTypes
        version = latestRelease.element("link").attribute("href").match(hrefRegExp)!![1]
      }
      else {
        version = await this.getLatestVersionString(cancellationToken)
        for (const element of feed.getElements("entry")) {
          if (element.element("link").attribute("href").match(hrefRegExp)!![1] === version) {
            latestRelease = element
            break
          }
        }

      }
    }
    catch (e) {
      throw newError(`Cannot parse releases feed: ${e.stack || e.message},\nXML:\n${feedXml}`, "ERR_UPDATER_INVALID_RELEASE_FEED")
    }

    if (version == null) {
      throw newError(`No published versions on GitHub`, "ERR_UPDATER_NO_PUBLISHED_VERSIONS")
    }

    const channelFile = getChannelFilename(this.getDefaultChannelName())
    const channelFileUrl = newUrlFromBase(this.getBaseDownloadPath(version, channelFile), this.baseUrl)
    const requestOptions = this.createRequestOptions(channelFileUrl)
    let rawData: string
    try {
      rawData = (await this.executor.request(requestOptions, cancellationToken))!!
    }
    catch (e) {
      if (!this.updater.allowPrerelease && e instanceof HttpError && e.statusCode === 404) {
        throw newError(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
      }
      throw e
    }

    const result = parseUpdateInfo(rawData, channelFile, channelFileUrl)
    if (result.releaseName == null) {
      result.releaseName = latestRelease.elementValueOrEmpty("title")
    }

    if (result.releaseNotes == null) {
      result.releaseNotes = computeReleaseNotes(this.updater.currentVersion, this.updater.fullChangelog, feed, latestRelease)
    }
    return result
  }
开发者ID:electron-userland,项目名称:electron-builder,代码行数:58,代码来源:GitHubProvider.ts

示例3: async

    await this.executeDownload(downloadOptions, fileInfo, async (tempDir, destinationFile) => {
      installerPath = destinationFile

      const oldFile = process.env.APPIMAGE!!
      if (oldFile == null) {
        throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND")
      }

      let isDownloadFull = false
      try {
        await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, {
          newUrl: fileInfo.url.href,
          oldFile,
          logger: this._logger,
          newFile: installerPath,
          useMultipleRangeRequest: provider.useMultipleRangeRequest,
          requestHeaders,
        })
          .download()
      }
      catch (e) {
        this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)
        // during test (developer machine mac) we must throw error
        isDownloadFull = process.platform === "linux"
      }

      if (isDownloadFull) {
        await this.httpExecutor.download(fileInfo.url.href, installerPath, downloadOptions)
      }

      await chmod(installerPath, 0o755)
    })
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:32,代码来源:AppImageUpdater.ts

示例4: async

    await this.executeDownload(downloadOptions, fileInfo, async (tempDir, destinationFile, removeTempDirIfAny) => {
      installerPath = destinationFile
      if (await this.differentialDownloadInstaller(fileInfo, "OLD", installerPath, requestHeaders, provider)) {
        await this.httpExecutor.download(fileInfo.url.href, installerPath, downloadOptions)
      }

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

      const packageInfo = fileInfo.packageInfo
      if (packageInfo != null) {
        packagePath = path.join(tempDir, `package-${updateInfo.version}${path.extname(packageInfo.path) || ".7z"}`)
        if (await this.differentialDownloadWebPackage(packageInfo, packagePath, provider)) {
          await this.httpExecutor.download(packageInfo.path, packagePath!!, {
            skipDirCreation: true,
            headers: requestHeaders,
            cancellationToken,
            sha512: packageInfo.sha512,
          })
        }
      }
    })
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:26,代码来源:NsisUpdater.ts

示例5: async

      task: async (updateFile, downloadOptions) => {
        const oldFile = process.env.APPIMAGE!!
        if (oldFile == null) {
          throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND")
        }

        let isDownloadFull = false
        try {
          await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, {
            newUrl: fileInfo.url,
            oldFile,
            logger: this._logger,
            newFile: updateFile,
            isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
            requestHeaders: downloadUpdateOptions.requestHeaders,
          })
            .download()
        }
        catch (e) {
          this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)
          // during test (developer machine mac) we must throw error
          isDownloadFull = process.platform === "linux"
        }

        if (isDownloadFull) {
          await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions)
        }

        await chmod(updateFile, 0o755)
      },
开发者ID:electron-userland,项目名称:electron-builder,代码行数:30,代码来源:AppImageUpdater.ts

示例6: getLatestVersionInfo

 private async getLatestVersionInfo(basePath: string, cancellationToken: CancellationToken): Promise<ReleaseInfo> {
   const url = newUrlFromBase(`${basePath}/latest`, this.baseUrl)
   try {
     return (JSON.parse((await this.httpRequest(url, this.configureHeaders("application/vnd.github.v3+json"), cancellationToken))!!))
   }
   catch (e) {
     throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
   }
 }
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:9,代码来源:PrivateGitHubProvider.ts

示例7: createClient

export function createClient(data: PublishConfiguration | AllPublishOptions, updater: AppUpdater, runtimeOptions: ProviderRuntimeOptions) {
  // noinspection SuspiciousTypeOfGuard
  if (typeof data === "string") {
    throw newError("Please pass PublishConfiguration object", "ERR_UPDATER_INVALID_PROVIDER_CONFIGURATION")
  }

  const provider = data.provider
  switch (provider) {
    case "github":
      const githubOptions = data as GithubOptions
      const token = (githubOptions.private ? process.env.GH_TOKEN || process.env.GITHUB_TOKEN : null) || githubOptions.token
      if (token == null) {
        return new GitHubProvider(githubOptions, updater, runtimeOptions)
      }
      else {
        return new PrivateGitHubProvider(githubOptions, updater, token, runtimeOptions)
      }

    case "s3":
    case "spaces":
      return new GenericProvider({
        provider: "generic",
        url: getS3LikeProviderBaseUrl(data),
        channel: (data as BaseS3Options).channel || null
      }, updater, {
        ...runtimeOptions,
        // https://github.com/minio/minio/issues/5285#issuecomment-350428955
        isUseMultipleRangeRequest: provider === "spaces",
      })

    case "generic":
      const options = data as GenericServerOptions
      return new GenericProvider(options, updater, {
        ...runtimeOptions,
        isUseMultipleRangeRequest: options.useMultipleRangeRequest !== false && isUrlProbablySupportMultiRangeRequests(options.url),
      })

    case "bintray":
      return new BintrayProvider(data as BintrayOptions, runtimeOptions)

    default:
      throw newError(`Unsupported provider: ${provider}`, "ERR_UPDATER_UNSUPPORTED_PROVIDER")
  }
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:44,代码来源:providerFactory.ts

示例8: getLatestVersion

  async getLatestVersion(): Promise<UpdateInfo> {
    try {
      const data = await this.client.getVersion("_latest")
      const channelFilename = getChannelFilename(this.getDefaultChannelName())
      const files = await this.client.getVersionFiles(data.name)
      const channelFile = files.find(it => it.name.endsWith(`_${channelFilename}`) || it.name.endsWith(`-${channelFilename}`))
      if (channelFile == null) {
        // noinspection ExceptionCaughtLocallyJS
        throw newError(`Cannot find channel file "${channelFilename}", existing files:\n${files.map(it => JSON.stringify(it, null, 2)).join(",\n")}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND")
      }

      const channelFileUrl = new URL(`https://dl.bintray.com/${this.client.owner}/${this.client.repo}/${channelFile.name}`)
      return parseUpdateInfo(await this.httpRequest(channelFileUrl), channelFilename, channelFileUrl)
    }
    catch (e) {
      if ("statusCode" in e && e.statusCode === 404) {
        throw newError(`No latest version, please ensure that user, package and repository correctly configured. Or at least one version is published. ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
      }
      throw e
    }
  }
开发者ID:electron-userland,项目名称:electron-builder,代码行数:21,代码来源:BintrayProvider.ts

示例9: getFileList

    return getFileList(updateInfo).map(it => {
      const name = path.posix.basename(it.url).replace(/ /g, "-")
      const asset = updateInfo.assets.find(it => it != null && it.name === name)
      if (asset == null) {
        throw newError(`Cannot find asset "${name}" in: ${JSON.stringify(updateInfo.assets, null, 2)}`, "ERR_UPDATER_ASSET_NOT_FOUND")
      }

      return {
        url: new URL(asset.url),
        info: it,
      }
    })
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:12,代码来源:PrivateGitHubProvider.ts

示例10: createClient

export function createClient(data: PublishConfiguration | AllPublishOptions, updater: AppUpdater) {
  if (typeof data === "string") {
    throw newError("Please pass PublishConfiguration object", "ERR_UPDATER_INVALID_PROVIDER_CONFIGURATION")
  }

  const httpExecutor = updater.httpExecutor
  const provider = data.provider
  switch (provider) {
    case "github":
      const githubOptions = data as GithubOptions
      const token = (githubOptions.private ? process.env.GH_TOKEN : null) || githubOptions.token
      if (token == null) {
        return new GitHubProvider(githubOptions, updater, httpExecutor)
      }
      else {
        return new PrivateGitHubProvider(githubOptions, token, httpExecutor)
      }

    case "s3":
    case "spaces":
      return new GenericProvider({
        provider: "generic",
        url: getS3LikeProviderBaseUrl(data),
        channel: (data as BaseS3Options).channel || null
      }, updater, provider === "spaces" /* https://github.com/minio/minio/issues/5285#issuecomment-350428955 */)

    case "generic":
      return new GenericProvider(data as GenericServerOptions, updater, true)

    case "bintray":
      return new BintrayProvider(data as BintrayOptions, httpExecutor)

    default:
      throw newError(`Unsupported provider: ${provider}`, "ERR_UPDATER_UNSUPPORTED_PROVIDER")
  }
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:36,代码来源:providerFactory.ts

示例11: getLatestVersionString

  private async getLatestVersionString(basePath: string, cancellationToken: CancellationToken): Promise<string | null> {
    const url = newUrlFromBase(`${basePath}/latest`, this.baseUrl)
    try {
      // do not use API to avoid limit
      const rawData = await this.httpRequest(url, {Accept: "application/json"}, cancellationToken)
      if (rawData == null) {
        return null
      }

      const releaseInfo: GithubReleaseInfo = JSON.parse(rawData)
      return (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
    }
    catch (e) {
      throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
    }
  }
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:16,代码来源:GitHubProvider.ts

示例12: getLatestVersionString

  private async getLatestVersionString(cancellationToken: CancellationToken): Promise<string | null> {
    const options = this.options
    // do not use API for GitHub to avoid limit, only for custom host or GitHub Enterprise
    const url = (options.host == null || options.host === "github.com") ?
      newUrlFromBase(`${this.basePath}/latest`, this.baseUrl) :
      new URL(`${this.computeGithubBasePath(`/repos/${options.owner}/${options.repo}/releases`)}/latest`, this.baseApiUrl)
    try {
      const rawData = await this.httpRequest(url, {Accept: "application/json"}, cancellationToken)
      if (rawData == null) {
        return null
      }

      const releaseInfo: GithubReleaseInfo = JSON.parse(rawData)
      return (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
    }
    catch (e) {
      throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
    }
  }
开发者ID:electron-userland,项目名称:electron-builder,代码行数:19,代码来源:GitHubProvider.ts

示例13: doInstall

  protected doInstall(options: InstallOptions): boolean {
    const appImageFile = process.env.APPIMAGE!!
    if (appImageFile == null) {
      throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND")
    }

    // https://stackoverflow.com/a/1712051/1910191
    unlinkSync(appImageFile)

    let destination: string
    const existingBaseName = path.basename(appImageFile)
    // https://github.com/electron-userland/electron-builder/issues/2964
    // if no version in existing file name, it means that user wants to preserve current custom name
    if (path.basename(options.installerPath) === existingBaseName || !/\d+\.\d+\.\d+/.test(existingBaseName)) {
      // no version in the file name, overwrite existing
      destination = appImageFile
    }
    else {
      destination = path.join(path.dirname(appImageFile), path.basename(options.installerPath))
    }

    execFileSync("mv", ["-f", options.installerPath, destination])

    const env: any = {
      ...process.env,
      APPIMAGE_SILENT_INSTALL: "true",
    }

    if (options.isForceRunAfter) {
      spawn(destination, [], {
        detached: true,
        stdio: "ignore",
        env,
      })
        .unref()
    }
    else {
      env.APPIMAGE_EXIT_AFTER_INSTALL = "true"
      execFileSync(destination, [], {env})
    }
    return true
  }
开发者ID:electron-userland,项目名称:electron-builder,代码行数:42,代码来源:AppImageUpdater.ts

示例14: getLatestVersionInfo

  private async getLatestVersionInfo(cancellationToken: CancellationToken): Promise<ReleaseInfo> {
    let basePath = this.basePath
    const allowPrerelease = this.updater.allowPrerelease

    if (!allowPrerelease) {
      basePath = `${basePath}/latest`
    }

    const url = newUrlFromBase(basePath, this.baseUrl)
    try {
      let version = (JSON.parse((await this.httpRequest(url, this.configureHeaders("application/vnd.github.v3+json"), cancellationToken))!!))
      if (allowPrerelease) {
        version = version.find((v: any) => v.prerelease)
      }
      return version
    }
    catch (e) {
      throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND")
    }
  }
开发者ID:electron-userland,项目名称:electron-builder,代码行数:20,代码来源:PrivateGitHubProvider.ts

示例15: doInstall

  protected doInstall(installerPath: string, isSilent: boolean, isRunAfter: boolean): boolean {
    const appImageFile = process.env.APPIMAGE!!
    if (appImageFile == null) {
      throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND")
    }

    // https://stackoverflow.com/a/1712051/1910191
    unlinkSync(appImageFile)

    let destination: string
    if (path.basename(installerPath) === path.basename(appImageFile)) {
      // no version in the file name, overwrite existing
      destination = appImageFile
    }
    else {
      destination = path.join(path.dirname(appImageFile), path.basename(installerPath))
    }

    execFileSync("mv", ["-f", installerPath, destination])

    const env: any = {
      ...process.env,
      APPIMAGE_SILENT_INSTALL: "true",
    }

    if (isRunAfter) {
      spawn(destination, [], {
        detached: true,
        stdio: "ignore",
        env,
      })
        .unref()
    }
    else {
      env.APPIMAGE_EXIT_AFTER_INSTALL = "true"
      execFileSync(destination, [], {env})
    }
    return true
  }
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:39,代码来源:AppImageUpdater.ts


注:本文中的builder-util-runtime.newError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。