https://github.com/jchip/unwrap-npm-cmd
Unwrap npm's node.js bin CMD batch for js files on Windows.
https://github.com/jchip/unwrap-npm-cmd
batch cmd nodejs npm unwrap windows
Last synced: about 1 year ago
JSON representation
Unwrap npm's node.js bin CMD batch for js files on Windows.
- Host: GitHub
- URL: https://github.com/jchip/unwrap-npm-cmd
- Owner: jchip
- License: other
- Created: 2019-07-14T19:34:25.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-11T05:19:04.000Z (over 6 years ago)
- Last Synced: 2025-04-09T23:13:44.619Z (about 1 year ago)
- Topics: batch, cmd, nodejs, npm, unwrap, windows
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unwrap-npm-cmd
Unwrap npm's node.js bin CMD batch for js files on Windows.
[Sample](./test/fixtures/sample.js):
```js
const unwrapNpmCmd = require("unwrap-npm-cmd");
console.log(unwrapNpmCmd("npm test"));
console.log(unwrapNpmCmd("npx mocha", { relative: true }));
console.log(unwrapNpmCmd("mocha test", { jsOnly: true }));
console.log(unwrapNpmCmd(`find "name" package.json`));
console.log(unwrapNpmCmd("hello world", { path: __dirname }));
```
Output:
```cmd
"C:\Users\userid\nvm\nodejs\bin\node.exe" "C:\Users\userid\nvm\nodejs\bin\node_modules\npm\bin\npm-cli.js" test
"C:\Users\userid\nvm\nodejs\bin\node.exe" "..\nvm\nodejs\bin\node_modules\npm\bin\npx-cli.js" mocha
"C:\Users\userid\unwrap-npm-cmd\node_modules\mocha\bin\mocha" test
"C:\WINDOWS\system32\find.EXE" "name" package.json
"C:\Users\userid\unwrap-npm-cmd\test\fixtures\hello.CMD" world
```
## Usage
```js
child.spawnSync(unwrapNpmCmd("mocha test", { relative: true }));
```
Would effectivly be doing:
```js
child.spawnSync(
`"C:\\Users\\userid\\nvm\\nodejs\\bin\\node.exe" ".\\node_modules\\mocha\\bin\\_mocha" test`
);
```
## API
```js
unwrapNpmCmd(cmd, options);
```
`options`:
| name | description |
| ---------- | ---------------------------------------------------------- |
| `path` | Use instead of the `PATH` environment variable. |
| `jsOnly` | Return only the JS file as command without node exe. |
| `relative` | Convert JS file to relative path from CWD. |
| `cwd` | Use instead of `process.cwd()` to find relative path from. |
# License
Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)