Skip to content

Commit

Permalink
feat: load experimental assets as globals via --experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 15, 2022
1 parent c205dc2 commit 1d50215
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ let {version} = require('./package.json')
The zx also provides a few experimental functions. Please leave a feedback about
those features in [the discussion](https://github.com/google/zx/discussions/299).
To enable new features via CLI pass `--experimantal` flag.
#### `retry()`
Expand Down
17 changes: 2 additions & 15 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,10 @@ export function $(pieces, ...args) {
return promise
}

$.verbose = !argv.quiet
if (typeof argv.shell === 'string') {
$.shell = argv.shell
$.prefix = ''
} else {
try {
$.shell = which.sync('bash')
$.prefix = 'set -euo pipefail;'
} catch (e) {
$.prefix = '' // Bash not found, no prefix.
}
}
if (typeof argv.prefix === 'string') {
$.prefix = argv.prefix
}
$.quote = quote
$.spawn = spawn
$.verbose = true
$.prefix = '' // Bash not found, no prefix.

export function cd(path) {
if ($.verbose) console.log('$', colorize(`cd ${path}`))
Expand Down
23 changes: 20 additions & 3 deletions zx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,27 @@ import {tmpdir} from 'os'
import {basename, dirname, extname, join, resolve} from 'path'
import url from 'url'

import './src/globals.mjs'
import {fetch, ProcessOutput} from './src/index.mjs'
import {$, argv, fetch, ProcessOutput, registerGlobals} from './src/index.mjs'
import which from 'which'

await async function main() {
registerGlobals()
$.verbose = !argv.quiet
if (typeof argv.shell === 'string') {
$.shell = argv.shell
} else {
try {
$.shell = which.sync('bash')
$.prefix = 'set -euo pipefail;'
} catch (e) {
}
}
if (typeof argv.prefix === 'string') {
$.prefix = argv.prefix
}
if (argv.experimental) {
Object.assign(global, await import('./experimental.mjs'))
}
try {
if (['--version', '-v', '-V'].includes(process.argv[2])) {
console.log(createRequire(import.meta.url)('./package.json').version)
Expand Down Expand Up @@ -197,7 +214,7 @@ function printUsage() {
Usage:
zx [options] <script>
Options:
--quiet : don't echo commands
--shell=<path> : custom shell binary
Expand Down

0 comments on commit 1d50215

Please sign in to comment.