tauri/tooling/cli/node/test/jest/helpers/spawn.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
feat(license): SPDX Headers (#1449) * chore(licenses): api Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(licenses): scripts Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/core Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/tauri-bundler Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): workflows Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): require license_template in rust Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-api Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-build Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-codegen Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-macros Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-updater Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): core/tauri-utils Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): examples Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): cli/tauri.js Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): changefile Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): place both licenses in root Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): package.json SPDX Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): SPDX everywhere Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * fix(tauri.js): tests more time for ubuntu Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): commons conservancy language Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): add spdx file Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * fix(license): clippy Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com> * chore(license): language Signed-off-by: Daniel Thompson-Yvetot <denjell@mailscript.com>
2021-04-11 01:09:09 +03:00
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
const crossSpawn = require('cross-spawn')
const logger = require('./logger')
const log = logger('app:spawn')
const warn = logger('app:spawn')
/*
Returns pid, takes onClose
*/
module.exports.spawn = (
cmd,
params,
cwd,
onClose
) => {
log(`Running "${cmd} ${params.join(' ')}"`)
log()
// TODO: move to execa?
const runner = crossSpawn(cmd, params, {
stdio: 'inherit',
2020-03-07 19:40:24 +03:00
cwd,
env: process.env
})
runner.on('close', (code) => {
log()
if (code) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
log(`Command "${cmd}" failed with exit code: ${code}`)
}
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
onClose && onClose(code || 0, runner.pid || 0)
})
return runner.pid || 0
}
/*
Returns nothing, takes onFail
*/
module.exports.spawnSync = (
cmd,
params,
cwd,
onFail
) => {
log(`[sync] Running "${cmd} ${params.join(' ')}"`)
log()
const runner = crossSpawn.sync(cmd, params, {
stdio: 'inherit',
cwd
})
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (runner.status || runner.error) {
warn()
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
warn(`⚠️ Command "${cmd}" failed with exit code: ${runner.status}`)
if (runner.status === null) {
warn(`⚠️ Please globally install "${cmd}"`)
}
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
onFail && onFail()
process.exit(1)
}
}