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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ npx package-version-info --output src/version-info.ts
```

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

### 3. Import it
Expand Down Expand Up @@ -135,7 +135,7 @@ npx package-version-info \
Compact mode is designed for normal builds:

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

Use verbose mode when diagnosing package, author, timestamp, Git, or output-path behavior:
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.
13 changes: 7 additions & 6 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const std = @import("std");

const embedded_package_json = @embedFile("package.json");
const compact_summary_format = "✅ Generated {s} (v{s}, {d}ms)";
const compact_summary_format = "✅ Generated {s} (v{s}, {d:.2}ms)";

const color = struct {
const reset = "\x1b[0m";
Expand All @@ -23,11 +23,11 @@ fn logNewLine() void {
std.debug.print("\n", .{});
}

fn writeCompactSummary(writer: anytype, output_path: []const u8, version: []const u8, duration_ms: i64) !void {
fn writeCompactSummary(writer: anytype, output_path: []const u8, version: []const u8, duration_ms: f64) !void {
try writer.print(compact_summary_format, .{ output_path, version, duration_ms });
}

fn logCompactSummary(output_path: []const u8, version: []const u8, duration_ms: i64) void {
fn logCompactSummary(output_path: []const u8, version: []const u8, duration_ms: f64) void {
std.debug.print("{s}" ++ compact_summary_format ++ "{s}\n", .{
color.bright_green,
output_path,
Expand Down Expand Up @@ -300,11 +300,12 @@ pub fn generateVersionInfoWithOptions(
try writer.flush();

const end_time = std.Io.Clock.awake.now(io);
const duration_ms = start_time.durationTo(end_time).toMilliseconds();
const duration_ns = start_time.durationTo(end_time).toNanoseconds();
const duration_ms = @as(f64, @floatFromInt(duration_ns)) / std.time.ns_per_ms;
if (options.verbose) {
log(color.bright_green, "✅", "Successfully generated {s}", .{output_path});
logNewLine();
log(color.yellow, "⏱️ ", "Duration: {d}ms", .{duration_ms});
log(color.yellow, "⏱️ ", "Duration: {d:.2}ms", .{duration_ms});
logNewLine();
} else {
logCompactSummary(output_path, version, duration_ms);
Expand Down Expand Up @@ -348,7 +349,7 @@ test "writes compact generation summary" {

try writeCompactSummary(&output.writer, "generated/version-info.ts", "0.0.0", 2);
try std.testing.expectEqualStrings(
"✅ Generated generated/version-info.ts (v0.0.0, 2ms)",
"✅ Generated generated/version-info.ts (v0.0.0, 2.00ms)",
output.writer.buffered(),
);
}
Expand Down
Loading