-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 25f3a12
Showing
6 changed files
with
3,685 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
node_modules | ||
data/WHD* | ||
data/* | ||
data/!.gitkeep | ||
doc | ||
.cache | ||
.DS_Store | ||
.rdoc-dist | ||
|
||
*.bak | ||
*.tem | ||
*.log | ||
*.temp | ||
#.swp | ||
*.*~ | ||
~*.* |
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,24 @@ | ||
whereis | ||
--- | ||
|
||
Like the unix `which` utility. | ||
|
||
Simply get the first path to a bin on any system. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @wcjiang/whereis --save | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
const whereis = require('@wcjiang/whereis'); | ||
|
||
(async () => { | ||
const where = await whereis('ls'); | ||
console.log('where:', where); | ||
// => /bin/ls | ||
})(); | ||
``` |
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,18 @@ | ||
const { exec } = require('child_process'); | ||
|
||
module.exports = function whereis(command, options) { | ||
return new Promise((resolve, reject) => { | ||
const commandStr = /(win32)/.test(process.platform) ? `for %i in (${command}.exe) do @echo. %~$PATH:i` : `which ${command}`; | ||
exec(commandStr, options, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(`Could not find ${command} on your system; ${error.message ? error.message : ''}`); | ||
return; | ||
} | ||
stdout = stdout.split('\n')[0]; | ||
if (stdout === '' || stdout.charAt(0) !== '/') { | ||
reject(new Error(`Could not find ${command} on your system;`)); | ||
} | ||
resolve(stdout, stderr); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.