zx
zx copied to clipboard
Allow running a command from a string instead of string template
Expected Behavior
const foo = 'foo'
const cmd = `${foo} bar`
console.log(cmd)
$(cmd)
Works.
Actual Behavior
I doesn't work properly.
I want this so I can log commands before I run them.
Related
https://github.com/google/zx/issues/394
- How it actually works:
const args = [
'npm',
'install',
'--no-save',
'--no-audit',
'--no-fund',
]
const pieces = new Array(args.length + 1).fill(' ')
await $(pieces as any as TemplateStringsArray, ...args)
-
quotesstands for security reasons. -
zx logs cmd if
$.verboseis set totrue. There's no need to add a custom hook for this.
export function log(entry: LogEntry) {
switch (entry.kind) {
case 'cmd':
if (!entry.verbose) return
process.stderr.write(formatCmd(entry.cmd))
break
- You can substitute
$with your own custom version with any hooks. https://github.com/qiwi/zx-extra/blob/master/src/main/js/index.mjs#L11