@richhaase/c2 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/report.ts +16 -12
- package/src/index.ts +9 -0
package/package.json
CHANGED
package/src/commands/report.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { writeFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
1
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
3
4
|
import type { Command } from "commander";
|
|
4
5
|
import { loadConfig } from "../config.ts";
|
|
5
6
|
import { formatMeters } from "../display.ts";
|
|
@@ -385,10 +386,6 @@ function buildProjection(goal: GoalProgress, workouts: Workout[]): string {
|
|
|
385
386
|
</div>
|
|
386
387
|
</div>
|
|
387
388
|
</div>
|
|
388
|
-
<div style="margin-top: 16px; padding: 12px; background: #21262d; border-radius: 6px; font-size: 13px; line-height: 1.8;">
|
|
389
|
-
<strong style="color: #f0f6fc;">The path forward:</strong>
|
|
390
|
-
${sessionsPerWeek} sessions/week at ${formatMeters(avgSessionDist)}m avg = ${formatMeters(Math.round(parseFloat(sessionsPerWeek as string) * avgSessionDist))}m/week.
|
|
391
|
-
</div>
|
|
392
389
|
</div>`;
|
|
393
390
|
}
|
|
394
391
|
|
|
@@ -661,11 +658,11 @@ ${buildProjection(goal, allWorkouts)}
|
|
|
661
658
|
export function registerReport(program: Command): void {
|
|
662
659
|
program
|
|
663
660
|
.command("report")
|
|
664
|
-
.description("Generate HTML progress report")
|
|
665
|
-
.option("-o, --output <file>", "
|
|
661
|
+
.description("Generate HTML progress report and open in browser")
|
|
662
|
+
.option("-o, --output <file>", "save to a specific file instead of a temp file")
|
|
666
663
|
.option("-w, --weeks <n>", "weeks of history to show", "12")
|
|
667
|
-
.option("--open", "open
|
|
668
|
-
.action(async (opts: { output
|
|
664
|
+
.option("--no-open", "don't open in browser")
|
|
665
|
+
.action(async (opts: { output?: string; weeks: string; open: boolean }) => {
|
|
669
666
|
const cfg = await loadConfig();
|
|
670
667
|
if (!cfg.goal.start_date || !cfg.goal.end_date) {
|
|
671
668
|
console.error("Goal dates not configured. Run `c2 setup` to set start and end dates.");
|
|
@@ -687,9 +684,14 @@ export function registerReport(program: Command): void {
|
|
|
687
684
|
const summaries = buildWeekSummaries(workouts, new Date(), weeks);
|
|
688
685
|
const html = buildHTML(goal, summaries, workouts, 10);
|
|
689
686
|
|
|
690
|
-
|
|
687
|
+
let outPath: string;
|
|
688
|
+
if (opts.output) {
|
|
689
|
+
outPath = resolve(opts.output);
|
|
690
|
+
} else {
|
|
691
|
+
const dir = await mkdtemp(join(tmpdir(), "c2-report-"));
|
|
692
|
+
outPath = join(dir, "report.html");
|
|
693
|
+
}
|
|
691
694
|
await writeFile(outPath, html, "utf-8");
|
|
692
|
-
console.log(`Report written to: ${outPath}`);
|
|
693
695
|
|
|
694
696
|
if (opts.open) {
|
|
695
697
|
const { spawn } = await import("node:child_process");
|
|
@@ -704,6 +706,8 @@ export function registerReport(program: Command): void {
|
|
|
704
706
|
console.error(`Could not open report: ${err.message}`);
|
|
705
707
|
});
|
|
706
708
|
child.unref();
|
|
709
|
+
} else {
|
|
710
|
+
console.log(`Report written to: ${outPath}`);
|
|
707
711
|
}
|
|
708
712
|
});
|
|
709
713
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,15 @@ registerTrend(program);
|
|
|
23
23
|
registerExport(program);
|
|
24
24
|
registerReport(program);
|
|
25
25
|
|
|
26
|
+
// Default to `report` when run with no subcommand
|
|
27
|
+
const args = process.argv.slice(2);
|
|
28
|
+
const knownCommands = program.commands.map((c) => c.name());
|
|
29
|
+
const hasSubcommand = args.some((a) => knownCommands.includes(a));
|
|
30
|
+
const hasHelpOrVersion = args.some((a) => ["-h", "--help", "-v", "--version"].includes(a));
|
|
31
|
+
if (args.length === 0 || (!hasSubcommand && !hasHelpOrVersion)) {
|
|
32
|
+
process.argv.splice(2, 0, "report");
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
program.parseAsync(process.argv).catch((err: Error) => {
|
|
27
36
|
console.error(`Error: ${err.message}`);
|
|
28
37
|
process.exit(1);
|