Skip to content

Commit

Permalink
modify cli options and API in README
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarektouati committed Oct 1, 2023
1 parent a61ef39 commit 84a7f25
Show file tree
Hide file tree
Showing 10 changed files with 522 additions and 350 deletions.
575 changes: 345 additions & 230 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"scripts": {
"build": "tsc --build",
"postbuild": "chmod +x dist/bin/concurrently.js",
"generate:doc:api": "ts-readme --header-depth 3 src/concurrently.ts ",
"clean": "tsc --build --clean",
"format": "prettier --check '**/*.{json,y?(a)ml,md}'",
"format:fix": "pnpm run format --write",
Expand Down Expand Up @@ -88,6 +89,7 @@
"prettier": "^3.0.3",
"safe-publish-latest": "^2.0.0",
"string-argv": "^0.3.2",
"ts-readme": "^1.1.3",
"typescript": "~5.2.2"
},
"files": [
Expand Down
137 changes: 135 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 16 additions & 48 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,39 @@ import { ChildProcess as BaseChildProcess, SpawnOptions } from 'child_process';
import * as Rx from 'rxjs';
import { EventEmitter, Writable } from 'stream';

/**
* Identifier for a command; if string, it's the command's name, if number, it's the index.
*/
/** Identifier for a command; if string, it's the command's name, if number, it's the index.*/
export type CommandIdentifier = string | number;

export interface CommandInfo {
/**
* Command's name.
*/
/** Command's name. */
name: string;

/**
* Which command line the command has.
*/
/** Which command line the command has. */
command: string;

/**
* Which environment variables should the spawned process have.
*/
/** Which environment variables should the spawned process have.*/
env?: Record<string, unknown>;

/**
* The current working directory of the process when spawned.
*/
/** The current working directory of the process when spawned.*/
cwd?: string;

/**
* Color to use on prefix of the command.
*/
/** Color to use on prefix of the command.*/
prefixColor?: string;

/**
* Output command in raw format.
*/
/** Output command in raw format.*/
raw?: boolean;
}

export interface CloseEvent {
command: CommandInfo;

/**
* The command's index among all commands ran.
*/
/** The command's index among all commands ran.*/
index: number;

/**
* Whether the command exited because it was killed.
*/
/** Whether the command exited because it was killed.*/
killed: boolean;

/**
* The exit code or signal for the command.
*/
/** The exit code or signal for the command.*/
exitCode: string | number;
timings: {
startDate: Date;
Expand All @@ -68,20 +48,14 @@ export interface TimerEvent {
endDate?: Date;
}

/**
* Subtype of NodeJS's child_process including only what's actually needed for a command to work.
*/
/** Subtype of NodeJS's child_process including only what's actually needed for a command to work. */
export type ChildProcess = EventEmitter &
Pick<BaseChildProcess, 'pid' | 'stdin' | 'stdout' | 'stderr'>;

/**
* Interface for a function that must kill the process with `pid`, optionally sending `signal` to it.
*/
/** Interface for a function that must kill the process with `pid`, optionally sending `signal` to it. */
export type KillProcess = (pid: number, signal?: string) => void;

/**
* Interface for a function that spawns a command and returns its child process instance.
*/
/** Interface for a function that spawns a command and returns its child process instance. */
export type SpawnCommand = (command: string, options: SpawnOptions) => ChildProcess;

export class Command implements CommandInfo {
Expand Down Expand Up @@ -139,9 +113,7 @@ export class Command implements CommandInfo {
this.spawnOpts = spawnOpts;
}

/**
* Starts this command, piping output, error and close events onto the corresponding observables.
*/
/** Starts this command, piping output, error and close events onto the corresponding observables. */
start() {
const child = this.spawn(this.command, this.spawnOpts);
this.process = child;
Expand Down Expand Up @@ -190,9 +162,7 @@ export class Command implements CommandInfo {
this.stdin = child.stdin || undefined;
}

/**
* Kills this command, optionally specifying a signal to send to it.
*/
/** Kills this command, optionally specifying a signal to send to it. */
kill(code?: string) {
if (Command.canKill(this)) {
this.killed = true;
Expand All @@ -210,9 +180,7 @@ export class Command implements CommandInfo {
}
}

/**
* Pipes all events emitted by `stream` into `subject`.
*/
/** Pipes all events emitted by `stream` into `subject`.s */
function pipeTo<T>(stream: Rx.Observable<T>, subject: Rx.Subject<T>) {
stream.subscribe((event) => subject.next(event));
}
Loading

0 comments on commit 84a7f25

Please sign in to comment.