import "./_dnt.polyfills.js"; import { CommandBuilder } from "./src/command.js"; import type { RawArg, TemplateExpr } from "./src/command.js"; import { type Delay, type DelayIterator, symbols } from "./src/common.js"; import { type ConfirmOptions, type MultiSelectOptions, ProgressBar, type ProgressOptions, type PromptOptions, type SelectOptions } from "./src/console/mod.js"; import { Path } from "./deps/jsr.io/@david/path/0.2.0/mod.js"; import { RequestBuilder } from "./src/request.js"; import { outdent } from "./src/vendor/outdent.js"; export { type DirEntry, FsFileWrapper, Path, type SymlinkOptions } from "./deps/jsr.io/@david/path/0.2.0/mod.js"; export type { Delay, DelayIterator } from "./src/common.js"; export { TimeoutError } from "./src/common.js"; /** @deprecated Import `Path` instead. */ declare const PathRef: typeof Path; export { PathRef }; export { CommandBuilder, CommandChild, CommandResult, KillController, KillSignal, type KillSignalListener, RawArg, type TemplateExpr, } from "./src/command.js"; export type { CommandContext, CommandHandler, CommandPipeReader, CommandPipeWriter } from "./src/command_handler.js"; export type { ConfirmOptions, MultiSelectOption, MultiSelectOptions, ProgressBar, ProgressOptions, PromptInputMask, PromptOptions, SelectOptions, } from "./src/console/mod.js"; export type { Closer, Reader, ShellPipeReaderKind, ShellPipeWriterKind, WriterSync } from "./src/pipes.js"; export { RequestBuilder, RequestResponse } from "./src/request.js"; export type { CdChange, ContinueExecuteResult, EnvChange, ExecuteResult, ExitExecuteResult, SetEnvVarChange, SetShellVarChange, UnsetVarChange, } from "./src/result.js"; export { createExecutableCommand } from "./src/commands/executable.js"; /** * Cross platform shell tools for Deno inspired by [zx](https://github.com/google/zx). * * Differences: * * 1. Cross platform shell. * - Makes more code work on Windows. * - Allows exporting the shell's environment to the current process. * - Uses [deno_task_shell](https://github.com/denoland/deno_task_shell)'s parser. * - Has common commands built-in for better Windows support. * 1. Minimal globals or global configuration. * - Only a default instance of `$`, but it's not mandatory to use this. * 1. No custom CLI. * 1. Good for application code in addition to use as a shell script replacement. * 1. Named after my cat. * * ## Example * * ```ts * import $ from "https://deno.land/x/dax@VERSION_GOES_HERE/mod.ts"; * * await $`echo hello`; * ``` * * @module */ /** Options for using `$.retry({ ... })` */ export interface RetryOptions { /** Number of times to retry. */ count: number; /** Delay in milliseconds. */ delay: Delay | DelayIterator; /** Action to retry if it throws. */ action: () => Promise; /** Do not log. */ quiet?: boolean; } /** Type of `$` instances. */ export type $Type = $Template & (string extends keyof TExtras ? $BuiltInProperties : Omit<$BuiltInProperties, keyof TExtras>) & TExtras; /** String literal template. */ export interface $Template { (strings: TemplateStringsArray, ...exprs: TemplateExpr[]): CommandBuilder; } /** * `outdent` from the https://deno.land/x/outdent module. * @internal */ type Outdent = typeof outdent; /** * `which` from the https://deno.land/x/which module. * @internal */ type Which = typeof import("./deps/jsr.io/@david/which/0.4.1/mod.js").which; /** * `whichSync` from the https://deno.land/x/which module. * @internal */ type WhichSync = typeof import("./deps/jsr.io/@david/which/0.4.1/mod.js").whichSync; /** Collection of built-in properties that come with a `$`. */ export interface $BuiltInProperties { /** * Makes a request to the provided URL throwing by default if the * response is not successful. * * ```ts * const data = await $.request("https://plugins.dprint.dev/info.json") * .json(); * ``` * * @see {@link RequestBuilder} */ request(url: string | URL): RequestBuilder; /** * Builds a new `$` which will use the state of the provided * builders as the default and inherits settings from the `$` the * new `$` was built from. * * This can be useful if you want different default settings or want * to change loggers for only a subset of code. * * Example: * * ```ts * import $ from "https://deno.land/x/dax/mod.ts"; * * const commandBuilder = new CommandBuilder() * .cwd("./subDir") * .env("HTTPS_PROXY", "some_value"); * const requestBuilder = new RequestBuilder() * .header("SOME_VALUE", "value"); * * const new$ = $.build$({ * commandBuilder, * requestBuilder, * // optional additional functions to add to `$` * extras: { * add(a: number, b: number) { * return a + b; * }, * }, * }); * * // this command will use the env described above, but the main * // process and default `$` won't have its environment changed * await new$`deno run my_script.ts`; * * // similarly, this will have the headers that were set in the request builder * const data = await new$.request("https://plugins.dprint.dev/info.json").json(); * * // use the extra function we defined * console.log(new$.add(1, 2)); * ``` */ build$(options?: Create$Options): $Type & TNewExtras>; /** * Escapes an argument for the shell when NOT using the template * literal. * * This is done by default in the template literal, so you most likely * don't need this, but it may be useful when using the command builder. * * For example: * * ```ts * const builder = new CommandBuilder() * .command(`echo ${$.escapeArg("some text with spaces")}`); * * // equivalent to this: * const builder = new CommandBuilder() * .command(`echo 'some text with spaces'`); * * // you may just want to do this though: * const builder = new CommandBuilder() * .command(["echo", "some text with spaces"]); * ``` */ escapeArg(arg: string): string; /** Strips ANSI escape codes from a string */ stripAnsi(text: string): string; /** * De-indents (a.k.a. dedent/outdent) template literal strings * * Re-export of https://deno.land/x/outdent * * Removes the leading whitespace from each line, * allowing you to break the string into multiple * lines with indentation. If lines have an uneven * amount of indentation, then only the common * whitespace is removed. * * The opening and closing lines (which contain * the ` marks) must be on their own line. The * opening line must be empty, and the closing * line may contain whitespace. The opening and * closing line will be removed from the output, * so that only the content in between remains. */ dedent: Outdent; /** * Determines if the provided command exists resolving to `true` if the command * will be resolved by the shell of the current `$` or false otherwise. */ commandExists(commandName: string): Promise; /** * Determines if the provided command exists resolving to `true` if the command * will be resolved by the shell of the current `$` or false otherwise. */ commandExistsSync(commandName: string): boolean; /** Helper function for creating path references, which provide an easier way for * working with paths, directories, and files on the file system. * * The function creates a new `Path` from a path or URL string, file URL, or for the current module. */ path: typeof createPath; /** * Logs with potential indentation (`$.logIndent`) * and output of commands or request responses. * * Note: Everything is logged over stderr. */ log(...data: any[]): void; /** * Similar to `$.log`, but logs out the text lighter than usual. This * might be useful for logging out something that's unimportant. */ logLight(...data: any[]): void; /** * Similar to `$.log`, but will bold green the first word if one argument or * first argument if multiple arguments. */ logStep(firstArg: string, ...data: any[]): void; /** * Similar to `$.logStep`, but will use bold red. */ logError(firstArg: string, ...data: any[]): void; /** * Similar to `$.logStep`, but will use bold yellow. */ logWarn(firstArg: string, ...data: any[]): void; /** * Causes all `$.log` and like functions to be logged with indentation. * * ```ts * $.logGroup(() => { * $.log("This will be indented."); * $.logGroup(() => { * $.log("This will indented even more."); * }); * }); * * const result = await $.logGroup(async () => { * $.log("This will be indented."); * const value = await someAsyncWork(); * return value * 5; * }); * ``` * @param action - Action to run and potentially get the result for. */ logGroup(action: () => TResult): TResult; /** * Causes all `$.log` and like functions to be logged with indentation and a label. * * ```ts * $.logGroup("Some label", () => { * $.log("This will be indented."); * }); * ``` * @param label Title message to log for this level. * @param action Action to run and potentially get the result for. */ logGroup(label: string, action: () => TResult): TResult; /** * Causes all `$.log` and like functions to be logged with indentation. * * ```ts * $.logGroup(); * $.log("This will be indented."); * $.logGroup("Level 2"); * $.log("This will be indented even more."); * $.logGroupEnd(); * $.logGroupEnd(); * ``` * * Note: You must call `$.logGroupEnd()` when using this. * * It is recommended to use `$.logGroup(() => { ... })` over this one * as it will internally call `$.logGroupEnd()` even when exceptions * are thrown. * * @param label Optional title message to log for this level. */ logGroup(label?: string): void; /** * Ends a logging level. * * Meant to be used with `$.logGroup();` when not providing a function.. */ logGroupEnd(): void; /** Gets or sets the current log depth (0-indexed). */ logDepth: number; /** * Shows a prompt asking the user to answer a yes or no question. * * @returns `true` or `false` if the user made a selection or `undefined` if the user pressed ctrl+c. */ maybeConfirm(message: string, options?: Omit): Promise; /** * Shows a prompt asking the user to answer a yes or no question. * * @returns `true` or `false` if the user made a selection or `undefined` if the user pressed ctrl+c. */ maybeConfirm(options: ConfirmOptions): Promise; /** * Shows a prompt asking the user to answer a yes or no question. * * @returns `true` or `false` if the user made a selection or exits the process if the user pressed ctrl+c. */ confirm(message: string, options?: Omit): Promise; /** * Shows a prompt asking the user to answer a yes or no question. * * @returns `true` or `false` if the user made a selection or exits the process if the user pressed ctrl+c. */ confirm(options: ConfirmOptions): Promise; /** * Shows a prompt selection to the user where there is one possible answer. * * @returns Option index the user selected or `undefined` if the user pressed ctrl+c. */ maybeSelect(options: SelectOptions): Promise; /** * Shows a prompt selection to the user where there is one possible answer. * * @returns Option index the user selected or exits the process if the user pressed ctrl+c. */ select(options: SelectOptions): Promise; /** * Shows a prompt selection to the user where there are multiple or zero possible answers. * * @returns Array of selected indexes or `undefined` if the user pressed ctrl+c. */ maybeMultiSelect(options: MultiSelectOptions): Promise; /** * Shows a prompt selection to the user where there are multiple or zero possible answers. * * @returns Array of selected indexes or exits the process if the user pressed ctrl+c. */ multiSelect(options: MultiSelectOptions): Promise; /** * Shows an input prompt where the user can enter any text. * * @param message Message to show. * @param options Optional additional options. * @returns The inputted text or `undefined` if the user pressed ctrl+c. */ maybePrompt(message: string, options?: Omit): Promise; /** * Shows an input prompt where the user can enter any text. * * @param options Options for the prompt. * @returns The inputted text or `undefined` if the user pressed ctrl+c. */ maybePrompt(options: PromptOptions): Promise; /** * Shows an input prompt where the user can enter any text. * * @param message Message to show. * @param options Optional additional options. * @returns The inputted text or exits the process if the user pressed ctrl+c. */ prompt(message: string, options?: Omit): Promise; /** * Shows an input prompt where the user can enter any text. * * @param options Options for the prompt. * @returns The inputted text or exits the process if the user pressed ctrl+c. */ prompt(options: PromptOptions): Promise; /** Shows a progress message when indeterminate or bar when determinate. */ progress(message: string, options?: Omit): ProgressBar; /** Shows a progress message when indeterminate or bar when determinate. */ progress(options: ProgressOptions): ProgressBar; /** * Sets the logger used for info logging. * @default console.error */ setInfoLogger(logger: (...args: any[]) => void): void; /** * Sets the logger used for warn logging. * @default console.error */ setWarnLogger(logger: (...args: any[]) => void): void; /** * Sets the logger used for error logging. * @default console.error */ setErrorLogger(logger: (...args: any[]) => void): void; /** * Mutates the internal command builder to print the command text by * default before executing commands instead of needing to build a * custom `$`. * * For example: * * ```ts * $.setPrintCommand(true); * const text = "example"; * await $`echo ${text}`; * ``` * * Outputs: * * ``` * > echo example * example * ``` * * @param value - Whether this should be enabled or disabled. */ setPrintCommand(value: boolean): void; /** * Sleep for the provided delay. * * ```ts * await $.sleep(1000); // ms * await $.sleep("1.5s"); * await $.sleep("100ms"); * ``` */ sleep(delay: Delay): Promise; /** Symbols that can be attached to objects for better integration with Dax. */ symbols: typeof symbols; /** * Executes the command as raw text without escaping expressions. * * ```ts * const expr = "some text to echo"; * $.raw`echo {expr}`; // outputs: some text to echo * ``` * * @remarks Most likely you will want to escape arguments or provide * an array of arguments to the main `$` tagged template. For example: * * ```ts * const exprs = ["arg1", "arg two", "arg three"]; * await $`command ${exprs}`; * ``` */ raw(strings: TemplateStringsArray, ...exprs: TemplateExpr[]): CommandBuilder; /** * Prevents an argument being escaped. * * ```ts * import $ from "dax"; * * const value = "1 2 3"; * await $`echo ${value}`; // 1 2 3 * await $`echo ${$.rawArg(value)}`; // 1 2 3 * ``` */ rawArg(arg: T): RawArg; /** * Does the provided action until it succeeds (does not throw) * or the specified number of retries (`count`) is hit. */ withRetries(opts: RetryOptions): Promise; /** Re-export of `jsr:@david/which` for getting the path to an executable. */ which: Which; /** Similar to `which`, but synchronously. */ whichSync: WhichSync; } /** @internal */ type ExtrasObject = Record unknown>; /** Options for creating a custom `$`. */ export interface Create$Options { /** Uses the state of this command builder as a starting point or * provide a function to build off the current builder. */ commandBuilder?: CommandBuilder | ((builder: CommandBuilder) => CommandBuilder); /** Uses the state of this request builder as a starting point or * provide a function to build off the current builder. */ requestBuilder?: RequestBuilder | ((builder: RequestBuilder) => RequestBuilder); /** Extra properties to put on the `$`. */ extras?: TExtras; } /** * Builds a new `$` which will use the state of the provided * builders as the default. * * This can be useful if you want different default settings. * * Example: * * ```ts * import { build$ } from "https://deno.land/x/dax/mod.ts"; * * const commandBuilder = new CommandBuilder() * .cwd("./subDir") * .env("HTTPS_PROXY", "some_value"); * const requestBuilder = new RequestBuilder() * .header("SOME_VALUE", "value"); * * const $ = build$({ * commandBuilder, * requestBuilder, * // optional additional functions to add to `$` * extras: { * add(a: number, b: number) { * return a + b; * }, * }, * }); * * // this command will use the env described above, but the main * // process and default `$` won't have its environment changed * await $`deno run my_script.ts`; * * // similarly, this will have the headers that were set in the request builder * const data = await $.request("https://plugins.dprint.dev/info.json").json(); * * // use the extra function we defined * console.log($.add(1, 2)); * ``` */ export declare function build$(options?: Create$Options): $Type; /** * Default `$` instance where commands may be executed. */ export declare const $: $Type; export default $; /** @internal */ declare function createPath(path: string | URL | Path): Path; //# sourceMappingURL=mod.d.ts.map