UNPKG

@serpent/common-cli

Version:

通用的 cli 相关的函数

49 lines (41 loc) 1.16 kB
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-7d1333e8.mjs'; import { i as isWin$1 } from './supportColor-2e661db8.mjs'; import require$$1 from 'child_process'; /** * * 基于 npm 模块 command-exists 改写的 * * @module libs/tty/isCommandExists * @createdAt 2017-04-11 * * @copyright Copyright (c) 2017 Zhonglei Qiu * @license Licensed under the MIT license. * */ var isWin = isWin$1; var execSync = require$$1.execSync; var isCommandExists = function(command) { return isWin ? /* istanbul ignore next */ winCommandExistsSync(command) : unixCommandExistsSync(command) }; function unixCommandExistsSync(command) { try { var stdout = execSync('command -v ' + command + ' 2>/dev/null' + ' && { echo >&1 \'' + command + ' found\'; exit 0; }' ); return !!stdout } catch (e) { return false } } /* istanbul ignore next */ function winCommandExistsSync(command) { try { var stdout = execSync('where ' + command); return !!stdout } catch (e) { return false } } var isCmdExists = /*@__PURE__*/getDefaultExportFromCjs(isCommandExists); export { isCmdExists as i };