22
22
<b >Deno shell tools inspired by <a href =" https://github.com/google/zx " >zx</a ></b >
23
23
</p >
24
24
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" )}! ` );
26
30
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
28
52
29
53
```
30
54
deno install --allow-all -r -f https://deno.land/x/dzx/dzx.ts
31
55
```
32
56
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
35
79
/// <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 `
36
132
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!" ));
38
162
```
39
163
40
164
## Remote usage
@@ -43,5 +167,13 @@ await $`Hello ${$.blue.bold("world")}!`;
43
167
#! / usr / bin / env deno run -- allow - run -- allow - read -- allow - env https :// deno.land/x/dzx/dzx.ts
44
168
/// <reference path = " https://deno.land/x/dzx/types.d.ts" />
45
169
46
- await $ ` Hello ${$ .blue .bold (" world" )}! ` ;
170
+ console . log ( ` Hello ${$ .blue .bold (" world" )}! ` ) ;
47
171
```
172
+
173
+ ## Contributing
174
+
175
+ Any kind of contribution is welcome!
176
+
177
+ ## License
178
+
179
+ [ MIT] ( LICENSE )
0 commit comments