← Back to archive

Repo of the Day

dawiidio/pli

Published: Apr 12, 2023

Open repository ↗

Create CLI for any project within a few minutes with Pli!

Summary

Pli is a TypeScript-based CLI scaffolder that generates files from templates with inline variables. It uses a $VARIABLE$ token syntax inside any file, file name, or directory name to collect user input interactively. Engineers define templates once and reuse them to spin up new files or folder structures with consistent naming and content.

What it is useful for

Pli is useful when a team repeatedly creates similar files and wants a guided, interactive command instead of copy-pasting. The README's React component example shows it generating a $NAME$/$NAME$.tsx file with a matching $NAME$.module.css under src/components, validating that the component name is at least three characters, and deriving a lowercase DIRNAME from NAME for the directory itself through a pipe transform. Beyond components, it can scaffold any boilerplate: config files, test suites, route modules, or service stubs. Nested templates let a parent scaffold spawn child templates via the entries option, which is useful when generating something like a feature module that needs a component, hook, and test file at once. outputMapping lets you rename or relocate generated files, so a child template's child.ts can become $PARENT_VAR$.ts under a different path. Variable names must contain only letters, numbers, and underscores, per the README, which constrains how filenames and directories can be parameterized.

How engineers can use it

Install globally (recommended by the README), locally, or run on demand via npx:

npm install -g @dawiidio/pli
# or
npx @dawiidio/pli

In a project directory, run pli init to drop a templates folder with a sample hello.js whose $NAME$ placeholder gets prompted at runtime. Run pli init -c to also produce a pli.config.ts; use -c -t js for a JavaScript config instead. After authoring templates, run pli (or pli run) to pick a template, fill variables, and choose an output directory. Useful flags include -d for a dry run that shows the result without writing files, -o to permit overwriting existing files, -l to set log verbosity (e.g., error, warn, info, debug), and -t to point at a non-default templates directory. Variable names are case-sensitive and may only contain letters, numbers, and underscores. Further configuration examples for scopes, pipes, and output mapping live in the examples folder linked from the README.