A fluent API for building command pipelines in TypeScript, inspired by the Go version of Corm.
- Fluent API: Chain commands with intuitive method calls
- Multiple Operators: Support for pipe (
|), and (&), and-and (&&), or-or (||), and semicolon (;) - Type Safety: Full TypeScript support with type checking
- Extensible: Easy to create custom command implementations
- Async/Await: Modern Promise-based execution
npm install cormimport { Pipeline, pipe, cmd, go, sudo } from 'corm';
// Builder pattern
const pipeline1 = Pipeline.new()
.add(cmd('echo', 'hello'))
.pipe(cmd('grep', 'h'))
.andAnd(cmd('echo', 'success'));
console.log(pipeline1.toString());
// Output: echo hello | grep h && echo success
// Functional pattern
const pipeline2 = pipe(
cmd('echo', 'hello'),
cmd('grep', 'h'),
cmd('wc', '-l')
);
console.log(pipeline2.toString());
// Output: echo hello | grep h | wc -lThe main class for building command pipelines.
add(cmd: Command): Add a command to the pipelinepipe(cmd: Command): Pipe output to the next command (|)and(cmd: Command): Run command in background (&)andAnd(cmd: Command): Run command only if previous succeeded (&&)orOr(cmd: Command): Run command only if previous failed (||)semicolon(cmd: Command): Run command sequentially (;)toString(): Get string representationrun(): Execute the pipelineoutput(): Execute and return output
Pipeline.new(): Create a new pipeline instance
pipe(...cmds): Create pipeline with pipe operatorsand(...cmds): Create pipeline with and operatorsandAnd(...cmds): Create pipeline with and-and operatorsorOr(...cmds): Create pipeline with or-or operatorssemicolon(...cmds): Create pipeline with semicolon operators
import { cmd } from 'corm';
const command = cmd('echo', 'hello', 'world');
console.log(command.toString()); // echo hello worldimport { go } from 'corm';
const testCmd = go()
.test('./...')
.coverprofile('coverage.out')
.covermode('atomic');
console.log(testCmd.toString());
// go test -coverprofile=coverage.out -covermode=atomic ./...import { sudo, cmd } from 'corm';
const sudoCmd = sudo(cmd('echo', 'hello'))
.shell()
.interactive();
console.log(sudoCmd.toString());
// sudo -i -s echo helloimport { Pipeline, sudo, go, cmd } from 'corm';
const pipeline = Pipeline.new()
.add(sudo(go().test('./...').coverprofile('coverage.out')).shell())
.pipe(cmd('grep', 'PASS'))
.andAnd(cmd('echo', 'All tests passed'))
.orOr(cmd('echo', 'Some tests failed'));
console.log(pipeline.toString());
// sudo -s go test -coverprofile=coverage.out ./... | grep PASS && echo All tests passed || echo Some tests failedimport { pipe, andAnd, orOr, cmd } from 'corm';
const pipeline = pipe(
cmd('npm', 'test'),
cmd('grep', 'PASS')
).andAnd(
cmd('echo', 'Tests passed')
).orOr(
cmd('echo', 'Tests failed')
);import { BaseCommand } from 'corm';
class DockerCommand extends BaseCommand {
private image: string;
private args: string[] = [];
constructor(image: string) {
super();
this.image = image;
}
name(): string {
return 'docker';
}
run(command: string): DockerCommand {
this.args.push('run', this.image, command);
return this;
}
toString(): string {
return `docker ${this.args.join(' ')}`;
}
}
const dockerCmd = new DockerCommand('node:18').run('npm test');
console.log(dockerCmd.toString()); // docker run node:18 npm testnpm run buildnpm testnpm run devMIT