Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "zx", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "A tool for writing better scripts", | ||
@@ -11,3 +11,3 @@ "main": "index.mjs", | ||
"scripts": { | ||
"test": "zx test.mjs" | ||
"test": "node zx.mjs test.mjs" | ||
}, | ||
@@ -17,2 +17,3 @@ "dependencies": { | ||
"node-fetch": "^2.6.1", | ||
"shq": "^1.0.2", | ||
"uuid": "^8.3.2" | ||
@@ -19,0 +20,0 @@ }, |
@@ -17,10 +17,12 @@ # 🐚 zx | ||
await $`ssh medv.io uptime` | ||
let name = 'foo bar' | ||
await $`mkdir /tmp/${name}` | ||
``` | ||
Bash is great, but when it comes to writing scripts, | ||
people usually choose a more convenient programming languages. | ||
JavaScript is a perfect choose, but standard Node.js library | ||
people usually choose a more convenient programming language. | ||
JavaScript is a perfect choice, but standard Node.js library | ||
requires additional hassle before using. `zx` package provides | ||
useful wrappers around `child_process` and gives sensible defaults. | ||
useful wrappers around `child_process`, escapes arguments and | ||
gives sensible defaults. | ||
@@ -36,3 +38,3 @@ ## Install | ||
Write your scripts in a file with `.mjs` extension in order to | ||
be able to use `await` on top level. In you prefer `.js` extension, | ||
be able to use `await` on top level. If you prefer `.js` extension, | ||
wrap your script in something like `void async function () {...}()`. | ||
@@ -60,3 +62,3 @@ | ||
### `$` | ||
### ``$`command` `` | ||
@@ -80,11 +82,2 @@ Executes given string using `exec` function | ||
```ts | ||
class ProcessOutput { | ||
readonly exitCode: number | ||
readonly stdout: string | ||
readonly stderr: string | ||
toString(): string | ||
} | ||
``` | ||
If executed program returns non-zero exit code, `ProcessOutput` will be thrown. | ||
@@ -101,4 +94,15 @@ | ||
### `cd` | ||
### `ProcessOutput` | ||
```ts | ||
class ProcessOutput { | ||
readonly exitCode: number | ||
readonly stdout: string | ||
readonly stderr: string | ||
toString(): string | ||
} | ||
``` | ||
### `cd()` | ||
Changes working directory. | ||
@@ -111,22 +115,4 @@ | ||
### `test` | ||
### `fetch()` | ||
Executes `test` command using `execSync` and returns `true` or `false`. | ||
```js | ||
if (test('-f package.json')) { | ||
console.log('Yes') | ||
} | ||
``` | ||
This is equivalent of next bash code: | ||
```bash | ||
if test -f package.json; then | ||
echo Yes; | ||
fi | ||
``` | ||
### `fetch` | ||
This is a wrapper around [node-fetch](https://www.npmjs.com/package/node-fetch) package. | ||
@@ -140,3 +126,3 @@ ```js | ||
### `question` | ||
### `question()` | ||
@@ -162,3 +148,3 @@ This is a wrapper around [readline](https://nodejs.org/api/readline.html) package. | ||
### `chalk` | ||
### `chalk` package | ||
@@ -172,5 +158,5 @@ The [chalk](https://www.npmjs.com/package/chalk) package available without | ||
### `fs` | ||
### `fs` package | ||
The [fx](https://nodejs.org/api/fs.html) package available without importing | ||
The [fs](https://nodejs.org/api/fs.html) package available without importing | ||
inside scripts. | ||
@@ -188,3 +174,3 @@ | ||
### `os` | ||
### `os` package | ||
@@ -213,3 +199,3 @@ The [os](https://nodejs.org/api/os.html) package available without importing | ||
### Importing | ||
### Importing from other scripts | ||
@@ -224,2 +210,9 @@ It's possible to use `$` and others with explicit import. | ||
### Passing env variables | ||
```js | ||
process.env.FOO = 'bar' | ||
await $`echo $FOO` | ||
``` | ||
### Executing remote scripts | ||
@@ -226,0 +219,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24482
300
4
219
+ Addedshq@^1.0.2
+ Addedshq@1.0.3(transitive)