Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .agents/skills/recreate-terminal-demo/scripts/render-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ git check-attr binary -- "$gif_path" | grep -q 'binary: set' || {
}

test ! -e generated/version-info.ts || {
echo "Tape cleanup failed: generated/version-info.ts still exists" >&2
echo "Dry-run created generated/version-info.ts" >&2
exit 1
}

mkdir -p "$frames_dir"
for sample in "3:help" "7:generate" "11.5:result"; do
for sample in "3:help" "7:generate" "11:verbose" "17:dry-run"; do
timestamp="${sample%%:*}"
name="${sample#*:}"
docker run --rm --entrypoint ffmpeg -v "$repo_root:/vhs" "$vhs_image" \
Expand Down Expand Up @@ -81,4 +81,5 @@ printf 'SHA-256: %s\n' "$checksum"
printf 'Inspection frames:\n'
printf ' %s/help.png\n' "$frames_dir"
printf ' %s/generate.png\n' "$frames_dir"
printf ' %s/result.png\n' "$frames_dir"
printf ' %s/verbose.png\n' "$frames_dir"
printf ' %s/dry-run.png\n' "$frames_dir"
4 changes: 2 additions & 2 deletions .github/actions/report-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ runs:
with:
filename: ${{ inputs.coverage-file }}
badge: true
fail_below_min: false
fail_below_min: true
format: markdown
hide_branch_rate: true
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
thresholds: '95 100'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ npx package-version-info --output src/version-info.ts
```

```text
✅ Generated src/version-info.ts (v1.0.0, 2.00ms)
✓ Generated src/version-info.ts • v1.0.0 • 2.00 ms
```

### 3. Import it
Expand Down Expand Up @@ -107,7 +107,8 @@ npx package-version-info
| --- | --- | --- | --- |
| `--help` | `-h` | — | Display usage information. |
| `--version` | `-v` | — | Display the installed package version. |
| `--verbose` | — | Disabled | Display detailed generation progress. |
| `--verbose` | — | Disabled | Display a detailed generation summary. |
| `--dry-run` | — | Disabled | Print TypeScript without creating a file. |
| `--input <path>` | `-i` | `package.json` | Input package file. |
| `--output <path>` | `-o` | `version-info.ts` | Generated TypeScript file. |
| `--git <path>` | `-g` | `.git` | Git directory or pointer file used for branch and commit metadata. |
Expand All @@ -124,6 +125,12 @@ npx package-version-info
# Show detailed progress
npx package-version-info --verbose

# Preview generated TypeScript without creating a file
npx package-version-info --dry-run

# Pipe the preview to another command
npx package-version-info --dry-run | less

# Use custom paths
npx package-version-info \
--input package.json \
Expand All @@ -142,7 +149,7 @@ npx package-version-info \
Compact mode is designed for normal builds:

```text
✅ Generated src/version-info.ts (v1.0.0, 2.00ms)
✓ Generated src/version-info.ts • v1.0.0 • 2.00 ms
```

Use verbose mode when diagnosing package, author, timestamp, Git, or output-path behavior:
Expand All @@ -151,6 +158,27 @@ Use verbose mode when diagnosing package, author, timestamp, Git, or output-path
npx package-version-info --verbose
```

```text
› Package package.json • v1.0.0
› Author Dominik Hladík • dominik.hladik@seznam.cz • https://github.com/Celtian
› Timestamp 2026-07-16T18:53:01.908Z
› Git main • 8be6ca60256cc90e0a41d40b9ee222165f239444
✓ Generated version-info.ts • v1.0.0 • 2.00 ms
```

### Dry-run preview

Use `--dry-run` to print the generated TypeScript to stdout without creating the configured output
file or its parent directories:

```bash
npx package-version-info --dry-run
```

The stdout stream contains only TypeScript, with no colors or status text, so it can be redirected
or piped directly. Combining `--verbose` with `--dry-run` keeps the TypeScript on stdout and writes
the colored diagnostic summary to stderr, ending with `✓ Previewed`.

## 🛠️ Build-tool integration

Generate version information automatically before your application build:
Expand Down
Binary file modified docs/assets/terminal-demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions docs/terminal-demo.tape
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Output docs/assets/terminal-demo.gif

Set Shell bash
Set Width 1200
Set Height 720
Set Width 1280
Set Height 640
Set FontSize 20
Set TypingSpeed 25ms
Set Framerate 24
Expand Down Expand Up @@ -41,10 +41,22 @@ Sleep 2s
Ctrl+L
Sleep 500ms

Type "sed -n '1,22p' generated/version-info.ts"
Type "package-version-info --verbose --output generated/version-info.ts"
Enter
Sleep 3s

Hide
Type "rm -f generated/version-info.ts"
Enter
Show

Ctrl+L
Sleep 500ms

Type "package-version-info --dry-run"
Enter
Sleep 4s

Hide
Type "rm -f generated/version-info.ts /tmp/pvi-demo-bin/package-version-info"
Type "rm -f /tmp/pvi-demo-bin/package-version-info"
Enter
13 changes: 12 additions & 1 deletion scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ kcov \
"$coverage_dir/root" \
"$coverage_dir/cli"

coverage_xml="$coverage_dir/merged/kcov-merged/cobertura.xml"

sed -i \
's/ branch-rate="[^"]*" branches-covered="[^"]*" branches-rate="[^"]*"/ branch-rate="0" branches-covered="0" branches-valid="0"/' \
"$coverage_dir/merged/kcov-merged/cobertura.xml"
"$coverage_xml"

line_rate=$(sed -n 's/^<coverage line-rate="\([^"]*\)".*/\1/p' "$coverage_xml")
test -n "$line_rate"

awk -v line_rate="$line_rate" 'BEGIN {
minimum = 0.95
printf "Line coverage: %.2f%% (minimum: %.2f%%)\n", line_rate * 100, minimum * 100
if (line_rate < minimum) exit 1
}'
16 changes: 13 additions & 3 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub const GenerateOptions = struct {
output_path: []const u8 = "version-info.ts",
git_path: []const u8 = ".git",
verbose: bool = false,
dry_run: bool = false,
};

pub const InvalidArgument = union(enum) {
Expand All @@ -37,6 +38,8 @@ pub fn parse(args: anytype) Action {
return .version;
} else if (std.mem.eql(u8, arg, "--verbose")) {
options.verbose = true;
} else if (std.mem.eql(u8, arg, "--dry-run")) {
options.dry_run = true;
} else if (std.mem.eql(u8, arg, "--input") or std.mem.eql(u8, arg, "-i")) {
const value = args.next() orelse return .{ .invalid = .{ .missing_value = arg } };
if (std.mem.startsWith(u8, value, "-")) return .{ .invalid = .{ .missing_value = arg } };
Expand Down Expand Up @@ -68,7 +71,9 @@ pub fn writeHelp(writer: anytype) !void {
"\n " ++ color.green ++ "-v, --version" ++ color.reset ++
" Display current version." ++
"\n " ++ color.green ++ "--verbose" ++ color.reset ++
" Display detailed generation progress." ++
" Display detailed generation summary." ++
"\n " ++ color.green ++ "--dry-run" ++ color.reset ++
" Print TypeScript without creating a file." ++
"\n " ++ color.green ++ "-i, --input <path>" ++ color.reset ++
" Input package.json (default: package.json)." ++
"\n " ++ color.green ++ "-o, --output <path>" ++ color.reset ++
Expand Down Expand Up @@ -114,6 +119,7 @@ test "no arguments generate with default paths" {
try std.testing.expectEqualStrings("version-info.ts", options.output_path);
try std.testing.expectEqualStrings(".git", options.git_path);
try std.testing.expect(!options.verbose);
try std.testing.expect(!options.dry_run);
}

test "help flags show help" {
Expand All @@ -129,6 +135,7 @@ test "version flags show version" {
test "generation options are parsed" {
const action = parseTest(&.{
"--verbose",
"--dry-run",
"--input",
"input.json",
"-o",
Expand All @@ -141,11 +148,13 @@ test "generation options are parsed" {
try std.testing.expectEqualStrings("generated/info.ts", options.output_path);
try std.testing.expectEqualStrings("../.git", options.git_path);
try std.testing.expect(options.verbose);
try std.testing.expect(options.dry_run);
}

test "verbose enables detailed generation progress" {
const options = parseTest(&.{"--verbose"}).generate;
test "verbose dry run enables a detailed preview" {
const options = parseTest(&.{ "--verbose", "--dry-run" }).generate;
try std.testing.expect(options.verbose);
try std.testing.expect(options.dry_run);
try std.testing.expectEqualStrings("package.json", options.input_path);
}

Expand Down Expand Up @@ -181,4 +190,5 @@ test "help contains usage commands and options" {
try std.testing.expect(std.mem.indexOf(u8, help, " generate") == null);
try std.testing.expect(std.mem.indexOf(u8, help, "--help") != null);
try std.testing.expect(std.mem.indexOf(u8, help, "--verbose") != null);
try std.testing.expect(std.mem.indexOf(u8, help, "--dry-run") != null);
}
7 changes: 5 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ pub fn main(init: std.process.Init) !void {
std.process.exit(2);
},
.generate => |options| {
if (options.verbose) {
if (options.verbose or options.dry_run) {
try version_info.generateVersionInfoWithOptions(
init.gpa,
init.io,
options.input_path,
options.output_path,
options.git_path,
.{ .verbose = true },
.{
.verbose = options.verbose,
.dry_run = options.dry_run,
},
);
} else {
try version_info.generateVersionInfo(
Expand Down
Loading
Loading