UNPKG

4.39 kBTypeScriptView Raw
1/// <reference types="node" />
2import execa from 'execa';
3import { WatchDirOptions } from './fs';
4import { ChildProcess } from 'child_process';
5export { execa };
6export declare function exec(command: string, options?: execa.Options): execa.ExecaChildProcess;
7export declare function exec(commands: string[], options?: execa.Options): Promise<execa.ExecaSyncReturnValue<string>[]>;
8export declare const spawn: {
9 (file: string, arguments?: readonly string[] | undefined, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
10 (file: string, arguments?: readonly string[] | undefined, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
11 (file: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
12 (file: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
13 sync(file: string, arguments?: readonly string[] | undefined, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
14 sync(file: string, arguments?: readonly string[] | undefined, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
15 sync(file: string, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
16 sync(file: string, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
17 command(command: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
18 command(command: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
19 commandSync(command: string, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
20 commandSync(command: string, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
21 node(scriptPath: string, arguments?: readonly string[] | undefined, options?: execa.NodeOptions<string> | undefined): execa.ExecaChildProcess<string>;
22 node(scriptPath: string, arguments?: readonly string[] | undefined, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
23 node(scriptPath: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
24 node(scriptPath: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
25};
26export declare class ShellContext {
27 private _cwdStack;
28 private _env;
29 logCommand: boolean;
30 sleep: (ms: number) => Promise<void>;
31 /**
32 * get current word directory
33 */
34 get cwd(): string;
35 protected _logger: import("./logger").Logger;
36 private readonly _process;
37 /**
38 * change work directory
39 * @param dir
40 */
41 cd(dir: string): this;
42 /**
43 * like pushd in shell
44 * @param dir
45 */
46 pushd(dir: string): this;
47 /**
48 * like popd in shell
49 */
50 popd(): this;
51 /**
52 * execute command(s)
53 * @param command
54 * @param options
55 */
56 exec(command: string, options?: execa.Options): execa.ExecaChildProcess;
57 exec(commands: string[], options?: execa.Options): Promise<execa.ExecaSyncReturnValue[]>;
58 /**
59 * spawn file
60 * @param file
61 * @param args
62 * @param options
63 */
64 spawn(file: string, args?: string[], options?: execa.Options): execa.ExecaChildProcess;
65 /**
66 * set/get/delete env
67 * set: ctx.env('key', 'val')
68 * get: ctx.env('key')
69 * delete: ctx.env('key', void 0)
70 * @param key
71 */
72 env(key: string): string | undefined;
73 env(key: string, val: string | undefined): this;
74 /**
75 * restart processes when file changes
76 * @example
77 * ctx.monitor('./src', 'tsc')
78 * ctx.monitor('./src', 'webpack')
79 * ctx.monitor('./src', 'foy watch')
80 * ctx.monitor('./src', ['rm -rf dist', 'foy watch'])
81 * ctx.monitor('./src', async p => {
82 * await fs.rmrf('dist')
83 * p.current = ctx.exec('webpack serve')
84 * })
85 */
86 monitor(dir: string, run: ((p: {
87 current: ChildProcess | null;
88 }) => void) | string | string[], options?: WatchDirOptions & {
89 ignore?: (event: string, file: string) => boolean;
90 }): void;
91 /**
92 * reset env to default
93 */
94 resetEnv(): this;
95 private _logCmd;
96}
97export declare function shell(callback: (ctx: ShellContext) => Promise<any>): Promise<any>;