Markdown 脚本
想象一个带有代码块、格式化注释、模式、插图等的脚本。Markdown 非常适合此目的。组合 ts
, js
, bash
部分以生成单个 zx 场景。 例如
文本
# Some script
`ls` — is an unix command to get directory contents. Let's see how to use it in `zx`:
```js
// ts, js, cjs, mjs, etc
const {stdout} = await $`ls -l`
console.log('directory contents:', stdout)
```
This part invokes the same command in a different way:
```bash
# bash syntax
ls -l
```
以及它的样子
一些脚本
ls
- 是一个用于获取目录内容的 unix 命令。 让我们看看如何在zx
中使用它js// ts, js, cjs, mjs, etc const {stdout} = await $`ls -l` console.log('directory contents:', stdout)
这部分以不同的方式调用相同的命令
bash# bash syntax ls -l
其余的很简单:只需通过 zx
命令运行
bash
zx script.md
提示
您也可以在此处使用导入
js
await import('chalk')
js
、javascript
、ts
、typescript
、sh
、shell
、bash
代码块将由 zx 执行。
bash
VAR=$(date)
echo "$VAR" | wc -c
其他类型将被忽略
css
body .hero {
margin: 42px;
}
__filename
将指向 markdown.md
js
console.log(chalk.yellowBright(__filename))