• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript promise.executeFinally函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: assertPack

export async function assertPack(fixtureName: string, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions = {}): Promise<void> {
  if (checkOptions.signed) {
    packagerOptions = signed(packagerOptions)
  }
  if (checkOptions.signedWin) {
    packagerOptions.cscLink = WIN_CSC_LINK
    packagerOptions.cscKeyPassword = ""
  }
  else if (packagerOptions.cscLink == null) {
    packagerOptions = deepAssign({}, packagerOptions, {config: {mac: {identity: null}}})
  }

  const projectDirCreated = checkOptions.projectDirCreated
  let projectDir = path.join(__dirname, "..", "..", "fixtures", fixtureName)
  // const isDoNotUseTempDir = platform === "darwin"
  const customTmpDir = process.env.TEST_APP_TMP_DIR
  const tmpDir = new TmpDir()
  // non-macOS test uses the same dir as macOS test, but we cannot share node_modules (because tests executed in parallel)
  const dir = customTmpDir == null ? await tmpDir.createTempDir() : path.resolve(customTmpDir)
  if (customTmpDir != null) {
    await emptyDir(dir)
    log(`Custom temp dir used: ${customTmpDir}`)
  }

  await copyDir(projectDir, dir, it => {
    const basename = path.basename(it)
    return basename !== OUT_DIR_NAME && basename !== "node_modules" && !basename.startsWith(".")
  }, null, it => path.basename(it) !== "package.json")
  projectDir = dir

  await executeFinally((async () => {
    if (projectDirCreated != null) {
      await projectDirCreated(projectDir, tmpDir)
      if (checkOptions.installDepsBefore) {
        // bin links required (e.g. for node-pre-gyp - if package refers to it in the install script)
        await spawn(process.platform === "win32" ? "yarn.cmd" : "yarn", ["install", "--production", "--no-lockfile"], {
          cwd: projectDir,
        })
      }
    }

    const {packager, outDir} = await packAndCheck({projectDir, ...packagerOptions}, checkOptions)

    if (checkOptions.packed != null) {
      function base(platform: Platform, arch?: Arch): string {
        return path.join(outDir, `${platform.buildConfigurationKey}${getArchSuffix(arch == null ? Arch.x64 : arch)}${platform === Platform.MAC ? "" : "-unpacked"}`)
      }

      await checkOptions.packed({
        projectDir,
        outDir,
        getResources: (platform, arch) => path.join(base(platform, arch), "resources"),
        getContent: platform => base(platform),
        packager,
        tmpDir,
      })
    }
  })(), () => tmpDir.cleanup())
}
开发者ID:jwheare,项目名称:electron-builder,代码行数:59,代码来源:packTester.ts


示例2: build

export function build(options: PackagerOptions & PublishOptions, packager: Packager = new Packager(options)): Promise<Array<string>> {
  checkBuildRequestOptions(options)

  const publishManager = new PublishManager(packager, options)
  const sigIntHandler = () => {
    log.warn("cancelled by SIGINT")
    packager.cancellationToken.cancel()
    publishManager.cancelTasks()
  }
  process.once("SIGINT", sigIntHandler)

  const promise = packager.build()
    .then(async buildResult => {
      const afterAllArtifactBuild = resolveFunction(buildResult.configuration.afterAllArtifactBuild, "afterAllArtifactBuild")
      if (afterAllArtifactBuild != null) {
        const newArtifacts = asArray(await Promise.resolve(afterAllArtifactBuild(buildResult)))
        if (newArtifacts.length === 0 || !publishManager.isPublish) {
          return buildResult.artifactPaths
        }

        const publishConfigurations = await publishManager.getGlobalPublishConfigurations()
        if (publishConfigurations == null || publishConfigurations.length === 0) {
          return buildResult.artifactPaths
        }

        for (const newArtifact of newArtifacts) {
          buildResult.artifactPaths.push(newArtifact)
          for (const publishConfiguration of publishConfigurations) {
            publishManager.scheduleUpload(publishConfiguration, {
              file: newArtifact,
              arch: null
            }, packager.appInfo)
          }
        }
      }
      return buildResult.artifactPaths
    })

  return executeFinally(promise, isErrorOccurred => {
    let promise: Promise<any>
    if (isErrorOccurred) {
      publishManager.cancelTasks()
      promise = Promise.resolve(null)
    }
    else {
      promise = publishManager.awaitTasks()
    }

    return promise
      .then(() => process.removeListener("SIGINT", sigIntHandler))
  })
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:52,代码来源:index.ts


示例3: attachAndExecute

export async function attachAndExecute(dmgPath: string, readWrite: boolean, task: () => Promise<any>) {
  //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))
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:17,代码来源:dmgUtil.ts


示例4: build

export async function build(rawOptions?: CliOptions): Promise<Array<string>> {
  const options = normalizeOptions(rawOptions || {})

  if (options.cscLink === undefined && !isEmptyOrSpaces(process.env.CSC_LINK)) {
    options.cscLink = process.env.CSC_LINK
  }
  if (options.cscInstallerLink === undefined && !isEmptyOrSpaces(process.env.CSC_INSTALLER_LINK)) {
    options.cscInstallerLink = process.env.CSC_INSTALLER_LINK
  }
  if (options.cscKeyPassword === undefined && !isEmptyOrSpaces(process.env.CSC_KEY_PASSWORD)) {
    options.cscKeyPassword = process.env.CSC_KEY_PASSWORD
  }
  if (options.cscInstallerKeyPassword === undefined && !isEmptyOrSpaces(process.env.CSC_INSTALLER_KEY_PASSWORD)) {
    options.cscInstallerKeyPassword = process.env.CSC_INSTALLER_KEY_PASSWORD
  }

  const cancellationToken = new CancellationToken()
  const packager = new Packager(options, cancellationToken)
  // because artifact event maybe dispatched several times for different publish providers
  const artifactPaths = new Set<string>()
  packager.artifactCreated(event => {
    if (event.file != null) {
      artifactPaths.add(event.file)
    }
  })

  const publishManager = new PublishManager(packager, options, cancellationToken)
  process.on("SIGINT", () => {
    warn("Cancelled by SIGINT")
    cancellationToken.cancel()
    publishManager.cancelTasks()
  })

  return await executeFinally(packager.build().then(() => Array.from(artifactPaths)), errorOccurred => {
    if (errorOccurred) {
      publishManager.cancelTasks()
      return BluebirdPromise.resolve(null)
    }
    else {
      return publishManager.awaitTasks()
    }
  })
}
开发者ID:jwheare,项目名称:electron-builder,代码行数:43,代码来源:builder.ts


示例5: _build

export async function _build(options: CliOptions, cancellationToken: CancellationToken = new CancellationToken()): Promise<Array<string>> {
  const packager = new Packager(options, cancellationToken)

  let electronDownloader: any = null
  packager.electronDownloader = options => {
    if (electronDownloader ==  null) {
      electronDownloader = BluebirdPromise.promisify(require("electron-download-tf"))
    }
    return electronDownloader(options)
  }

  // because artifact event maybe dispatched several times for different publish providers
  const artifactPaths = new Set<string>()
  packager.artifactCreated(event => {
    if (event.file != null) {
      artifactPaths.add(event.file)
    }
  })

  const publishManager = new PublishManager(packager, options)
  const sigIntHandler = () => {
    log.warn("cancelled by SIGINT")
    cancellationToken.cancel()
    publishManager.cancelTasks()
  }
  process.once("SIGINT", sigIntHandler)

  return await executeFinally(packager.build().then(() => Array.from(artifactPaths)), errorOccurred => {
    let promise: Promise<any>
    if (errorOccurred) {
      publishManager.cancelTasks()
      promise = BluebirdPromise.resolve(null)
    }
    else {
      promise = publishManager.awaitTasks()
    }

    return promise
      .then(() => process.removeListener("SIGINT", sigIntHandler))
  })
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:41,代码来源:builder.ts


示例6: assertPack

export async function assertPack(fixtureName: string, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions = {}): Promise<void> {
  let configuration = packagerOptions.config as Configuration
  if (configuration == null) {
    configuration = {};
    (packagerOptions as any).config = configuration
  }

  if (checkOptions.signed) {
    packagerOptions = signed(packagerOptions)
  }
  if (checkOptions.signedWin) {
    configuration.cscLink = WIN_CSC_LINK
    configuration.cscKeyPassword = ""
  }
  else if (configuration == null || (configuration as Configuration).cscLink == null) {
    packagerOptions = deepAssign({}, packagerOptions, {config: {mac: {identity: null}}})
  }

  const projectDirCreated = checkOptions.projectDirCreated
  let projectDir = path.join(__dirname, "..", "..", "fixtures", fixtureName)
  // const isDoNotUseTempDir = platform === "darwin"
  const customTmpDir = process.env.TEST_APP_TMP_DIR
  const tmpDir = checkOptions.tmpDir || new TmpDir(`pack-tester: ${fixtureName}`)
  // non-macOS test uses the same dir as macOS test, but we cannot share node_modules (because tests executed in parallel)
  const dir = customTmpDir == null ? await tmpDir.createTempDir({prefix: "test-project"}) : path.resolve(customTmpDir)
  if (customTmpDir != null) {
    await emptyDir(dir)
    log.info({customTmpDir}, "custom temp dir used")
  }

  await copyDir(projectDir, dir, {
    filter: it => {
      const basename = path.basename(it)
      // if custom project dir specified, copy node_modules (i.e. do not ignore it)
      return (packagerOptions.projectDir != null || basename !== "node_modules") && (!basename.startsWith(".") || basename === ".babelrc")
    },
    isUseHardLink: USE_HARD_LINKS,
  })
  projectDir = dir

  await executeFinally((async () => {
    if (projectDirCreated != null) {
      await projectDirCreated(projectDir, tmpDir)
    }

    if (checkOptions.isInstallDepsBefore) {
      // bin links required (e.g. for node-pre-gyp - if package refers to it in the install script)
      await spawn(process.platform === "win32" ? "yarn.cmd" : "yarn", ["install", "--production", "--no-lockfile"], {
        cwd: projectDir,
      })
    }

    if (packagerOptions.projectDir != null) {
      packagerOptions.projectDir = path.resolve(projectDir, packagerOptions.projectDir)
    }

    const {packager, outDir} = await packAndCheck({
      projectDir,
      ...packagerOptions
    }, checkOptions)

    if (checkOptions.packed != null) {
      function base(platform: Platform, arch?: Arch): string {
        return path.join(outDir, `${platform.buildConfigurationKey}${getArchSuffix(arch == null ? Arch.x64 : arch)}${platform === Platform.MAC ? "" : "-unpacked"}`)
      }

      await checkOptions.packed({
        projectDir,
        outDir,
        getResources: (platform, arch) => path.join(base(platform, arch), "resources"),
        getContent: platform => base(platform),
        packager,
        tmpDir,
      })
    }
  })(), (): any => tmpDir === checkOptions.tmpDir ? null : tmpDir.cleanup())
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:77,代码来源:packTester.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript promise.orNullIfFileNotExist函数代码示例发布时间:2022-05-25
下一篇:
TypeScript nodeHttpExecutor.httpExecutor类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap