Commit 65eba95
breaking! feat: add CLI interface for format-css package (#170)
## Summary
This PR adds a command-line interface (CLI) to the format-css package,
allowing users to format CSS files directly from the terminal.
## Key Changes
- **New CLI module** (`src/cli/cli.ts`): Implements a complete
command-line interface with support for:
- Formatting CSS files passed as arguments
- Reading CSS from stdin for pipe operations
- `--minify` flag to minify CSS output
- `--tab-size=<n>` option to customize indentation
- `--help` / `-h` flag with formatted usage documentation
- Proper error handling and exit codes
- **Build configuration** (`tsdown.config.ts`): Updated to build both
the library and CLI:
- Converted from single entry point to multi-entry configuration
- Added separate build target for CLI with Node.js platform
- Configured CLI to reference the main package as external to avoid
duplication
- **Package metadata** (`package.json`): Added `bin` field to register
the `format-css` command, making it available as an executable when
installed globally or locally
## Implementation Details
- The CLI intelligently detects input source: file arguments, stdin
pipe, or displays help if neither is provided
- Uses Node.js built-in utilities (`parseArgs`, `styleText`) for
argument parsing and formatted output
- Validates `--tab-size` parameter to ensure it's a positive integer
- Properly handles async stdin reading for piped input
- Includes comprehensive help text with usage examples
https://claude.ai/code/session_01QXPADk12xcj6p5nGFNJHsh
Breaking because the supported node version went from >=18.0.0 to
>=20.12.0
closes #123
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9be1afb commit 65eba95
18 files changed
Lines changed: 389 additions & 345 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
82 | | - | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
94 | 124 | | |
95 | 125 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
0 commit comments