Skip to content

Commit 730aed0

Browse files
committed
docs: add documentation
1 parent 855a800 commit 730aed0

File tree

1 file changed

+138
-6
lines changed

1 file changed

+138
-6
lines changed

README.md

Lines changed: 138 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,143 @@
2222
<b>Deno shell tools inspired by <a href="https://github.com/google/zx">zx</a></b>
2323
</p>
2424

25-
## Global usage
25+
```typescript
26+
#!/usr/bin/env dzx
27+
/// <reference path="https://deno.land/x/dzx/types.d.ts" />
28+
29+
console.log(`Hello from ${$.blue.bold("dzx")}!`);
2630

27-
Install dzx globally
31+
const branch = await $`git branch --show-current`;
32+
await $`dep deploy --branch=${branch}`;
33+
34+
await Promise.all([
35+
$`deno lint --unstable`,
36+
$`deno fmt --check`,
37+
$`deno test --allow-all`,
38+
]);
39+
40+
const name = "foo bar";
41+
await $`mkdir /tmp/${name}`;
42+
```
43+
44+
## Content
45+
46+
- [Install](#install)
47+
- [Documentation](#documentation)
48+
- [Contributing](#contributing)
49+
- [License](#license)
50+
51+
## Install
2852

2953
```
3054
deno install --allow-all -r -f https://deno.land/x/dzx/dzx.ts
3155
```
3256

33-
```typescript
34-
#!/usr/bin/env dzx
57+
## Documentation
58+
59+
You can write your scripts in a file with .js, .mjs or .ts extension.
60+
61+
Add next shebang at the beginning of your script:
62+
63+
```
64+
#!/usr/bin/env zx
65+
```
66+
67+
Now you will be able to run your script as:
68+
69+
```shell
70+
chmod +x ./script.js
71+
./script.js
72+
```
73+
74+
If you want to use typescript you need to add a tripple slash reference for the
75+
typings at the top of the file, but not before the shebang line.
76+
77+
```
78+
#!/usr/bin/env zx
3579
/// <reference path="https://deno.land/x/dzx/types.d.ts" />
80+
```
81+
82+
Now you will be able to run your typescript script the same way as your js
83+
script:
84+
85+
```shell
86+
chmod +x ./script.ts
87+
./script.ts
88+
```
89+
90+
You can also import all symbol directly from `dzx/mod.ts` instead of using
91+
globals.
92+
93+
```ts
94+
#!/usr/bin/env zx
95+
import { $ } from "https://deno.land/x/dzx/mod.ts";
96+
```
97+
98+
### `$.verbose`
99+
100+
Enable debugging output.
101+
102+
### `$.shell`
103+
104+
Set the current shel.
105+
106+
### `$.cwd`
107+
108+
Set the current working directory.
109+
110+
### $`command`
111+
112+
```ts
113+
const count = parseInt(await $`ls -1 | wc -l`);
114+
console.log(`Files count: ${count}`);
115+
```
116+
117+
#### Error Handling
118+
119+
If the executed program returns a non-zero exit code, a `ProcessError` will be
120+
thrown.
121+
122+
```ts
123+
try {
124+
await $`exit 1`;
125+
} catch (p) {
126+
console.log(`Exit code: ${p.exitCode}`);
127+
console.log(`Error: ${p.stderr}`);
128+
}
129+
```
130+
131+
#### `ProcessOutput`
36132

37-
await $`Hello ${$.blue.bold("world")}!`;
133+
```ts
134+
class ProcessOutput {
135+
readonly stdout: string;
136+
readonly stderr: string;
137+
readonly statud: Deno.RunStatus;
138+
toString(): string;
139+
}
140+
```
141+
142+
#### `ProcessError`
143+
144+
The `ProcessError` class extends from the `Error` class and implements all
145+
properties and methods from the `ProcessOutput`.
146+
147+
```ts
148+
class ProcessError extends Error implements ProcessOutput {}
149+
```
150+
151+
### `cd()`
152+
153+
Global available cd method to set the current working directory. Also available
154+
on the global `$` symbol.
155+
156+
### `$.[style]()`
157+
158+
dzx has chainable color methods that are available on the global `$` symbol.
159+
160+
```ts
161+
console.log($.blue("Hello world!"));
38162
```
39163

40164
## Remote usage
@@ -43,5 +167,13 @@ await $`Hello ${$.blue.bold("world")}!`;
43167
#!/usr/bin/env deno run --allow-run --allow-read --allow-env https://deno.land/x/dzx/dzx.ts
44168
/// <reference path="https://deno.land/x/dzx/types.d.ts" />
45169

46-
await $`Hello ${$.blue.bold("world")}!`;
170+
console.log(`Hello ${$.blue.bold("world")}!`);
47171
```
172+
173+
## Contributing
174+
175+
Any kind of contribution is welcome!
176+
177+
## License
178+
179+
[MIT](LICENSE)

0 commit comments

Comments
 (0)