Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "zx", | ||
"version": "1.0.0", | ||
"description": "Deployment and automation tool", | ||
"main": "src/index.js", | ||
"version": "1.0.1", | ||
"description": "Replaces bash with js", | ||
"main": "index.mjs", | ||
"types": "index.d.ts", | ||
"bin": { | ||
"zx": "zx.mjs" | ||
}, | ||
"scripts": { | ||
"test": "ava" | ||
"test": "zx test.mjs" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/antonmedv/zx.git" | ||
"dependencies": { | ||
"chalk": "^4.1.1", | ||
"node-fetch": "^2.6.1", | ||
"uuid": "^8.3.2" | ||
}, | ||
"keywords": [ | ||
"deployment" | ||
"publishConfig": { | ||
"registry": "https://wombat-dressing-room.appspot.com" | ||
}, | ||
"files": [ | ||
"*.mjs", | ||
"*.js" | ||
], | ||
"repository": "google/zx", | ||
"author": "Anton Medvedev <anton@medv.io>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/antonmedv/zx/issues" | ||
}, | ||
"homepage": "https://github.com/antonmedv/zx#readme" | ||
"license": "Apache-2.0" | ||
} |
227
README.md
@@ -1,2 +0,225 @@ | ||
# zx | ||
Node deployment and automation tool | ||
# 🐚 zx | ||
```js | ||
#!/usr/bin/env zx | ||
await $`cat package.json | grep name` | ||
let branch = await $`git branch --show-current` | ||
await $`dep deploy --branch=${branch}` | ||
await Promise.all([ | ||
$`sleep 1; echo 1`, | ||
$`sleep 2; echo 2`, | ||
$`sleep 3; echo 3`, | ||
]) | ||
await $`ssh medv.io uptime` | ||
``` | ||
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 | ||
requires additional hassle before using. `zx` package provides | ||
useful wrappers around `child_process` and gives sensible defaults. | ||
## Install | ||
```bash | ||
npm i -g zx | ||
``` | ||
## Documentation | ||
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, | ||
wrap your script in something like `void async function () {...}()`. | ||
Add next shebang at the beginning of your script: | ||
```bash | ||
#!/usr/bin/env zx | ||
``` | ||
Now you will be able to run your script as: | ||
```bash | ||
chmod +x ./script.mjs | ||
./script.mjs | ||
``` | ||
Or via `zx` bin: | ||
```bash | ||
zx ./script.mjs | ||
``` | ||
Then using `zx` bin or via shebang, all `$`, `cd`, `fetch`, etc | ||
available without imports. | ||
### `$` | ||
Executes given string using `exec` function | ||
from `child_process` package and returns `Promise<ProcessOutput>`. | ||
```js | ||
let count = parseInt(await $`ls -1 | wc -l`) | ||
console.log(`Files count: ${count}`) | ||
``` | ||
Example. Upload files in parallel: | ||
```js | ||
let hosts = [...] | ||
await Promise.all(hosts.map(host => | ||
$`rsync -azP ./src ${host}:/var/www` | ||
)) | ||
``` | ||
```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. | ||
```js | ||
try { | ||
await $`exit 1` | ||
} catch (p) { | ||
console.log(`Exit code: ${p.exitCode}`) | ||
console.log(`Error: ${p.stderr}`) | ||
} | ||
``` | ||
### `cd` | ||
Changes working directory. | ||
```js | ||
cd('/tmp') | ||
await $`pwd` // outputs /tmp | ||
``` | ||
### `test` | ||
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. | ||
```js | ||
let resp = await fetch('http://wttr.in') | ||
if (resp.ok) { | ||
console.log(await resp.text()) | ||
} | ||
``` | ||
### `question` | ||
This is a wrapper around [readline](https://nodejs.org/api/readline.html) package. | ||
```ts | ||
type QuestionOptions = { choices: string[] } | ||
function question(query: string, options?: QuestionOptions): Promise<string> | ||
``` | ||
Usage: | ||
```js | ||
let username = await question('What is your username? ') | ||
let token = await question('Choose env variable: ', { | ||
choices: Object.keys(process.env) | ||
}) | ||
``` | ||
### `chalk` | ||
The [chalk](https://www.npmjs.com/package/chalk) package available without | ||
importing inside scripts. | ||
```js | ||
console.log(chalk.blue('Hello world!')) | ||
``` | ||
### `fs` | ||
The [fx](https://nodejs.org/api/fs.html) package available without importing | ||
inside scripts. | ||
```js | ||
let content = await fs.readFile('./package.json') | ||
``` | ||
Promisified version imported by default. Same as if you write: | ||
```js | ||
import {promises as fs} from 'fs' | ||
``` | ||
### `os` | ||
The [os](https://nodejs.org/api/os.html) package available without importing | ||
inside scripts. | ||
```js | ||
await $`cd ${os.homedir()} && mkdir example` | ||
``` | ||
### `$.shell` | ||
Specifies what shell is used. Default is `/bin/sh`. | ||
```js | ||
$.shell = '/bin/bash' | ||
``` | ||
### `$.verbose` | ||
Specifies verbosity. Default: `true`. | ||
In verbose mode prints executed commands with outputs of it. Same as | ||
`set -x` in bash. | ||
### Importing | ||
It's possible to use `$` and others with explicit import. | ||
```js | ||
#!/usr/bin/env node | ||
import {$} from 'zx' | ||
await $`date` | ||
``` | ||
### Executing remote scripts | ||
If arg to `zx` bin starts with `https://`, it will be downloaded and executed. | ||
```bash | ||
zx https://medv.io/example-script.mjs | ||
``` | ||
## License | ||
[Apache-2.0](LICENSE) | ||
Disclaimer: _This is not an officially supported Google product._ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23631
7
253
226
3
3
5
+ Addedchalk@^4.1.1
+ Addednode-fetch@^2.6.1
+ Addeduuid@^8.3.2
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)