@lowlighter/run 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/command.ts +10 -1
- package/deno.jsonc +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,42 @@
|
|
|
9
9
|
> [!WARNING]
|
|
10
10
|
> Deno exclusive!
|
|
11
11
|
|
|
12
|
+
## 📑 Examples
|
|
13
|
+
|
|
14
|
+
### Run a command
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { command } from "./command.ts"
|
|
18
|
+
|
|
19
|
+
// Commands are run asynchronously, and support Deno.command options alongside additional options
|
|
20
|
+
// For example, stdio can also be set to a Logger level too or you can automatically append an extension when running on Windows
|
|
21
|
+
await command("deno", ["version"], { stdout: "debug", stderr: "piped", winext: ".exe" })
|
|
22
|
+
|
|
23
|
+
// Commands can be run synchronously too, and can also throw an error automatically when the process exits with a non-zero code
|
|
24
|
+
command("deno", ["version"], { sync: true, throw: true })
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Writing to stdin
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { command } from "./command.ts"
|
|
31
|
+
|
|
32
|
+
const { stdout } = await command("deno", ["repl"], {
|
|
33
|
+
env: { NO_COLOR: "true" },
|
|
34
|
+
// Passing a callback will automatically set `stdin` to `"piped"`
|
|
35
|
+
// You can then write to the process using utility functions
|
|
36
|
+
callback: async ({ i, stdio, write, close, wait }) => {
|
|
37
|
+
if ((!stdio.stdout.includes("exit using")) || i) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
await write("console.log('hello')")
|
|
41
|
+
await wait(1000)
|
|
42
|
+
close()
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
console.assert(stdout.includes("hello"))
|
|
46
|
+
```
|
|
47
|
+
|
|
12
48
|
## ✨ Features
|
|
13
49
|
|
|
14
50
|
- Supports `stdin` interactivity through callbacks.
|
package/command.ts
CHANGED
|
@@ -161,9 +161,18 @@ export function command(bin: string, args: string[], options?: options & { sync:
|
|
|
161
161
|
* @example
|
|
162
162
|
* ```ts
|
|
163
163
|
* import { command } from "./command.ts"
|
|
164
|
+
*
|
|
164
165
|
* const { stdout } = await command("deno", ["repl"], {
|
|
165
166
|
* env: { NO_COLOR: "true" },
|
|
166
|
-
*
|
|
167
|
+
* // Passing a callback will automatically set `stdin` to `"piped"`
|
|
168
|
+
* // You can then write to the process using utility functions
|
|
169
|
+
* callback: async ({ i, stdio, write, close, wait }) => {
|
|
170
|
+
* if ((!stdio.stdout.includes("exit using")) || (i))
|
|
171
|
+
* return
|
|
172
|
+
* await write("console.log('hello')")
|
|
173
|
+
* await wait(1000)
|
|
174
|
+
* close()
|
|
175
|
+
* },
|
|
167
176
|
* })
|
|
168
177
|
* console.assert(stdout.includes("hello"))
|
|
169
178
|
* ```
|
package/deno.jsonc
CHANGED