The following file(s) aim to display a pattern of node script development.
In this pattern the CLI program is built to execute the standalone node script.
- It is a common pattern to write a script.
- It is a common pattern to write a CLI program to run a script.
- I want to easily write CLI programs to execute a node script
- I want that CLI program to be easily unit tested based on its options, not the script it runs! 🎉
Directory structure of the script
flowchart LR
A(src/);
A --> B(program.ts: cli script runner);
A --> C(script.ts: node script);
A --> D(tests/);
D --> E(program.test.ts: tests program);
D --> F(script.test.ts: tests script);
Options to execute the script
flowchart LR
A(node script);
A --> B(execute script via CLI);
A --> C(execute script via LAMBDA Handler);
A --> D(execute script in other node application);
The charts aboves diagrams a node script which works on it's own but can be executed in multiple formats.
The example-program.ts
file below displays how the CLI portion of Developer Ergonomics (Ref 2nd diagram) can execute the script and provide options to easily unit test it.
See stdoutToJSON for more detail.