本文整理匯總了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.'`
)
)
}
})
})
示例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.'`
)
)
}
})
})