forked from linuxmobile/commitia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
committer.js
executable file
·71 lines (57 loc) · 1.83 KB
/
committer.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bun
import { firstLaunch, i18xs } from "./FIRST_LAUNCH";
import { DATA } from "./utils/KEY";
import { outro, confirm, isCancel, cancel, multiselect } from "@clack/prompts";
import { readFirstLaunchFile } from "./components/readFirstLaunchFile";
import { fileOptions, addStagedFiles, resetStagedFiles, getDiffSummary } from "~/components/gitStageManager";
const selectedFilesOptions = fileOptions;
async function main() {
const firstLaunchData = await readFirstLaunchFile();
if (firstLaunchData) {
if (firstLaunchData.lang === 'es') {
i18xs.changeCurrentLocale('es');
} else if (firstLaunchData.lang === 'en') {
i18xs.changeCurrentLocale('en');
}
}
console.clear()
const askGitCommitStatus = await confirm({
message: `${i18xs.t('common.ask_select_files')}`,
default: true,
});
if (isCancel(askGitCommitStatus)) {
cancel(`${i18xs.t('common.operation_canceled')}`);
return process.exit(0);
}
let selectedFiles;
if (!askGitCommitStatus) {
selectedFiles = files;
} else {
selectedFiles = await multiselect({
message: `${i18xs.t('common.selecting_files')}`,
options: selectedFilesOptions,
});
}
if (isCancel(selectedFiles)) {
cancel(`${i18xs.t('common.operation_canceled')}`);
await resetStagedFiles(selectedFiles);
return process.exit(0);
}
const stagedFiles = await addStagedFiles(selectedFiles);
const { added, totalTokenCount } = await getDiffSummary(stagedFiles);
console.log("Resumen de cambios:", { added, totalTokenCount });
}
async function checkAndRun() {
try {
const firstLaunchData = await readFirstLaunchFile();
if (!firstLaunchData || !firstLaunchData.exist) {
await firstLaunch();
}
await main();
} catch (error) {
console.error(`${i18xs.t('common.error_verifying_launchfile')}`, error);
await firstLaunch();
await main();
}
}
checkAndRun().catch(console.error);