Skip to content

Commit 837240d

Browse files
committed
added command-exists package
1 parent 90efcaa commit 837240d

File tree

3 files changed

+183
-11
lines changed

3 files changed

+183
-11
lines changed

dist/index.js

Lines changed: 174 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,179 @@ function copyFile(srcFile, destFile, force) {
15501550
}
15511551
//# sourceMappingURL=io.js.map
15521552

1553+
/***/ }),
1554+
1555+
/***/ 569:
1556+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1557+
1558+
module.exports = __webpack_require__(325);
1559+
1560+
1561+
/***/ }),
1562+
1563+
/***/ 325:
1564+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1565+
1566+
"use strict";
1567+
1568+
1569+
var exec = __webpack_require__(129).exec;
1570+
var execSync = __webpack_require__(129).execSync;
1571+
var fs = __webpack_require__(747);
1572+
var path = __webpack_require__(622);
1573+
var access = fs.access;
1574+
var accessSync = fs.accessSync;
1575+
var constants = fs.constants || fs;
1576+
1577+
var isUsingWindows = process.platform == 'win32'
1578+
1579+
var fileNotExists = function(commandName, callback){
1580+
access(commandName, constants.F_OK,
1581+
function(err){
1582+
callback(!err);
1583+
});
1584+
};
1585+
1586+
var fileNotExistsSync = function(commandName){
1587+
try{
1588+
accessSync(commandName, constants.F_OK);
1589+
return false;
1590+
}catch(e){
1591+
return true;
1592+
}
1593+
};
1594+
1595+
var localExecutable = function(commandName, callback){
1596+
access(commandName, constants.F_OK | constants.X_OK,
1597+
function(err){
1598+
callback(null, !err);
1599+
});
1600+
};
1601+
1602+
var localExecutableSync = function(commandName){
1603+
try{
1604+
accessSync(commandName, constants.F_OK | constants.X_OK);
1605+
return true;
1606+
}catch(e){
1607+
return false;
1608+
}
1609+
}
1610+
1611+
var commandExistsUnix = function(commandName, cleanedCommandName, callback) {
1612+
1613+
fileNotExists(commandName, function(isFile){
1614+
1615+
if(!isFile){
1616+
var child = exec('command -v ' + cleanedCommandName +
1617+
' 2>/dev/null' +
1618+
' && { echo >&1 ' + cleanedCommandName + '; exit 0; }',
1619+
function (error, stdout, stderr) {
1620+
callback(null, !!stdout);
1621+
});
1622+
return;
1623+
}
1624+
1625+
localExecutable(commandName, callback);
1626+
});
1627+
1628+
}
1629+
1630+
var commandExistsWindows = function(commandName, cleanedCommandName, callback) {
1631+
// Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator
1632+
if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) {
1633+
callback(null, false);
1634+
return;
1635+
}
1636+
var child = exec('where ' + cleanedCommandName,
1637+
function (error) {
1638+
if (error !== null){
1639+
callback(null, false);
1640+
} else {
1641+
callback(null, true);
1642+
}
1643+
}
1644+
)
1645+
}
1646+
1647+
var commandExistsUnixSync = function(commandName, cleanedCommandName) {
1648+
if(fileNotExistsSync(commandName)){
1649+
try {
1650+
var stdout = execSync('command -v ' + cleanedCommandName +
1651+
' 2>/dev/null' +
1652+
' && { echo >&1 ' + cleanedCommandName + '; exit 0; }'
1653+
);
1654+
return !!stdout;
1655+
} catch (error) {
1656+
return false;
1657+
}
1658+
}
1659+
return localExecutableSync(commandName);
1660+
}
1661+
1662+
var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) {
1663+
// Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator
1664+
if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) {
1665+
return false;
1666+
}
1667+
try {
1668+
var stdout = execSync('where ' + cleanedCommandName, {stdio: []});
1669+
return !!stdout;
1670+
} catch (error) {
1671+
return false;
1672+
}
1673+
}
1674+
1675+
var cleanInput = function(s) {
1676+
if (/[^A-Za-z0-9_\/:=-]/.test(s)) {
1677+
s = "'"+s.replace(/'/g,"'\\''")+"'";
1678+
s = s.replace(/^(?:'')+/g, '') // unduplicate single-quote at the beginning
1679+
.replace(/\\'''/g, "\\'" ); // remove non-escaped single-quote if there are enclosed between 2 escaped
1680+
}
1681+
return s;
1682+
}
1683+
1684+
if (isUsingWindows) {
1685+
cleanInput = function(s) {
1686+
var isPathName = /[\\]/.test(s);
1687+
if (isPathName) {
1688+
var dirname = '"' + path.dirname(s) + '"';
1689+
var basename = '"' + path.basename(s) + '"';
1690+
return dirname + ':' + basename;
1691+
}
1692+
return '"' + s + '"';
1693+
}
1694+
}
1695+
1696+
module.exports = function commandExists(commandName, callback) {
1697+
var cleanedCommandName = cleanInput(commandName);
1698+
if (!callback && typeof Promise !== 'undefined') {
1699+
return new Promise(function(resolve, reject){
1700+
commandExists(commandName, function(error, output) {
1701+
if (output) {
1702+
resolve(commandName);
1703+
} else {
1704+
reject(error);
1705+
}
1706+
});
1707+
});
1708+
}
1709+
if (isUsingWindows) {
1710+
commandExistsWindows(commandName, cleanedCommandName, callback);
1711+
} else {
1712+
commandExistsUnix(commandName, cleanedCommandName, callback);
1713+
}
1714+
};
1715+
1716+
module.exports.sync = function(commandName) {
1717+
var cleanedCommandName = cleanInput(commandName);
1718+
if (isUsingWindows) {
1719+
return commandExistsWindowsSync(commandName, cleanedCommandName);
1720+
} else {
1721+
return commandExistsUnixSync(commandName, cleanedCommandName);
1722+
}
1723+
};
1724+
1725+
15531726
/***/ }),
15541727

15551728
/***/ 399:
@@ -1579,7 +1752,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
15791752
Object.defineProperty(exports, "__esModule", ({ value: true }));
15801753
const core = __importStar(__webpack_require__(186));
15811754
const exec = __importStar(__webpack_require__(514));
1582-
const { sync: commandExistsSync } = __webpack_require__(238);
1755+
const { sync: commandExistsSync } = __webpack_require__(569);
15831756
const errorDeploying = "⚠️ Error deploying";
15841757
async function run() {
15851758
try {
@@ -1655,14 +1828,6 @@ async function installCommand(command) {
16551828
;
16561829

16571830

1658-
/***/ }),
1659-
1660-
/***/ 238:
1661-
/***/ ((module) => {
1662-
1663-
module.exports = eval("require")("command-exists");
1664-
1665-
16661831
/***/ }),
16671832

16681833
/***/ 357:

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"description": "web deploy",
66
"main": "dist/index.js",
77
"scripts": {
8-
"build": "ncc build src/main.ts --no-cache"
8+
"build": "ncc build src/main.ts --no-cache",
9+
"deploy": "npm run build && node ./dist/index.js --target-server samkirkland.com --remote-user \"sshUser\" --remote-key \"sshPassword\" --source-path ./ --destination-path rsync-target/"
910
},
1011
"repository": {
1112
"type": "git",
@@ -22,7 +23,8 @@
2223
"license": "MIT",
2324
"dependencies": {
2425
"@actions/core": "^1.2.6",
25-
"@actions/exec": "^1.0.4"
26+
"@actions/exec": "^1.0.4",
27+
"command-exists": "^1.2.9"
2628
},
2729
"devDependencies": {
2830
"@types/node": "12.12.8",

0 commit comments

Comments
 (0)