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


TypeScript GitProcess.spawn方法代码示例

本文整理汇总了TypeScript中dugite.GitProcess.spawn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GitProcess.spawn方法的具体用法?TypeScript GitProcess.spawn怎么用?TypeScript GitProcess.spawn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dugite.GitProcess的用法示例。


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

示例1: Error

      new Promise<ProcessOutput>((resolve, reject) => {
        const process = GitProcess.spawn(args, path)
        let totalStdoutLength = 0
        let killSignalSent = false

        const stdoutChunks = new Array<Buffer>()
        process.stdout.on('data', (chunk: Buffer) => {
          if (!stdOutMaxLength || totalStdoutLength < stdOutMaxLength) {
            stdoutChunks.push(chunk)
            totalStdoutLength += chunk.length
          }

          if (
            stdOutMaxLength &&
            totalStdoutLength >= stdOutMaxLength &&
            !killSignalSent
          ) {
            process.kill()
            killSignalSent = true
          }
        })

        const stderrChunks = new Array<Buffer>()
        process.stderr.on('data', (chunk: Buffer) => {
          stderrChunks.push(chunk)
        })

        process.on('error', err => {
          // for unhandled errors raised by the process, let's surface this in the
          // promise and make the caller handle it
          reject(err)
        })

        process.on('close', (code, signal) => {
          const stdout = Buffer.concat(
            stdoutChunks,
            stdOutMaxLength
              ? Math.min(stdOutMaxLength, totalStdoutLength)
              : totalStdoutLength
          )

          const stderr = Buffer.concat(stderrChunks)

          // mimic the experience of GitProcess.exec for handling known codes when
          // the process terminates
          const exitCodes = successExitCodes || new Set([0])

          if (exitCodes.has(code) || signal) {
            resolve({
              output: stdout,
              error: stderr,
            })
            return
          } else {
            reject(
              new Error(
                `Git returned an unexpected exit code '${code}' which should be handled by the caller.'`
              )
            )
          }
        })
      })
开发者ID:Ahskys,项目名称:desktop,代码行数:62,代码来源:spawn.ts

示例2: reportTimings

  return new Promise<ProcessOutput>((resolve, reject) => {
    const commandName = `${name}: git ${args.join(' ')}`
    log.debug(`Executing ${commandName}`)

    const startTime = performance && performance.now ? performance.now() : null

    const process = GitProcess.spawn(args, path)

    const stdout = new Array<Buffer>()
    let output: Buffer | undefined
    process.stdout.on('data', chunk => {
      stdout.push(chunk as Buffer)
    })

    const stderr = new Array<Buffer>()
    let error: Buffer | undefined
    process.stderr.on('data', chunk => {
      stderr.push(chunk as Buffer)
    })

    function reportTimings() {
      if (startTime) {
        const rawTime = performance.now() - startTime
        if (rawTime > 1000) {
          const timeInSeconds = (rawTime / 1000).toFixed(3)
          log.info(`Executing ${commandName} (took ${timeInSeconds}s)`)
        }
      }
    }

    process.stdout.once('close', () => {
      // process.on('exit') may fire before stdout has closed, so this is a
      // more accurate point in time to measure that the command has completed
      // as we cannot proceed without the contents of the stdout stream
      reportTimings()

      output = Buffer.concat(stdout)
      if (output && error) {
        resolve({ output, error })
      }
    })

    process.stderr.once('close', () => {
      error = Buffer.concat(stderr)

      if (output && error) {
        resolve({ output, error })
      }
    })

    process.on('error', err => {
      // for unhandled errors raised by the process, let's surface this in the
      // promise and make the caller handle it
      reject(err)
    })

    process.on('exit', (code, signal) => {
      // mimic the experience of GitProcess.exec for handling known codes when
      // the process terminates
      const exitCodes = successExitCodes || new Set([0])
      if (!exitCodes.has(code)) {
        reject(
          new Error(
            `Git returned an unexpected exit code '${code}' which should be handled by the caller.'`
          )
        )
      }
    })
  })
开发者ID:Aj-ajaam,项目名称:desktop,代码行数:69,代码来源:spawn.ts


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