@serpent/common-cli
Version:
通用的 cli 相关的函数
51 lines (42 loc) • 1.2 kB
JavaScript
;
var _commonjsHelpers = require('./_commonjsHelpers-ed042b00.cjs');
var supportColor = require('./supportColor-07ee281e.cjs');
var require$$1 = require('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 = supportColor.isWin;
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__*/_commonjsHelpers.getDefaultExportFromCjs(isCommandExists);
exports.isCmdExists = isCmdExists;