@jannael/glinter 1.0.2 → 1.0.4
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 +411 -66
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -90,6 +90,19 @@ var require_src = __commonJS((exports, module) => {
|
|
|
90
90
|
module.exports = { cursor, scroll, erase, beep };
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
+
// src/packages/colors.ts
|
|
94
|
+
var GREEN = "\x1B[32m";
|
|
95
|
+
var YELLOW = "\x1B[33m";
|
|
96
|
+
var RED = "\x1B[31m";
|
|
97
|
+
var MAGENTA = "\x1B[35m";
|
|
98
|
+
var BOLD = "\x1B[1m";
|
|
99
|
+
var BLACK = "\x1B[30m";
|
|
100
|
+
var BG_YELLOW = "\x1B[43m";
|
|
101
|
+
var RESET = "\x1B[0m";
|
|
102
|
+
|
|
103
|
+
// src/packages/check.ts
|
|
104
|
+
var CHECK = `${GREEN}\u2714${RESET}`;
|
|
105
|
+
|
|
93
106
|
// node_modules/@clack/core/dist/index.mjs
|
|
94
107
|
import { styleText as y } from "util";
|
|
95
108
|
import { stdout as S, stdin as $ } from "process";
|
|
@@ -1008,6 +1021,33 @@ var it = class extends p {
|
|
|
1008
1021
|
});
|
|
1009
1022
|
}
|
|
1010
1023
|
};
|
|
1024
|
+
class nt extends p {
|
|
1025
|
+
options;
|
|
1026
|
+
cursor = 0;
|
|
1027
|
+
get _selectedValue() {
|
|
1028
|
+
return this.options[this.cursor];
|
|
1029
|
+
}
|
|
1030
|
+
changeValue() {
|
|
1031
|
+
this.value = this._selectedValue.value;
|
|
1032
|
+
}
|
|
1033
|
+
constructor(t) {
|
|
1034
|
+
super(t, false), this.options = t.options;
|
|
1035
|
+
const e = this.options.findIndex(({ value: i }) => i === t.initialValue), s = e === -1 ? 0 : e;
|
|
1036
|
+
this.cursor = this.options[s].disabled ? d(s, 1, this.options) : s, this.changeValue(), this.on("cursor", (i) => {
|
|
1037
|
+
switch (i) {
|
|
1038
|
+
case "left":
|
|
1039
|
+
case "up":
|
|
1040
|
+
this.cursor = d(this.cursor, -1, this.options);
|
|
1041
|
+
break;
|
|
1042
|
+
case "down":
|
|
1043
|
+
case "right":
|
|
1044
|
+
this.cursor = d(this.cursor, 1, this.options);
|
|
1045
|
+
break;
|
|
1046
|
+
}
|
|
1047
|
+
this.changeValue();
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1011
1051
|
|
|
1012
1052
|
// node_modules/@clack/prompts/dist/index.mjs
|
|
1013
1053
|
import { styleText as t, stripVTControlCharacters as ne } from "util";
|
|
@@ -1167,97 +1207,402 @@ ${r ? t("cyan", E2) : ""}
|
|
|
1167
1207
|
} }).prompt();
|
|
1168
1208
|
};
|
|
1169
1209
|
var Ve = { light: w2("\u2500", "-"), heavy: w2("\u2501", "="), block: w2("\u2588", "#") };
|
|
1210
|
+
var re = (e, i) => e.includes(`
|
|
1211
|
+
`) ? e.split(`
|
|
1212
|
+
`).map((s) => i(s)).join(`
|
|
1213
|
+
`) : i(e);
|
|
1214
|
+
var _t = (e) => {
|
|
1215
|
+
const i = (s, r) => {
|
|
1216
|
+
const u2 = s.label ?? String(s.value);
|
|
1217
|
+
switch (r) {
|
|
1218
|
+
case "disabled":
|
|
1219
|
+
return `${t("gray", H2)} ${re(u2, (n) => t("gray", n))}${s.hint ? ` ${t("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
1220
|
+
case "selected":
|
|
1221
|
+
return `${re(u2, (n) => t("dim", n))}`;
|
|
1222
|
+
case "active":
|
|
1223
|
+
return `${t("green", z2)} ${u2}${s.hint ? ` ${t("dim", `(${s.hint})`)}` : ""}`;
|
|
1224
|
+
case "cancelled":
|
|
1225
|
+
return `${re(u2, (n) => t(["strikethrough", "dim"], n))}`;
|
|
1226
|
+
default:
|
|
1227
|
+
return `${t("dim", H2)} ${re(u2, (n) => t("dim", n))}`;
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
return new nt({ options: e.options, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue, render() {
|
|
1231
|
+
const s = e.withGuide ?? u.withGuide, r = `${V2(this.state)} `, u2 = `${ye(this.state)} `, n = R(e.output, e.message, u2, r), o = `${s ? `${t("gray", d2)}
|
|
1232
|
+
` : ""}${n}
|
|
1233
|
+
`;
|
|
1234
|
+
switch (this.state) {
|
|
1235
|
+
case "submit": {
|
|
1236
|
+
const c2 = s ? `${t("gray", d2)} ` : "", a = R(e.output, i(this.options[this.cursor], "selected"), c2);
|
|
1237
|
+
return `${o}${a}`;
|
|
1238
|
+
}
|
|
1239
|
+
case "cancel": {
|
|
1240
|
+
const c2 = s ? `${t("gray", d2)} ` : "", a = R(e.output, i(this.options[this.cursor], "cancelled"), c2);
|
|
1241
|
+
return `${o}${a}${s ? `
|
|
1242
|
+
${t("gray", d2)}` : ""}`;
|
|
1243
|
+
}
|
|
1244
|
+
default: {
|
|
1245
|
+
const c2 = s ? `${t("cyan", d2)} ` : "", a = s ? t("cyan", E2) : "", l = o.split(`
|
|
1246
|
+
`).length, $2 = s ? 2 : 1;
|
|
1247
|
+
return `${o}${c2}${Y2({ output: e.output, cursor: this.cursor, options: this.options, maxItems: e.maxItems, columnPadding: c2.length, rowPadding: l + $2, style: (y2, p2) => i(y2, y2.disabled ? "disabled" : p2 ? "active" : "inactive") }).join(`
|
|
1248
|
+
${c2}`)}
|
|
1249
|
+
${a}
|
|
1250
|
+
`;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
} }).prompt();
|
|
1254
|
+
};
|
|
1170
1255
|
var je = `${t("gray", d2)} `;
|
|
1171
1256
|
|
|
1172
|
-
// src/
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1257
|
+
// src/packages/multiselect.ts
|
|
1258
|
+
async function MultiSelect({
|
|
1259
|
+
message,
|
|
1260
|
+
options
|
|
1261
|
+
}) {
|
|
1262
|
+
const selected = await yt({
|
|
1263
|
+
message,
|
|
1264
|
+
options,
|
|
1265
|
+
required: true
|
|
1266
|
+
});
|
|
1267
|
+
if (q(selected)) {
|
|
1268
|
+
pt("Operation cancelled.");
|
|
1269
|
+
process.exit(0);
|
|
1179
1270
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1271
|
+
return selected;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
// src/add/app/add-command.ts
|
|
1275
|
+
class AddCommand {
|
|
1276
|
+
getChangesUseCase;
|
|
1277
|
+
stageChangesUseCase;
|
|
1278
|
+
constructor(getChangesUseCase, stageChangesUseCase) {
|
|
1279
|
+
this.getChangesUseCase = getChangesUseCase;
|
|
1280
|
+
this.stageChangesUseCase = stageChangesUseCase;
|
|
1281
|
+
}
|
|
1282
|
+
async execute() {
|
|
1283
|
+
const { changes, warnings } = await this.getChangesUseCase.execute();
|
|
1284
|
+
if (changes.length === 0) {
|
|
1285
|
+
console.log(`${CHECK} All changes are either staged or sensitive (like .env).`);
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
const options = [
|
|
1289
|
+
{ value: "all", label: `${BOLD}all changes${RESET}` },
|
|
1290
|
+
...changes.map((c2) => ({ value: c2.value, label: c2.label }))
|
|
1291
|
+
];
|
|
1292
|
+
const selectedChanges = await MultiSelect({
|
|
1293
|
+
message: "Select the changes you want to commit. (select with space and confirm with enter)",
|
|
1294
|
+
options
|
|
1295
|
+
});
|
|
1296
|
+
let selected = selectedChanges.map((file) => file.trim());
|
|
1297
|
+
if (selected.includes("all")) {
|
|
1298
|
+
selected = changes.map((c2) => c2.value);
|
|
1299
|
+
}
|
|
1300
|
+
if (selected.length > 0) {
|
|
1301
|
+
await this.stageChangesUseCase.execute(selected);
|
|
1302
|
+
if (warnings.size > 0) {
|
|
1303
|
+
console.log(`
|
|
1304
|
+
${BG_YELLOW}${BLACK} WARNING ${RESET}`);
|
|
1305
|
+
for (const warning of warnings) {
|
|
1306
|
+
console.log(warning);
|
|
1307
|
+
}
|
|
1308
|
+
console.log("");
|
|
1309
|
+
}
|
|
1194
1310
|
}
|
|
1195
|
-
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// src/add/domain/change.ts
|
|
1315
|
+
class Change {
|
|
1316
|
+
props;
|
|
1317
|
+
constructor(props) {
|
|
1318
|
+
this.props = props;
|
|
1319
|
+
}
|
|
1320
|
+
get value() {
|
|
1321
|
+
return this.props.value;
|
|
1322
|
+
}
|
|
1323
|
+
get status() {
|
|
1324
|
+
return this.props.status;
|
|
1325
|
+
}
|
|
1326
|
+
get displayPath() {
|
|
1327
|
+
return this.props.displayPath;
|
|
1328
|
+
}
|
|
1329
|
+
get label() {
|
|
1330
|
+
const { status, displayPath } = this.props;
|
|
1331
|
+
let label = `${status}: ${displayPath}`;
|
|
1196
1332
|
if (status.includes("M")) {
|
|
1197
|
-
label =
|
|
1198
|
-
} else if (status.includes("A") || status.includes("?")) {
|
|
1199
|
-
label = `\x1B[32mnew file:\x1B[0m ${displayPath}`;
|
|
1200
|
-
} else if (status.includes("D")) {
|
|
1201
|
-
label = `\x1B[31mdeleted:\x1B[0m ${displayPath}`;
|
|
1202
|
-
} else if (status.includes("R")) {
|
|
1203
|
-
label = `\x1B[35mrenamed:\x1B[0m ${displayPath}`;
|
|
1204
|
-
} else {
|
|
1205
|
-
label = `${status}: ${displayPath}`;
|
|
1333
|
+
label = `${YELLOW}modified:${RESET} ${displayPath}`;
|
|
1206
1334
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
warnings.add("\x1B[33m .env file hidden\x1B[0m (Add to .gitignore to avoid leaks)");
|
|
1335
|
+
if (status.includes("A") || status.includes("?")) {
|
|
1336
|
+
label = `${GREEN}new file:${RESET} ${displayPath}`;
|
|
1210
1337
|
}
|
|
1211
|
-
if (
|
|
1212
|
-
|
|
1338
|
+
if (status.includes("D")) {
|
|
1339
|
+
label = `${RED}deleted:${RESET} ${displayPath}`;
|
|
1213
1340
|
}
|
|
1214
|
-
if (
|
|
1215
|
-
|
|
1341
|
+
if (status.includes("R")) {
|
|
1342
|
+
label = `${MAGENTA}renamed:${RESET} ${displayPath}`;
|
|
1216
1343
|
}
|
|
1344
|
+
return label;
|
|
1217
1345
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
return;
|
|
1346
|
+
isSensitive() {
|
|
1347
|
+
return this.value.includes(".env") || this.value.includes("node_modules");
|
|
1221
1348
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1349
|
+
getWarning() {
|
|
1350
|
+
if (this.value.includes(".env")) {
|
|
1351
|
+
return `${YELLOW} .env file hidden${RESET} (Add to .gitignore to avoid leaks)`;
|
|
1352
|
+
}
|
|
1353
|
+
if (this.value.includes("node_modules")) {
|
|
1354
|
+
return `${YELLOW} node_modules hidden${RESET} (Add to .gitignore to save space)`;
|
|
1355
|
+
}
|
|
1356
|
+
return null;
|
|
1357
|
+
}
|
|
1358
|
+
static fromPorcelain(entries) {
|
|
1359
|
+
const changes = [];
|
|
1360
|
+
for (let i = 0;i < entries.length; i++) {
|
|
1361
|
+
const entry = entries[i];
|
|
1362
|
+
if (!entry)
|
|
1363
|
+
continue;
|
|
1364
|
+
const status = entry.slice(0, 2);
|
|
1365
|
+
const file = entry.slice(3);
|
|
1366
|
+
const isStaged = status[0] !== " " && status[0] !== "?";
|
|
1367
|
+
if (isStaged)
|
|
1368
|
+
continue;
|
|
1369
|
+
let displayPath = file;
|
|
1370
|
+
const value = file;
|
|
1371
|
+
if (status.startsWith("R") || status.startsWith("C")) {
|
|
1372
|
+
const source = entries[++i];
|
|
1373
|
+
displayPath = `${source} -> ${file}`;
|
|
1374
|
+
}
|
|
1375
|
+
changes.push(new Change({ value, status, displayPath }));
|
|
1376
|
+
}
|
|
1377
|
+
return changes;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// src/add/app/get-changes.use-case.ts
|
|
1382
|
+
class GetChangesUseCase {
|
|
1383
|
+
gitRepository;
|
|
1384
|
+
constructor(gitRepository) {
|
|
1385
|
+
this.gitRepository = gitRepository;
|
|
1386
|
+
}
|
|
1387
|
+
async execute() {
|
|
1388
|
+
const entries = await this.gitRepository.getEntries();
|
|
1389
|
+
if (entries.length === 0) {
|
|
1390
|
+
return { changes: [], warnings: new Set };
|
|
1391
|
+
}
|
|
1392
|
+
const allChanges = Change.fromPorcelain(entries);
|
|
1393
|
+
const warnings = new Set;
|
|
1394
|
+
const changes = [];
|
|
1395
|
+
for (const change of allChanges) {
|
|
1396
|
+
const warning = change.getWarning();
|
|
1397
|
+
if (warning) {
|
|
1398
|
+
warnings.add(warning);
|
|
1399
|
+
}
|
|
1400
|
+
if (!change.isSensitive()) {
|
|
1401
|
+
changes.push(change);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return { changes, warnings };
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// src/add/app/stage-changes.use-case.ts
|
|
1409
|
+
class StageChangesUseCase {
|
|
1410
|
+
gitRepository;
|
|
1411
|
+
constructor(gitRepository) {
|
|
1412
|
+
this.gitRepository = gitRepository;
|
|
1413
|
+
}
|
|
1414
|
+
async execute(files) {
|
|
1415
|
+
if (files.length === 0)
|
|
1416
|
+
return;
|
|
1417
|
+
await this.gitRepository.stageFiles(files);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// src/add/infra/bun-git.repository.ts
|
|
1422
|
+
var {$: $2 } = globalThis.Bun;
|
|
1423
|
+
|
|
1424
|
+
class BunGitRepository {
|
|
1425
|
+
async getEntries() {
|
|
1426
|
+
const output = await $2`git status --porcelain -z`.quiet().text();
|
|
1427
|
+
if (!output.trim()) {
|
|
1428
|
+
return [];
|
|
1429
|
+
}
|
|
1430
|
+
return output.split("\x00").filter(Boolean);
|
|
1431
|
+
}
|
|
1432
|
+
async stageFiles(files) {
|
|
1433
|
+
if (files.length === 0)
|
|
1434
|
+
return;
|
|
1435
|
+
const proc = Bun.spawn(["git", "add", ...files], {
|
|
1436
|
+
stdio: ["inherit", "inherit", "inherit"]
|
|
1437
|
+
});
|
|
1438
|
+
const exitCode = await proc.exited;
|
|
1439
|
+
if (exitCode !== 0) {
|
|
1440
|
+
throw new Error(`Git add failed with exit code ${exitCode}`);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// src/add/main.ts
|
|
1446
|
+
async function addCommand() {
|
|
1447
|
+
const gitRepository = new BunGitRepository;
|
|
1448
|
+
const getChangesUseCase = new GetChangesUseCase(gitRepository);
|
|
1449
|
+
const stageChangesUseCase = new StageChangesUseCase(gitRepository);
|
|
1450
|
+
const addCommand2 = new AddCommand(getChangesUseCase, stageChangesUseCase);
|
|
1451
|
+
await addCommand2.execute();
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// src/switch/domain/branch.ts
|
|
1455
|
+
class Branch {
|
|
1456
|
+
props;
|
|
1457
|
+
constructor(props) {
|
|
1458
|
+
this.props = props;
|
|
1459
|
+
}
|
|
1460
|
+
get name() {
|
|
1461
|
+
return this.props.name;
|
|
1462
|
+
}
|
|
1463
|
+
get isCurrentBranch() {
|
|
1464
|
+
return this.props.current;
|
|
1465
|
+
}
|
|
1466
|
+
get isRemoteBranch() {
|
|
1467
|
+
return this.props.remote;
|
|
1468
|
+
}
|
|
1469
|
+
get isHeadBranch() {
|
|
1470
|
+
return this.props.name.includes("HEAD");
|
|
1471
|
+
}
|
|
1472
|
+
static fromPorcelain(entries) {
|
|
1473
|
+
const branches = [];
|
|
1474
|
+
for (let i = 0;i < entries.length; i++) {
|
|
1475
|
+
const entry = entries[i];
|
|
1476
|
+
if (!entry)
|
|
1477
|
+
continue;
|
|
1478
|
+
const current = entry.includes("*");
|
|
1479
|
+
const remote = entry.includes("remotes/");
|
|
1480
|
+
branches.push(new Branch({ name: entry, current, remote }));
|
|
1481
|
+
}
|
|
1482
|
+
return branches;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
// src/switch/app/get-branches.use-case.ts
|
|
1487
|
+
class GetBranchesUseCase {
|
|
1488
|
+
branchRepository;
|
|
1489
|
+
constructor(branchRepository) {
|
|
1490
|
+
this.branchRepository = branchRepository;
|
|
1491
|
+
}
|
|
1492
|
+
async execute() {
|
|
1493
|
+
const branches = await this.branchRepository.getBranches();
|
|
1494
|
+
const allBranches = Branch.fromPorcelain(branches);
|
|
1495
|
+
return allBranches;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// src/switch/app/switch-branch.use-case.ts
|
|
1500
|
+
class SwitchBranch {
|
|
1501
|
+
branchRepository;
|
|
1502
|
+
constructor(branchRepository) {
|
|
1503
|
+
this.branchRepository = branchRepository;
|
|
1504
|
+
}
|
|
1505
|
+
async execute({ branch }) {
|
|
1506
|
+
await this.branchRepository.switchBranch({ branch });
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// src/packages/select.ts
|
|
1511
|
+
async function Select({
|
|
1512
|
+
message,
|
|
1513
|
+
options
|
|
1514
|
+
}) {
|
|
1515
|
+
const selected = await _t({
|
|
1516
|
+
message,
|
|
1517
|
+
options
|
|
1230
1518
|
});
|
|
1231
|
-
if (q(
|
|
1519
|
+
if (q(selected)) {
|
|
1232
1520
|
pt("Operation cancelled.");
|
|
1233
1521
|
process.exit(0);
|
|
1234
1522
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1523
|
+
return selected;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// src/switch/app/switch-command.ts
|
|
1527
|
+
class SwitchCommand {
|
|
1528
|
+
getBranchesUseCase;
|
|
1529
|
+
switchBranch;
|
|
1530
|
+
constructor(getBranchesUseCase, switchBranch) {
|
|
1531
|
+
this.getBranchesUseCase = getBranchesUseCase;
|
|
1532
|
+
this.switchBranch = switchBranch;
|
|
1533
|
+
}
|
|
1534
|
+
async execute() {
|
|
1535
|
+
const branches = await this.getBranchesUseCase.execute();
|
|
1536
|
+
if (branches.length === 0) {
|
|
1537
|
+
console.log(`${CHECK} No branches found.`);
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const options = [];
|
|
1541
|
+
for (const branch of branches) {
|
|
1542
|
+
let label = branch.name;
|
|
1543
|
+
let value = branch.name;
|
|
1544
|
+
if (branch.isHeadBranch)
|
|
1545
|
+
continue;
|
|
1546
|
+
if (branch.isCurrentBranch) {
|
|
1547
|
+
console.log(`${CHECK} Current branch: ${branch.name}`);
|
|
1548
|
+
continue;
|
|
1549
|
+
}
|
|
1550
|
+
if (branch.isRemoteBranch) {
|
|
1551
|
+
label = branch.name.replace("remotes/origin/", `${GREEN}remote branch:${RESET} `);
|
|
1552
|
+
value = branch.name.replace("remotes/origin/", "");
|
|
1553
|
+
}
|
|
1554
|
+
options.push({
|
|
1555
|
+
value,
|
|
1556
|
+
label
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
const selectedBranch = await Select({
|
|
1560
|
+
message: "Select the branch you want to switch to.",
|
|
1561
|
+
options
|
|
1562
|
+
});
|
|
1563
|
+
await this.switchBranch.execute({ branch: selectedBranch });
|
|
1238
1564
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
// src/switch/infra/bun-switch-repository.ts
|
|
1568
|
+
var {$: $3 } = globalThis.Bun;
|
|
1569
|
+
|
|
1570
|
+
class BunSwitchRepository {
|
|
1571
|
+
async getBranches() {
|
|
1572
|
+
const output = await $3`git branch -a`.quiet().text();
|
|
1573
|
+
if (!output.trim()) {
|
|
1574
|
+
return [];
|
|
1575
|
+
}
|
|
1576
|
+
return output.split(`
|
|
1577
|
+
`).map((branch) => branch.trim());
|
|
1578
|
+
}
|
|
1579
|
+
async switchBranch({ branch }) {
|
|
1580
|
+
const proc = Bun.spawn(["git", "checkout", branch], {
|
|
1241
1581
|
stdio: ["inherit", "inherit", "inherit"]
|
|
1242
1582
|
});
|
|
1243
1583
|
const exitCode = await proc.exited;
|
|
1244
|
-
if (
|
|
1245
|
-
|
|
1246
|
-
\x1B[43m\x1B[30m WARNING \x1B[0m`);
|
|
1247
|
-
for (const warning of warnings) {
|
|
1248
|
-
console.log(warning);
|
|
1249
|
-
}
|
|
1250
|
-
console.log("");
|
|
1584
|
+
if (exitCode !== 0) {
|
|
1585
|
+
throw new Error(`Git checkout failed with exit code ${exitCode}`);
|
|
1251
1586
|
}
|
|
1252
|
-
process.exit(exitCode);
|
|
1253
1587
|
}
|
|
1254
1588
|
}
|
|
1255
1589
|
|
|
1590
|
+
// src/switch/main.ts
|
|
1591
|
+
async function switchCommand() {
|
|
1592
|
+
const switchRepo = new BunSwitchRepository;
|
|
1593
|
+
const switchBranchUseCase = new SwitchBranch(switchRepo);
|
|
1594
|
+
const getBranchesUseCase = new GetBranchesUseCase(switchRepo);
|
|
1595
|
+
const switchCommand2 = new SwitchCommand(getBranchesUseCase, switchBranchUseCase);
|
|
1596
|
+
await switchCommand2.execute();
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1256
1599
|
// src/index.ts
|
|
1257
1600
|
var args = Bun.argv.slice(2);
|
|
1258
|
-
if (args[0] === "add" && !args[1])
|
|
1259
|
-
await
|
|
1260
|
-
|
|
1601
|
+
if (args[0] === "add" && !args[1])
|
|
1602
|
+
await addCommand();
|
|
1603
|
+
else if (args[0] === "switch" && !args[1])
|
|
1604
|
+
await switchCommand();
|
|
1605
|
+
else {
|
|
1261
1606
|
const proc = Bun.spawn(["git", ...args], {
|
|
1262
1607
|
stdio: ["inherit", "inherit", "inherit"]
|
|
1263
1608
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jannael/glinter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A high-performance, transparent Git wrapper with interactive staging",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -31,12 +31,15 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"exports": {
|
|
34
|
-
".": "./
|
|
34
|
+
".": "./src/index.ts"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"dev": "bun run src/index.ts",
|
|
38
38
|
"build": "bun build ./src/index.ts --outfile=./dist/index.js --target=bun",
|
|
39
|
-
"prepublishOnly": "bun run build"
|
|
39
|
+
"prepublishOnly": "bun run build",
|
|
40
|
+
"test": "vitest",
|
|
41
|
+
"lint": "biome check",
|
|
42
|
+
"lint:fix": "biome format --write"
|
|
40
43
|
},
|
|
41
44
|
"bin": {
|
|
42
45
|
"g": "./dist/index.js"
|
|
@@ -46,7 +49,8 @@
|
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
51
|
"@biomejs/biome": "2.4.10",
|
|
49
|
-
"@types/bun": "latest"
|
|
52
|
+
"@types/bun": "latest",
|
|
53
|
+
"vitest": "4.1.4"
|
|
50
54
|
},
|
|
51
55
|
"peerDependencies": {
|
|
52
56
|
"bun": ">=1.0.0",
|