-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
41 lines (35 loc) · 972 Bytes
/
utils.ts
File metadata and controls
41 lines (35 loc) · 972 Bytes
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
import { basename } from "node:path";
import { stdout } from "node:process";
import sliceAnsi from "slice-ansi";
import chalk from "chalk";
export function getTaskFromPath(path: string): string {
return basename(path);
}
export function isTask(branch: string): boolean {
return (
/^[\w\d]+$/.test(branch) &&
["master", "solo-", "mob-", "fix-", "feat"].find((match) =>
branch.includes(match),
) == null
);
}
const TRUNCATE_CHAR = "…";
export function truncate(text: string, size: number): string {
const truncated = sliceAnsi(text, 0, size - 1);
return truncated.length < text.length
? truncated + chalk.dim(TRUNCATE_CHAR)
: text;
}
export function getColumns(): number {
return stdout.columns - 1;
}
const _running: Record<string, boolean> = {};
export function runOnce(id: string, cb: (resolve: () => void) => void) {
if (_running[id]) {
return;
}
function resolve() {
delete _running[id];
}
cb(resolve);
}