-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create script to run a command iff it's available on the PATH
... and use it to run actionlint and ShellCheck.
- Loading branch information
1 parent
4f03fd8
commit abaae3d
Showing
4 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @overview Run a tool if it's present on the PATH, otherwise output a warning. | ||
* @license MIT-0 | ||
*/ | ||
|
||
import process from "node:process"; | ||
|
||
import which from "which"; | ||
|
||
import { common } from "./_.js"; | ||
|
||
if (common.argv.length === 0) { | ||
console.error("Provide a command to try and execute."); | ||
process.exit(1); | ||
} | ||
|
||
const cmd = common.argv[0]; | ||
const args = common.argv.slice(1); | ||
|
||
try { | ||
which.sync(cmd); | ||
} catch (_) { | ||
console.warn( | ||
`Command '${cmd}' not found, it will not be run.`, | ||
"Install it to make this warning go away.", | ||
); | ||
process.exit(0); | ||
} | ||
|
||
const { status } = common.spawnSync(cmd, args); | ||
process.exit(status); |