-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ts
More file actions
42 lines (38 loc) · 1.22 KB
/
Copy pathgit.ts
File metadata and controls
42 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import chalk from 'chalk';
import { execa } from 'execa';
import ora from 'ora';
export class GitService {
async init(cwd: string) {
const spinner = ora('Initializing Git repository...').start();
try {
await execa('git', ['init'], { cwd });
spinner.succeed(chalk.green('Git repository initialized.'));
} catch {
spinner.warn(chalk.yellow('Failed to initialize git repository. Is git installed?'));
}
}
async addAll(cwd: string) {
try {
await execa('git', ['add', '.'], { cwd });
} catch {
// Ignore (maybe git isn't ready or empty dir)
}
}
async commit(cwd: string, message: string) {
const spinner = ora('Creating initial commit...').start();
try {
await execa('git', ['commit', '-m', message], { cwd });
spinner.succeed(chalk.green('Initial commit created.'));
} catch {
spinner.warn(chalk.yellow('Failed to create initial commit.'));
}
}
async isGitInstalled(): Promise<boolean> {
try {
await execa('git', ['--version']);
return true;
} catch {
return false;
}
}
}