git-shots-cli 0.1.0 → 0.1.1

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/dist/index.js CHANGED
@@ -157,6 +157,65 @@ async function status(config) {
157
157
  }
158
158
  }
159
159
 
160
+ // src/pull-baselines.ts
161
+ import { mkdirSync, writeFileSync } from "fs";
162
+ import { resolve as resolve3, dirname as dirname2 } from "path";
163
+ import chalk4 from "chalk";
164
+ async function pullBaselines(config, options) {
165
+ const branch = options.branch ?? "main";
166
+ const outputDir = resolve3(process.cwd(), options.output ?? config.directory);
167
+ console.log(chalk4.dim(`Project: ${config.project}`));
168
+ console.log(chalk4.dim(`Branch: ${branch}`));
169
+ console.log(chalk4.dim(`Output: ${outputDir}`));
170
+ console.log();
171
+ const manifestUrl = `${config.server}/api/projects/${encodeURIComponent(config.project)}/snapshots?branch=${encodeURIComponent(branch)}`;
172
+ let snapshots;
173
+ try {
174
+ const res = await fetch(manifestUrl);
175
+ const data = await res.json();
176
+ if (!res.ok) {
177
+ console.error(chalk4.red(`Failed to fetch snapshots: ${JSON.stringify(data)}`));
178
+ process.exit(1);
179
+ }
180
+ snapshots = data.snapshots;
181
+ } catch (err) {
182
+ console.error(chalk4.red(`Request failed: ${err}`));
183
+ process.exit(1);
184
+ }
185
+ if (snapshots.length === 0) {
186
+ console.log(chalk4.yellow("No baseline snapshots found."));
187
+ return;
188
+ }
189
+ console.log(chalk4.dim(`Found ${snapshots.length} baselines to download`));
190
+ console.log();
191
+ const batchSize = 5;
192
+ let downloaded = 0;
193
+ for (let i = 0; i < snapshots.length; i += batchSize) {
194
+ const batch = snapshots.slice(i, i + batchSize);
195
+ await Promise.all(
196
+ batch.map(async (snap) => {
197
+ const imageUrl = `${config.server}/api/images/${snap.r2_key}`;
198
+ const res = await fetch(imageUrl);
199
+ if (!res.ok) {
200
+ console.error(chalk4.red(` Failed to download ${snap.screen_slug}: ${res.status}`));
201
+ return;
202
+ }
203
+ const buffer = Buffer.from(await res.arrayBuffer());
204
+ const subDir = snap.category ?? "";
205
+ const filePath = resolve3(outputDir, subDir, `${snap.screen_slug}.png`);
206
+ mkdirSync(dirname2(filePath), { recursive: true });
207
+ writeFileSync(filePath, buffer);
208
+ downloaded++;
209
+ console.log(
210
+ chalk4.green(` [${downloaded}/${snapshots.length}]`) + ` ${subDir ? subDir + "/" : ""}${snap.screen_slug}.png`
211
+ );
212
+ })
213
+ );
214
+ }
215
+ console.log();
216
+ console.log(chalk4.green(`Downloaded ${downloaded} baselines to ${outputDir}`));
217
+ }
218
+
160
219
  // src/index.ts
161
220
  var program = new Command();
162
221
  program.name("git-shots").description("CLI for git-shots visual regression platform").version("0.1.0");
@@ -191,4 +250,14 @@ program.command("status").description("Show current diff status").option("-p, --
191
250
  }
192
251
  await status(config);
193
252
  });
253
+ program.command("pull-baselines").description("Download baseline screenshots from git-shots").option("-p, --project <slug>", "Project slug").option("-s, --server <url>", "Server URL").option("-o, --output <path>", "Output directory").option("-b, --branch <name>", "Branch to pull baselines from (default: main)").action(async (options) => {
254
+ const config = loadConfig();
255
+ if (options.project) config.project = options.project;
256
+ if (options.server) config.server = options.server;
257
+ if (!config.project) {
258
+ console.error("Error: project slug required. Use --project or .git-shots.json");
259
+ process.exit(1);
260
+ }
261
+ await pullBaselines(config, { branch: options.branch, output: options.output });
262
+ });
194
263
  program.parse();
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
- {
2
- "name": "git-shots-cli",
3
- "version": "0.1.0",
4
- "description": "CLI for git-shots visual regression platform",
5
- "type": "module",
6
- "bin": {
7
- "git-shots": "dist/index.js"
8
- },
9
- "scripts": {
10
- "build": "tsup src/index.ts --format esm --dts",
11
- "dev": "tsup src/index.ts --format esm --watch"
12
- },
13
- "dependencies": {
14
- "commander": "^12.0.0",
15
- "chalk": "^5.3.0",
16
- "glob": "^11.0.0"
17
- },
18
- "devDependencies": {
19
- "tsup": "^8.0.0",
20
- "typescript": "^5.0.0",
21
- "@types/node": "^22.0.0"
22
- }
23
- }
1
+ {
2
+ "name": "git-shots-cli",
3
+ "version": "0.1.1",
4
+ "description": "CLI for git-shots visual regression platform",
5
+ "type": "module",
6
+ "bin": {
7
+ "git-shots": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsup src/index.ts --format esm --dts",
11
+ "dev": "tsup src/index.ts --format esm --watch"
12
+ },
13
+ "dependencies": {
14
+ "commander": "^12.0.0",
15
+ "chalk": "^5.3.0",
16
+ "glob": "^11.0.0"
17
+ },
18
+ "devDependencies": {
19
+ "tsup": "^8.0.0",
20
+ "typescript": "^5.0.0",
21
+ "@types/node": "^22.0.0"
22
+ }
23
+ }
package/src/compare.ts CHANGED
@@ -1,57 +1,57 @@
1
- import chalk from 'chalk';
2
- import type { GitShotsConfig } from './config.js';
3
-
4
- export async function compare(
5
- config: GitShotsConfig,
6
- options: { base?: string; head: string; threshold?: number }
7
- ) {
8
- const url = `${config.server}/api/compare`;
9
- const body = {
10
- project: config.project,
11
- base: options.base ?? 'main',
12
- head: options.head,
13
- threshold: options.threshold ?? 0.1
14
- };
15
-
16
- console.log(chalk.dim(`Comparing ${body.base} vs ${body.head} for ${config.project}...`));
17
-
18
- try {
19
- const res = await fetch(url, {
20
- method: 'POST',
21
- headers: { 'Content-Type': 'application/json', Origin: config.server },
22
- body: JSON.stringify(body)
23
- });
24
- const data = await res.json();
25
-
26
- if (!res.ok) {
27
- console.error(chalk.red(`Compare failed: ${JSON.stringify(data)}`));
28
- process.exit(1);
29
- }
30
-
31
- console.log();
32
- console.log(`Compared ${chalk.bold(data.compared)} screens`);
33
- console.log();
34
-
35
- if (data.diffs.length === 0) {
36
- console.log(chalk.green('No visual differences found!'));
37
- return;
38
- }
39
-
40
- // Print table
41
- console.log(chalk.dim('Screen'.padEnd(30) + 'Mismatch'.padEnd(15) + 'Pixels'));
42
- console.log(chalk.dim('-'.repeat(55)));
43
-
44
- for (const d of data.diffs) {
45
- const pct = d.mismatchPercentage.toFixed(2) + '%';
46
- const color = d.mismatchPercentage > 10 ? chalk.red : d.mismatchPercentage > 1 ? chalk.yellow : chalk.green;
47
- console.log(
48
- d.screen.padEnd(30) +
49
- color(pct.padEnd(15)) +
50
- chalk.dim(d.mismatchPixels.toLocaleString())
51
- );
52
- }
53
- } catch (err) {
54
- console.error(chalk.red(`Request failed: ${err}`));
55
- process.exit(1);
56
- }
57
- }
1
+ import chalk from 'chalk';
2
+ import type { GitShotsConfig } from './config.js';
3
+
4
+ export async function compare(
5
+ config: GitShotsConfig,
6
+ options: { base?: string; head: string; threshold?: number }
7
+ ) {
8
+ const url = `${config.server}/api/compare`;
9
+ const body = {
10
+ project: config.project,
11
+ base: options.base ?? 'main',
12
+ head: options.head,
13
+ threshold: options.threshold ?? 0.1
14
+ };
15
+
16
+ console.log(chalk.dim(`Comparing ${body.base} vs ${body.head} for ${config.project}...`));
17
+
18
+ try {
19
+ const res = await fetch(url, {
20
+ method: 'POST',
21
+ headers: { 'Content-Type': 'application/json', Origin: config.server },
22
+ body: JSON.stringify(body)
23
+ });
24
+ const data = await res.json();
25
+
26
+ if (!res.ok) {
27
+ console.error(chalk.red(`Compare failed: ${JSON.stringify(data)}`));
28
+ process.exit(1);
29
+ }
30
+
31
+ console.log();
32
+ console.log(`Compared ${chalk.bold(data.compared)} screens`);
33
+ console.log();
34
+
35
+ if (data.diffs.length === 0) {
36
+ console.log(chalk.green('No visual differences found!'));
37
+ return;
38
+ }
39
+
40
+ // Print table
41
+ console.log(chalk.dim('Screen'.padEnd(30) + 'Mismatch'.padEnd(15) + 'Pixels'));
42
+ console.log(chalk.dim('-'.repeat(55)));
43
+
44
+ for (const d of data.diffs) {
45
+ const pct = d.mismatchPercentage.toFixed(2) + '%';
46
+ const color = d.mismatchPercentage > 10 ? chalk.red : d.mismatchPercentage > 1 ? chalk.yellow : chalk.green;
47
+ console.log(
48
+ d.screen.padEnd(30) +
49
+ color(pct.padEnd(15)) +
50
+ chalk.dim(d.mismatchPixels.toLocaleString())
51
+ );
52
+ }
53
+ } catch (err) {
54
+ console.error(chalk.red(`Request failed: ${err}`));
55
+ process.exit(1);
56
+ }
57
+ }
package/src/config.ts CHANGED
@@ -1,28 +1,28 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
- import { resolve } from 'node:path';
3
-
4
- export interface GitShotsConfig {
5
- project: string;
6
- server: string;
7
- directory: string;
8
- }
9
-
10
- const DEFAULT_CONFIG: GitShotsConfig = {
11
- project: '',
12
- server: 'https://git-shots.rijid356.workers.dev',
13
- directory: 'docs/screenshots/current'
14
- };
15
-
16
- export function loadConfig(cwd: string = process.cwd()): GitShotsConfig {
17
- const configPath = resolve(cwd, '.git-shots.json');
18
- if (!existsSync(configPath)) {
19
- return DEFAULT_CONFIG;
20
- }
21
- try {
22
- const raw = readFileSync(configPath, 'utf-8');
23
- const parsed = JSON.parse(raw);
24
- return { ...DEFAULT_CONFIG, ...parsed };
25
- } catch {
26
- return DEFAULT_CONFIG;
27
- }
28
- }
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+
4
+ export interface GitShotsConfig {
5
+ project: string;
6
+ server: string;
7
+ directory: string;
8
+ }
9
+
10
+ const DEFAULT_CONFIG: GitShotsConfig = {
11
+ project: '',
12
+ server: 'https://git-shots.rijid356.workers.dev',
13
+ directory: 'docs/screenshots/current'
14
+ };
15
+
16
+ export function loadConfig(cwd: string = process.cwd()): GitShotsConfig {
17
+ const configPath = resolve(cwd, '.git-shots.json');
18
+ if (!existsSync(configPath)) {
19
+ return DEFAULT_CONFIG;
20
+ }
21
+ try {
22
+ const raw = readFileSync(configPath, 'utf-8');
23
+ const parsed = JSON.parse(raw);
24
+ return { ...DEFAULT_CONFIG, ...parsed };
25
+ } catch {
26
+ return DEFAULT_CONFIG;
27
+ }
28
+ }
package/src/index.ts CHANGED
@@ -1,70 +1,89 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { loadConfig } from './config.js';
4
- import { upload } from './upload.js';
5
- import { compare } from './compare.js';
6
- import { status } from './status.js';
7
-
8
- const program = new Command();
9
-
10
- program
11
- .name('git-shots')
12
- .description('CLI for git-shots visual regression platform')
13
- .version('0.1.0');
14
-
15
- program
16
- .command('upload')
17
- .description('Upload screenshots to git-shots')
18
- .option('-p, --project <slug>', 'Project slug')
19
- .option('-s, --server <url>', 'Server URL')
20
- .option('-d, --directory <path>', 'Screenshots directory')
21
- .option('-b, --branch <name>', 'Git branch (auto-detected)')
22
- .option('--sha <hash>', 'Git SHA (auto-detected)')
23
- .action(async (options) => {
24
- const config = loadConfig();
25
- if (options.project) config.project = options.project;
26
- if (options.server) config.server = options.server;
27
- if (options.directory) config.directory = options.directory;
28
- if (!config.project) {
29
- console.error('Error: project slug required. Use --project or .git-shots.json');
30
- process.exit(1);
31
- }
32
- await upload(config, { branch: options.branch, sha: options.sha });
33
- });
34
-
35
- program
36
- .command('compare')
37
- .description('Compare screenshots between branches')
38
- .requiredOption('--head <branch>', 'Head branch to compare')
39
- .option('-p, --project <slug>', 'Project slug')
40
- .option('-s, --server <url>', 'Server URL')
41
- .option('--base <branch>', 'Base branch (default: main)')
42
- .option('-t, --threshold <number>', 'Mismatch threshold 0-1', parseFloat)
43
- .action(async (options) => {
44
- const config = loadConfig();
45
- if (options.project) config.project = options.project;
46
- if (options.server) config.server = options.server;
47
- if (!config.project) {
48
- console.error('Error: project slug required. Use --project or .git-shots.json');
49
- process.exit(1);
50
- }
51
- await compare(config, { base: options.base, head: options.head, threshold: options.threshold });
52
- });
53
-
54
- program
55
- .command('status')
56
- .description('Show current diff status')
57
- .option('-p, --project <slug>', 'Project slug')
58
- .option('-s, --server <url>', 'Server URL')
59
- .action(async (options) => {
60
- const config = loadConfig();
61
- if (options.project) config.project = options.project;
62
- if (options.server) config.server = options.server;
63
- if (!config.project) {
64
- console.error('Error: project slug required. Use --project or .git-shots.json');
65
- process.exit(1);
66
- }
67
- await status(config);
68
- });
69
-
70
- program.parse();
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { loadConfig } from './config.js';
4
+ import { upload } from './upload.js';
5
+ import { compare } from './compare.js';
6
+ import { status } from './status.js';
7
+ import { pullBaselines } from './pull-baselines.js';
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .name('git-shots')
13
+ .description('CLI for git-shots visual regression platform')
14
+ .version('0.1.0');
15
+
16
+ program
17
+ .command('upload')
18
+ .description('Upload screenshots to git-shots')
19
+ .option('-p, --project <slug>', 'Project slug')
20
+ .option('-s, --server <url>', 'Server URL')
21
+ .option('-d, --directory <path>', 'Screenshots directory')
22
+ .option('-b, --branch <name>', 'Git branch (auto-detected)')
23
+ .option('--sha <hash>', 'Git SHA (auto-detected)')
24
+ .action(async (options) => {
25
+ const config = loadConfig();
26
+ if (options.project) config.project = options.project;
27
+ if (options.server) config.server = options.server;
28
+ if (options.directory) config.directory = options.directory;
29
+ if (!config.project) {
30
+ console.error('Error: project slug required. Use --project or .git-shots.json');
31
+ process.exit(1);
32
+ }
33
+ await upload(config, { branch: options.branch, sha: options.sha });
34
+ });
35
+
36
+ program
37
+ .command('compare')
38
+ .description('Compare screenshots between branches')
39
+ .requiredOption('--head <branch>', 'Head branch to compare')
40
+ .option('-p, --project <slug>', 'Project slug')
41
+ .option('-s, --server <url>', 'Server URL')
42
+ .option('--base <branch>', 'Base branch (default: main)')
43
+ .option('-t, --threshold <number>', 'Mismatch threshold 0-1', parseFloat)
44
+ .action(async (options) => {
45
+ const config = loadConfig();
46
+ if (options.project) config.project = options.project;
47
+ if (options.server) config.server = options.server;
48
+ if (!config.project) {
49
+ console.error('Error: project slug required. Use --project or .git-shots.json');
50
+ process.exit(1);
51
+ }
52
+ await compare(config, { base: options.base, head: options.head, threshold: options.threshold });
53
+ });
54
+
55
+ program
56
+ .command('status')
57
+ .description('Show current diff status')
58
+ .option('-p, --project <slug>', 'Project slug')
59
+ .option('-s, --server <url>', 'Server URL')
60
+ .action(async (options) => {
61
+ const config = loadConfig();
62
+ if (options.project) config.project = options.project;
63
+ if (options.server) config.server = options.server;
64
+ if (!config.project) {
65
+ console.error('Error: project slug required. Use --project or .git-shots.json');
66
+ process.exit(1);
67
+ }
68
+ await status(config);
69
+ });
70
+
71
+ program
72
+ .command('pull-baselines')
73
+ .description('Download baseline screenshots from git-shots')
74
+ .option('-p, --project <slug>', 'Project slug')
75
+ .option('-s, --server <url>', 'Server URL')
76
+ .option('-o, --output <path>', 'Output directory')
77
+ .option('-b, --branch <name>', 'Branch to pull baselines from (default: main)')
78
+ .action(async (options) => {
79
+ const config = loadConfig();
80
+ if (options.project) config.project = options.project;
81
+ if (options.server) config.server = options.server;
82
+ if (!config.project) {
83
+ console.error('Error: project slug required. Use --project or .git-shots.json');
84
+ process.exit(1);
85
+ }
86
+ await pullBaselines(config, { branch: options.branch, output: options.output });
87
+ });
88
+
89
+ program.parse();
@@ -0,0 +1,87 @@
1
+ import { mkdirSync, writeFileSync } from 'node:fs';
2
+ import { resolve, dirname } from 'node:path';
3
+ import chalk from 'chalk';
4
+ import type { GitShotsConfig } from './config.js';
5
+
6
+ interface Snapshot {
7
+ screen_slug: string;
8
+ category: string | null;
9
+ r2_key: string;
10
+ git_sha: string;
11
+ width: number;
12
+ height: number;
13
+ }
14
+
15
+ export async function pullBaselines(
16
+ config: GitShotsConfig,
17
+ options: { branch?: string; output?: string }
18
+ ) {
19
+ const branch = options.branch ?? 'main';
20
+ const outputDir = resolve(process.cwd(), options.output ?? config.directory);
21
+
22
+ console.log(chalk.dim(`Project: ${config.project}`));
23
+ console.log(chalk.dim(`Branch: ${branch}`));
24
+ console.log(chalk.dim(`Output: ${outputDir}`));
25
+ console.log();
26
+
27
+ // Fetch manifest
28
+ const manifestUrl = `${config.server}/api/projects/${encodeURIComponent(config.project)}/snapshots?branch=${encodeURIComponent(branch)}`;
29
+ let snapshots: Snapshot[];
30
+
31
+ try {
32
+ const res = await fetch(manifestUrl);
33
+ const data = await res.json();
34
+
35
+ if (!res.ok) {
36
+ console.error(chalk.red(`Failed to fetch snapshots: ${JSON.stringify(data)}`));
37
+ process.exit(1);
38
+ }
39
+
40
+ snapshots = data.snapshots;
41
+ } catch (err) {
42
+ console.error(chalk.red(`Request failed: ${err}`));
43
+ process.exit(1);
44
+ }
45
+
46
+ if (snapshots.length === 0) {
47
+ console.log(chalk.yellow('No baseline snapshots found.'));
48
+ return;
49
+ }
50
+
51
+ console.log(chalk.dim(`Found ${snapshots.length} baselines to download`));
52
+ console.log();
53
+
54
+ // Download in batches of 5
55
+ const batchSize = 5;
56
+ let downloaded = 0;
57
+
58
+ for (let i = 0; i < snapshots.length; i += batchSize) {
59
+ const batch = snapshots.slice(i, i + batchSize);
60
+ await Promise.all(
61
+ batch.map(async (snap) => {
62
+ const imageUrl = `${config.server}/api/images/${snap.r2_key}`;
63
+ const res = await fetch(imageUrl);
64
+ if (!res.ok) {
65
+ console.error(chalk.red(` Failed to download ${snap.screen_slug}: ${res.status}`));
66
+ return;
67
+ }
68
+
69
+ const buffer = Buffer.from(await res.arrayBuffer());
70
+ const subDir = snap.category ?? '';
71
+ const filePath = resolve(outputDir, subDir, `${snap.screen_slug}.png`);
72
+
73
+ mkdirSync(dirname(filePath), { recursive: true });
74
+ writeFileSync(filePath, buffer);
75
+
76
+ downloaded++;
77
+ console.log(
78
+ chalk.green(` [${downloaded}/${snapshots.length}]`) +
79
+ ` ${subDir ? subDir + '/' : ''}${snap.screen_slug}.png`
80
+ );
81
+ })
82
+ );
83
+ }
84
+
85
+ console.log();
86
+ console.log(chalk.green(`Downloaded ${downloaded} baselines to ${outputDir}`));
87
+ }
package/src/status.ts CHANGED
@@ -1,42 +1,42 @@
1
- import chalk from 'chalk';
2
- import type { GitShotsConfig } from './config.js';
3
-
4
- export async function status(config: GitShotsConfig) {
5
- const url = `${config.server}/api/diffs?project=${encodeURIComponent(config.project)}`;
6
-
7
- try {
8
- const res = await fetch(url);
9
- const data = await res.json();
10
-
11
- if (!res.ok) {
12
- console.error(chalk.red(`Status failed: ${JSON.stringify(data)}`));
13
- process.exit(1);
14
- }
15
-
16
- if (data.length === 0) {
17
- console.log(chalk.dim('No diffs found for this project.'));
18
- return;
19
- }
20
-
21
- console.log(`${chalk.bold(data.length)} diffs for ${config.project}`);
22
- console.log();
23
- console.log(chalk.dim('ID'.padEnd(8) + 'Status'.padEnd(12) + 'Mismatch'.padEnd(12) + 'Date'));
24
- console.log(chalk.dim('-'.repeat(50)));
25
-
26
- for (const { diff } of data) {
27
- const statusColor =
28
- diff.status === 'approved' ? chalk.green :
29
- diff.status === 'rejected' ? chalk.red :
30
- chalk.yellow;
31
- console.log(
32
- String(diff.id).padEnd(8) +
33
- statusColor(diff.status.padEnd(12)) +
34
- (diff.mismatch_percentage.toFixed(2) + '%').padEnd(12) +
35
- chalk.dim(new Date(diff.created_at * 1000).toLocaleDateString())
36
- );
37
- }
38
- } catch (err) {
39
- console.error(chalk.red(`Request failed: ${err}`));
40
- process.exit(1);
41
- }
42
- }
1
+ import chalk from 'chalk';
2
+ import type { GitShotsConfig } from './config.js';
3
+
4
+ export async function status(config: GitShotsConfig) {
5
+ const url = `${config.server}/api/diffs?project=${encodeURIComponent(config.project)}`;
6
+
7
+ try {
8
+ const res = await fetch(url);
9
+ const data = await res.json();
10
+
11
+ if (!res.ok) {
12
+ console.error(chalk.red(`Status failed: ${JSON.stringify(data)}`));
13
+ process.exit(1);
14
+ }
15
+
16
+ if (data.length === 0) {
17
+ console.log(chalk.dim('No diffs found for this project.'));
18
+ return;
19
+ }
20
+
21
+ console.log(`${chalk.bold(data.length)} diffs for ${config.project}`);
22
+ console.log();
23
+ console.log(chalk.dim('ID'.padEnd(8) + 'Status'.padEnd(12) + 'Mismatch'.padEnd(12) + 'Date'));
24
+ console.log(chalk.dim('-'.repeat(50)));
25
+
26
+ for (const { diff } of data) {
27
+ const statusColor =
28
+ diff.status === 'approved' ? chalk.green :
29
+ diff.status === 'rejected' ? chalk.red :
30
+ chalk.yellow;
31
+ console.log(
32
+ String(diff.id).padEnd(8) +
33
+ statusColor(diff.status.padEnd(12)) +
34
+ (diff.mismatch_percentage.toFixed(2) + '%').padEnd(12) +
35
+ chalk.dim(new Date(diff.created_at * 1000).toLocaleDateString())
36
+ );
37
+ }
38
+ } catch (err) {
39
+ console.error(chalk.red(`Request failed: ${err}`));
40
+ process.exit(1);
41
+ }
42
+ }
package/src/upload.ts CHANGED
@@ -1,74 +1,74 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
- import { resolve, basename, relative, dirname } from 'node:path';
3
- import { execSync } from 'node:child_process';
4
- import { glob } from 'glob';
5
- import chalk from 'chalk';
6
- import type { GitShotsConfig } from './config.js';
7
-
8
- export async function upload(config: GitShotsConfig, options: { branch?: string; sha?: string }) {
9
- const dir = resolve(process.cwd(), config.directory);
10
- if (!existsSync(dir)) {
11
- console.error(chalk.red(`Directory not found: ${dir}`));
12
- process.exit(1);
13
- }
14
-
15
- // Get git info
16
- const branch = options.branch ?? execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf-8' }).trim();
17
- const sha = options.sha ?? execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
18
-
19
- console.log(chalk.dim(`Project: ${config.project}`));
20
- console.log(chalk.dim(`Branch: ${branch}`));
21
- console.log(chalk.dim(`SHA: ${sha.slice(0, 7)}`));
22
- console.log(chalk.dim(`Dir: ${dir}`));
23
- console.log();
24
-
25
- // Find all PNGs
26
- const files = await glob('**/*.png', { cwd: dir });
27
- if (files.length === 0) {
28
- console.log(chalk.yellow('No PNG files found.'));
29
- return;
30
- }
31
-
32
- console.log(chalk.dim(`Found ${files.length} screenshots`));
33
-
34
- // Build multipart form
35
- const formData = new FormData();
36
- formData.append('project', config.project);
37
- formData.append('branch', branch);
38
- formData.append('gitSha', sha);
39
-
40
- for (const file of files) {
41
- const fullPath = resolve(dir, file);
42
- const buffer = readFileSync(fullPath);
43
- const blob = new Blob([buffer], { type: 'image/png' });
44
-
45
- // Use directory as field name for category derivation
46
- const dirName = dirname(file);
47
- const fieldName = dirName !== '.' ? `${dirName}/${basename(file)}` : basename(file);
48
-
49
- formData.append(fieldName, blob, basename(file));
50
- }
51
-
52
- // Upload
53
- const url = `${config.server}/api/upload`;
54
- console.log(chalk.dim(`Uploading to ${url}...`));
55
-
56
- try {
57
- const res = await fetch(url, {
58
- method: 'POST',
59
- body: formData,
60
- headers: { Origin: config.server },
61
- });
62
- const data = await res.json();
63
-
64
- if (!res.ok) {
65
- console.error(chalk.red(`Upload failed: ${JSON.stringify(data)}`));
66
- process.exit(1);
67
- }
68
-
69
- console.log(chalk.green(`Uploaded ${data.uploaded} screenshots`));
70
- } catch (err) {
71
- console.error(chalk.red(`Request failed: ${err}`));
72
- process.exit(1);
73
- }
74
- }
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { resolve, basename, relative, dirname } from 'node:path';
3
+ import { execSync } from 'node:child_process';
4
+ import { glob } from 'glob';
5
+ import chalk from 'chalk';
6
+ import type { GitShotsConfig } from './config.js';
7
+
8
+ export async function upload(config: GitShotsConfig, options: { branch?: string; sha?: string }) {
9
+ const dir = resolve(process.cwd(), config.directory);
10
+ if (!existsSync(dir)) {
11
+ console.error(chalk.red(`Directory not found: ${dir}`));
12
+ process.exit(1);
13
+ }
14
+
15
+ // Get git info
16
+ const branch = options.branch ?? execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf-8' }).trim();
17
+ const sha = options.sha ?? execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
18
+
19
+ console.log(chalk.dim(`Project: ${config.project}`));
20
+ console.log(chalk.dim(`Branch: ${branch}`));
21
+ console.log(chalk.dim(`SHA: ${sha.slice(0, 7)}`));
22
+ console.log(chalk.dim(`Dir: ${dir}`));
23
+ console.log();
24
+
25
+ // Find all PNGs
26
+ const files = await glob('**/*.png', { cwd: dir });
27
+ if (files.length === 0) {
28
+ console.log(chalk.yellow('No PNG files found.'));
29
+ return;
30
+ }
31
+
32
+ console.log(chalk.dim(`Found ${files.length} screenshots`));
33
+
34
+ // Build multipart form
35
+ const formData = new FormData();
36
+ formData.append('project', config.project);
37
+ formData.append('branch', branch);
38
+ formData.append('gitSha', sha);
39
+
40
+ for (const file of files) {
41
+ const fullPath = resolve(dir, file);
42
+ const buffer = readFileSync(fullPath);
43
+ const blob = new Blob([buffer], { type: 'image/png' });
44
+
45
+ // Use directory as field name for category derivation
46
+ const dirName = dirname(file);
47
+ const fieldName = dirName !== '.' ? `${dirName}/${basename(file)}` : basename(file);
48
+
49
+ formData.append(fieldName, blob, basename(file));
50
+ }
51
+
52
+ // Upload
53
+ const url = `${config.server}/api/upload`;
54
+ console.log(chalk.dim(`Uploading to ${url}...`));
55
+
56
+ try {
57
+ const res = await fetch(url, {
58
+ method: 'POST',
59
+ body: formData,
60
+ headers: { Origin: config.server },
61
+ });
62
+ const data = await res.json();
63
+
64
+ if (!res.ok) {
65
+ console.error(chalk.red(`Upload failed: ${JSON.stringify(data)}`));
66
+ process.exit(1);
67
+ }
68
+
69
+ console.log(chalk.green(`Uploaded ${data.uploaded} screenshots`));
70
+ } catch (err) {
71
+ console.error(chalk.red(`Request failed: ${err}`));
72
+ process.exit(1);
73
+ }
74
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "esModuleInterop": true,
7
- "strict": true,
8
- "outDir": "dist",
9
- "rootDir": "src",
10
- "declaration": true,
11
- "skipLibCheck": true
12
- },
13
- "include": ["src"]
14
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "esModuleInterop": true,
7
+ "strict": true,
8
+ "outDir": "dist",
9
+ "rootDir": "src",
10
+ "declaration": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["src"]
14
+ }