@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 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
- * callback: ({ i, write, close }) => i === 0 ? write("console.log('hello')") : close(),
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "icon": "⏯️",
3
3
  "name": "@libs/run",
4
- "version": "2.0.4",
4
+ "version": "2.0.5",
5
5
  "description": "Utilities to run subprocess.",
6
6
  "keywords": [
7
7
  "subprocess",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowlighter/run",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "type": "module",
5
5
  "scripts": {},
6
6
  "dependencies": {},