26
26
</p >
27
27
28
28
``` typescript
29
- #! / usr / bin / env dzx
30
- /// <reference path = " https://deno.land/x/[email protected] /types.d.ts" />
29
+ import {
30
+ $ ,
31
+ asny ,
32
+ cd ,
33
+ fs ,
34
+ io ,
35
+ path ,
36
+ }
from " https://deno.land/x/[email protected] /mod.ts" ;
31
37
32
38
$ .verbose = true ;
33
39
$ .shell = " /usr/local/bin/zsh" ;
@@ -37,9 +43,10 @@ console.log(`Hello from ${$.blue.bold("dzx")}!`);
37
43
const branch = await $ ` git branch --show-current ` ;
38
44
await $ ` dep deploy --branch=${branch } ` ;
39
45
40
- // Print command output to stdout. Will be reverted to "piped" after all async ops are done .
46
+ // Print command output to stdout and stderr .
41
47
$ .stdout = " inherit" ;
42
48
$ .stderr = " inherit" ;
49
+
43
50
await Promise .all ([
44
51
$ ` deno lint ` ,
45
52
$ ` deno fmt --check ` ,
@@ -66,89 +73,90 @@ await fs.ensureDir("./tmp");
66
73
- [ Install] ( #install )
67
74
- [ Usage] ( #usage )
68
75
- [ Permissions] ( #permissions )
69
- - [ Worker] ( #worker )
70
76
- [ Markdown] ( #markdown )
71
77
- [ Methods] ( #methods )
72
78
- [ Modules] ( #modules )
73
79
- [ Variables] ( #variables )
80
+ - [ Experimental] ( #experimental )
81
+ - [ Worker] ( #worker )
74
82
- [ CLI] ( #cli )
75
83
- [ Contributing] ( #contributing )
76
84
- [ License] ( #license )
77
85
78
86
## Install
79
87
80
88
```
81
- deno install --allow-all --unstable -f https://deno.land/x/[email protected] .1 /dzx.ts
89
+ deno install --allow-all --unstable -f https://deno.land/x/[email protected] .2 /dzx.ts
82
90
```
83
91
84
92
> ` --unstable ` is required for the ` bundle ` command which uses ` Deno.emit ` , for
85
93
> ` std/fs/copy ` and for web workers.
86
94
87
95
## Usage
88
96
89
- To start writing a dzx script, add next shebang at the beginning of your script:
97
+ ### Module usage
90
98
91
- ```
92
- #!/usr/bin/env dzx
99
+ The default way is to just import the modules you need from the ` dzx/mod.ts `
100
+ module. This doesn't inject any globals into your script.
101
+
102
+ ``` ts
103
+ import {
$ ,
cd ,
fs ,
io ,
log ,
path }
from " https://deno.land/x/[email protected] /mod.ts" ;
93
104
```
94
105
95
- To enable typings for typescript in your IDE, you can add a tripple slash
96
- reference to the top of the file,
106
+ ### Globals usage
97
107
98
- ```
99
- #!/usr/bin/env dzx
100
- /// <reference path="https://deno.land/x/[email protected] /types.d.ts" />
108
+ To avoid importing modules you can also import the ` globals.ts ` file. This makes
109
+ all exports from ` mod.ts ` globally available.
110
+
111
+ ``` ts
112
+ import from " https://deno.land/x/[email protected] /globals.ts" ;
101
113
```
102
114
103
- or you can import all symbol directly from the ` dzx/mod.ts ` module instead of
104
- using globals.
115
+ ### CLI usage
105
116
106
- ``` ts
117
+ When a dzx script is executed via CLI, you don't need to import anything. All
118
+ exports are automatically global available. This applies also to commands like
119
+ ` dzx eval "console.log($)" ` .
120
+
121
+ To start writing a dzx script, add next shebang at the beginning of your script:
122
+
123
+ ```
107
124
#!/usr/bin/env dzx
108
- import {
$ ,
cd ,
fs ,
io ,
log ,
path }
from " https://deno.land/x/[email protected] /mod.ts" ;
109
125
```
110
126
111
127
After making your script executable,
112
128
113
129
``` shell
114
- chmod +x ./script.ts
130
+ chmod +x ./script.js
115
131
```
116
132
117
133
you can simply run it with:
118
134
119
135
``` shell
120
- ./script.ts
136
+ ./script.js
121
137
```
122
138
123
- ## Permissions
124
-
125
- You can use ` dzx ` without installation by using next shebang. This also allows
126
- you to explicitly set the permissions for your script.
127
-
128
- ``` typescript
129
- #
! / usr / bin / env deno run -- allow - run -- allow - read -- allow - env https :
// deno.land/x/[email protected] /dzx.ts
130
- /// <reference path = " https://deno.land/x/[email protected] /types.d.ts" />
139
+ To enable typescript support in your IDE, you can optionally add a tripple slash
140
+ reference to the top of the file.
131
141
132
- console .log (` Hello ${$ .blue .bold (" world" )}! ` );
142
+ ```
143
+ #!/usr/bin/env dzx
144
+ /// <reference path="https://deno.land/x/[email protected] /types.d.ts" />
133
145
```
134
146
135
- ## Worker
136
-
137
- > This is currently an exerminental feature. Permission flags doens't support
138
- > values currently. Read permissions are required by default.
147
+ ### Permissions
139
148
140
- If ` dzx ` is called with ` -w ` or ` --worker ` , the script is executed inside an
141
- isolated web worker. If enabled, you can pass explicit permissions directly to
142
- the ` dzx ` cli.
149
+ You can use ` dzx ` without installation by using next shebang. This also allows
150
+ you to explicitly set the permissions for your script.
143
151
144
152
``` typescript
145
- #! / usr / bin / env dzx -- worker -- allow - read
146
- /// <reference path = " https://deno.land/x/[email protected] .1 /types.d.ts" />
153
+ #
! / usr / bin / env deno run -- allow - run -- allow - read -- allow - env https : // deno.land/x/[email protected] /dzx.ts
154
+ /// <reference path = " https://deno.land/x/[email protected] .2 /types.d.ts" />
147
155
148
- console .log (` Hello from ${$ .blue .bold (" worker " )}! ` );
156
+ console .log (` Hello ${$ .blue .bold (" world " )}! ` );
149
157
```
150
158
151
- ## Markdown
159
+ ### Markdown
152
160
153
161
With ` dzx ` you can run the ` js ` /` ts ` code blocks from a Markdown file as if they
154
162
were a regular script. This is very convenient when you want to blend some
@@ -163,9 +171,10 @@ dzx ./examples/markdown.md
163
171
See the [ markdown example] ( ./examples/markdown.md ) for further documentation and
164
172
notes.
165
173
166
- ## Methods
174
+ ### Methods
167
175
168
- - `` $`command` `` : Executes a shell command.
176
+ - `` $`command` `` : Executes a shell command and returns a ` Process ` instance.
177
+ The [ ` Process ` ] ( #process ) class has several chainable methods.
169
178
170
179
``` ts
171
180
const count = parseInt (await $ ` ls -1 | wc -l ` );
@@ -253,7 +262,34 @@ notes.
253
262
- `` quote`string` `` : The quote methods quotes safly a string. by default the
254
263
` shq ` package is used. Can be overidden with ` $.quote ` .
255
264
256
- ## Modules
265
+ ### Process
266
+
267
+ Methods and properties of the ` Process ` class which implements
268
+ ` Promise<ProcessOutput> ` and is returned by the ` $ ` method.
269
+
270
+ - ` .pid ` : Returns the process id of the executed command.
271
+
272
+ - ` .noThrow ` : If invoked the command doesn't throw an error if the command
273
+ returns a none-zero exit code.
274
+
275
+ - ` .statusCode ` : Returns the status code of the executed command and calls
276
+ ` .noThrow ` internally to catch the error and return the status code.
277
+
278
+ - ` .stdout ` Returns ` Promise<string> ` and resolves with the stdout output.
279
+
280
+ - ` .stderr ` Returns ` Promise<string> ` and resolves with the stderr output.
281
+
282
+ - ` .retry(retries: number) ` Retry the command ` n ` times if it fails.
283
+
284
+ - ` .delay(delay: number) ` Number of milliseconds to delay the retry of a failed
285
+ command. Default: ` 500 `
286
+
287
+ - ` .timeout(timeout: number) ` Throws an error if the command takes longer than
288
+ the provided ` timeout ` in milliseconds.
289
+
290
+ - ` .kill(signal: Deno.Signal) ` Kills the running process.
291
+
292
+ ### Modules
257
293
258
294
- ** $.\[ style] :** Cliffy's color module. A chainable wrapper for Deno's
259
295
` std/fmt/colors ` module. Available on the global ` $ ` symbol.
@@ -309,7 +345,7 @@ notes.
309
345
const args: flags .Args = flags .parse ($ .args );
310
346
```
311
347
312
- ## Variables
348
+ ### Variables
313
349
314
350
- ** $.shell:** Set the shell that is used by `` $`command` `` . Default:
315
351
` /bin/bash `
@@ -328,37 +364,64 @@ notes.
328
364
- ** $.quote:** Parser method that is used to safely quote strings. Used by:
329
365
`` $`command` ``
330
366
331
- # CLI
367
+ ## Experimental
368
+
369
+ ### Worker
370
+
371
+ > This is currently an exerminental feature. Permission flags doesn't support
372
+ > values currently. Read permissions are required by default.
373
+
374
+ If ` dzx ` is called with ` -w ` or ` --worker ` , the script is executed inside an
375
+ isolated web worker. If enabled, you can pass explicit permissions directly to
376
+ the ` dzx ` cli.
377
+
378
+ ``` typescript
379
+ #! / usr / bin / env dzx -- worker -- allow - read
380
+ /// <reference path = " https://deno.land/x/[email protected] /types.d.ts" />
381
+
382
+ console .log (` Hello from ${$ .blue .bold (" worker" )}! ` );
383
+ ```
384
+
385
+ ## CLI
332
386
333
387
```
334
- Usage: dzx [script] [args...]
335
- Version: 0.3.1
336
-
337
- Description:
338
-
339
- 🦕 A custom deno runtime for fun.
340
-
341
- Options:
342
-
343
- -h, --help - Show this help.
344
- -V, --version - Show the version number for this program.
345
- -A, --allow-all - Allow all permissions. (Depends: --worker)
346
- --allow-env - Allow environment access. (Depends: --worker)
347
- --allow-hrtime - Allow high resolution time measurement. (Depends: --worker)
348
- --allow-net - Allow network access. (Depends: --worker)
349
- --allow-ffi - Allow loading dynamic libraries. (Depends: --worker)
350
- --allow-read - Allow file system read access. (Depends: --worker)
351
- --allow-run - Allow running subprocesses. (Depends: --worker)
352
- --allow-write - Allow file system write access. (Depends: --worker)
353
- -w, --worker - Run script in an isolated web worker with it's own permissions.
354
-
355
- Commands:
356
-
357
- bundle [script] - Bundle an dzx script to a standalone deno sript.
358
- compile [compile-options...] [script] [script-options...] - Combile an dzx script to a standalone binary.
359
- eval <code> - Evaluate a dzx script from the command line.
360
- repl - Start a dzx repl.
361
- upgrade - Upgrade dzx executable to latest or given version.
388
+ Usage: dzx [script] [args...]
389
+ Version: 0.3.1 (New version available: 0.3.2. Run 'dzx upgrade' to upgrade to the latest version!)
390
+
391
+ Description:
392
+
393
+ A custom deno runtime for fun.
394
+
395
+ Options:
396
+
397
+ -h, --help - Show this help.
398
+ -V, --version - Show the version number for this program.
399
+ -A, --allow-all - Allow all permissions. (Depends: --worker)
400
+ --allow-env - Allow environment access. (Depends: --worker)
401
+ --allow-hrtime - Allow high resolution time measurement. (Depends: --worker)
402
+ --allow-net - Allow network access. (Depends: --worker)
403
+ --allow-ffi - Allow loading dynamic libraries. (Depends: --worker)
404
+ --allow-read - Allow file system read access. (Depends: --worker)
405
+ --allow-run - Allow running subprocesses. (Depends: --worker)
406
+ --allow-write - Allow file system write access. (Depends: --worker)
407
+ --compat - Node compatibility mode. Currently only enables built-in node modules like 'fs'
408
+ and globals like 'process'.
409
+ --inspect <host> - Activate inspector on host:port. (default: 127.0.0.1:9229)
410
+ --inspect-brk <host> - Activate inspector on host:port and break at start of user script.
411
+ -w, --worker - Run script in an isolated web worker with it's own permissions. (experimental)
412
+ -v, --verbose - Enable verbose mode. This option can appear up to three times. (Default: 1)
413
+ -v: Print executed commands and script execution time.
414
+ -vv: Print also stdout and stderr.
415
+ -vvv: Print internal debug information.
416
+ --no-verbose - Disable stdout output.
417
+
418
+ Commands:
419
+
420
+ bundle [script] - Bundle a dzx script to a standalone deno script.
421
+ compile [script] - Compile a dzx script to a standalone binary.
422
+ eval [code] - Evaluate a dzx script from the command line.
423
+ repl - Start a dzx repl.
424
+ upgrade - Upgrade dzx executable to latest or given version.
362
425
```
363
426
364
427
- ** dzx** ` [script] [...args] ` : Run a local or remote dzx script (optional in a
0 commit comments