-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 add api docs and readme examples for tinyexec
Docs are good if we want a contrib library to have a good score and be used. This adds typedocs for the tinyexec package as well as some simple examples
- Loading branch information
Showing
2 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import { | |
resource, | ||
type Stream, | ||
stream, | ||
useAbortSignal, | ||
} from "npm:[email protected]"; | ||
import { | ||
type KillSignal, | ||
|
@@ -13,21 +12,38 @@ import { | |
x as $x, | ||
} from "npm:[email protected]"; | ||
|
||
/** | ||
* Wraps a [tinyexec](https://github.com/tinylibs/tinyexec) process. | ||
* To create one use the {@link x} function. | ||
*/ | ||
export interface TinyProcess extends Operation<Output> { | ||
/** | ||
* A stream of lines coming from both stdin and stdout. The stream | ||
* will terminate when stdout and stderr are closed which usually | ||
* corresponds to the process ending. | ||
*/ | ||
lines: Stream<string, void>; | ||
|
||
/** | ||
* Send `signal` to this process | ||
* @paramu signal - the OS signal to send to the process | ||
*/ | ||
kill(signal?: KillSignal): Operation<void>; | ||
} | ||
|
||
/** | ||
* Run OS process with `cmd` | ||
* | ||
* This will create a {@link TinyProcess} resource. If it is still running | ||
* when it passes out of scope, it will be killed. | ||
*/ | ||
export function x( | ||
cmd: string, | ||
args: string[] = [], | ||
options?: Partial<Options>, | ||
): Operation<TinyProcess> { | ||
return resource(function* (provide) { | ||
let signal = yield* useAbortSignal(); | ||
|
||
let tinyexec = $x(cmd, args, { ...options, signal }); | ||
let tinyexec = $x(cmd, args, { ...options }); | ||
|
||
let promise: Promise<Output> = tinyexec as unknown as Promise<Output>; | ||
|
||
|