Commit 287ed0b
Changed files (8)
examples
examples/basics.mjs
@@ -1,42 +0,0 @@
-#!/usr/bin/env zx
-
-// Copyright 2021 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-await $`ls -1 | wc -l`
-
-let branch = await $`git branch --show-current`
-await $`echo ${branch} | wc` // The new line trimmed from stdout.
-
-let foo = `hi; echo 'oops'`
-await $`echo ${foo} | wc` // Vars properly quoted.
-
-let path = await import('path') // We can use import,
-let {name} = require(path.join(__dirname, '..', 'package.json')) // and require.
-
-console.log(chalk.black.bgCyanBright(name)) // The chalk is available without import.
-
-try {
- await $`exit 42` // ProcessOutput will be thrown on non-zero exit codes.
-} catch (p) {
- console.log(p.exitCode)
-}
-
-let {exitCode} = await nothrow($`exit 42`) // Change behavior to no-throw.
-exitCode = await $`exit 42`.exitCode // Or wait on exitCode itself.
-
-// Use combinations of pipe() and nothrow():
-await $`find ./examples -type f -print0`
- .pipe(nothrow($`xargs -0 grep ${'missing' + 'part'}`))
- .pipe($`wc -l`)
examples/markdown.md
@@ -5,7 +5,7 @@ by zx. Try to run `zx examples/markdown.md`.
```js
await $`whoami`
-await $`ls -la ${__dirname}`
+await $`echo ${__dirname}`
```
The `__filename` will be pointed to **markdown.md**:
@@ -17,7 +17,7 @@ console.log(chalk.yellowBright(__filename))
We can use imports here as well:
```js
-await import('./basics.mjs')
+await import('chalk')
```
A bash code (with `bash` or `sh` language tags) also will be executed:
examples/interactive.mjs → tests/interactive.mjs
File renamed without changes
examples/no-extension → tests/no-extension
File renamed without changes
examples/typescript.ts → tests/typescript.ts
@@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import {ProcessOutput, ProcessPromise} from '..'
+import {ProcessOutput, ProcessPromise} from '../index'
void async function () {
let p: ProcessPromise<ProcessOutput> = $`cat`
README.md
@@ -354,7 +354,7 @@ zx examples/markdown.md
The `zx` can compile `.ts` scripts to `.mjs` and execute them.
```bash
-zx examples/typescript.ts
+zx script.ts
```
In TypeScript file include the `zx` package to import types:
test.mjs
@@ -82,7 +82,7 @@ import path from 'path'
}
{ // Scripts with no extension are working
- await $`node zx.mjs examples/no-extension`
+ await $`node zx.mjs tests/no-extension`
}
{ // require() is working from stdin
@@ -94,7 +94,7 @@ import path from 'path'
}
{ // TypeScript scripts are working
- await $`node zx.mjs examples/typescript.ts`
+ await $`node zx.mjs tests/typescript.ts`
}
{ // Quiet mode is working
zx.mjs
@@ -198,14 +198,13 @@ async function compile(input) {
let tsc = $`npm_config_yes=true npx -p typescript tsc --target esnext --lib esnext --module esnext --moduleResolution node ${input}`
$.verbose = v
- let i = 0, color = [chalk.magentaBright, chalk.cyanBright, chalk.yellowBright,
- chalk.greenBright, chalk.blueBright][new Date().getMinutes() % 5],
- interval = setInterval(() => {
- process.stdout.write(' '
- + color(['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'][i++ % 10])
- + '\r'
- )
- }, 100)
+ let i = 0
+ let interval = setInterval(() => {
+ process.stdout.write(' '
+ + ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'][i++ % 10]
+ + '\r'
+ )
+ }, 100)
try {
await tsc