Skip to content

Commit 8c19cf0

Browse files
committed
feat(genomic): add spinner to git clone operation
- Show animated spinner while cloning (silent mode, default) - Add silent option to GitCloneOptions (default: true) - Silence git output when spinner is active - Show success/fail status when clone completes - Update test mock to include createSpinner
1 parent 03ea57e commit 8c19cf0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

packages/genomic/__tests__/create-gen.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ jest.mock('inquirerer', () => {
2020
};
2121
}),
2222
registerDefaultResolver: jest.fn(),
23+
createSpinner: jest.fn().mockImplementation(() => {
24+
return {
25+
start: jest.fn(),
26+
succeed: jest.fn(),
27+
fail: jest.fn(),
28+
text: jest.fn(),
29+
};
30+
}),
2331
};
2432
});
2533

packages/genomic/src/git/git-cloner.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
22
import * as fs from 'fs';
33
import * as os from 'os';
44
import * as path from 'path';
5+
import { createSpinner } from 'inquirerer';
56
import { GitCloneOptions, GitCloneResult } from './types';
67

78
export class GitCloner {
@@ -97,16 +98,34 @@ export class GitCloner {
9798
const branch = options?.branch;
9899
const depth = options?.depth ?? 1;
99100
const singleBranch = options?.singleBranch ?? true;
101+
const silent = options?.silent ?? true;
100102

101103
const branchArgs = branch ? ` --branch ${branch}` : '';
102104
const singleBranchArgs = singleBranch ? ' --single-branch' : '';
103105
const depthArgs = ` --depth ${depth}`;
104106

105107
const command = `git clone${branchArgs}${singleBranchArgs}${depthArgs} ${url} ${destination}`;
106108

109+
const spinner = silent ? createSpinner(`Cloning ${url}...`) : null;
110+
107111
try {
108-
execSync(command, { stdio: 'inherit' });
112+
if (spinner) {
113+
spinner.start();
114+
}
115+
116+
execSync(command, {
117+
stdio: silent ? 'pipe' : 'inherit',
118+
encoding: 'utf-8'
119+
});
120+
121+
if (spinner) {
122+
spinner.succeed('Repository cloned');
123+
}
109124
} catch (error) {
125+
if (spinner) {
126+
spinner.fail('Failed to clone repository');
127+
}
128+
110129
// Clean up on failure
111130
if (fs.existsSync(destination)) {
112131
fs.rmSync(destination, { recursive: true, force: true });

packages/genomic/src/git/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export interface GitCloneOptions {
22
branch?: string;
33
depth?: number;
44
singleBranch?: boolean;
5+
/** If true (default), show spinner and silence git output. If false, show raw git output. */
6+
silent?: boolean;
57
}
68

79
export interface GitCloneResult {

0 commit comments

Comments
 (0)