Skip to content

Commit

Permalink
first commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 5, 2018
0 parents commit 25f3a12
Show file tree
Hide file tree
Showing 6 changed files with 3,685 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
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
*.*~
~*.*
24 changes: 24 additions & 0 deletions README.md
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
})();
```
18 changes: 18 additions & 0 deletions index.js
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);
});
});
}
Loading

0 comments on commit 25f3a12

Please sign in to comment.