@andocorp/cli 0.1.1 → 0.1.2
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 +13911 -0
- package/package.json +5 -5
- package/src/adapters.test.ts +0 -50
- package/src/adapters.ts +0 -215
- package/src/args.test.ts +0 -28
- package/src/args.ts +0 -98
- package/src/cli-helpers.test.ts +0 -82
- package/src/cli-helpers.ts +0 -149
- package/src/client.test.ts +0 -235
- package/src/client.ts +0 -378
- package/src/components/prompt-line.ts +0 -179
- package/src/components/transcript-pane.test.ts +0 -26
- package/src/components/transcript-pane.ts +0 -457
- package/src/config.ts +0 -53
- package/src/emoji-suggestions.ts +0 -152
- package/src/format.test.ts +0 -54
- package/src/format.ts +0 -611
- package/src/help.test.ts +0 -13
- package/src/help.ts +0 -48
- package/src/index.ts +0 -466
- package/src/interactive.ts +0 -832
- package/src/test-helpers.ts +0 -207
- package/src/types.ts +0 -24
package/src/emoji-suggestions.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import emojiData from "emojibase-data/en/data.json" with { type: "json" };
|
|
2
|
-
import shortcodeData from "emojibase-data/en/shortcodes/cldr.json" with { type: "json" };
|
|
3
|
-
|
|
4
|
-
type EmojiSuggestion = {
|
|
5
|
-
emoji: string;
|
|
6
|
-
label: string;
|
|
7
|
-
shortcode: string;
|
|
8
|
-
keywords: string[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
12
|
-
return typeof value === "object" && value !== null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getString(value: unknown): string | null {
|
|
16
|
-
return typeof value === "string" && value !== "" ? value : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getStringArray(value: unknown): string[] {
|
|
20
|
-
if (!Array.isArray(value)) {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return value.filter((item): item is string => typeof item === "string" && item !== "");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getPrimaryShortcode(value: unknown): string | null {
|
|
28
|
-
if (typeof value === "string" && value !== "") {
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!Array.isArray(value)) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
value.find(
|
|
38
|
-
(item): item is string => typeof item === "string" && item !== ""
|
|
39
|
-
) ?? null
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function buildEmojiSuggestions(): EmojiSuggestion[] {
|
|
44
|
-
const suggestions: EmojiSuggestion[] = [];
|
|
45
|
-
const rawShortcodes: Record<string, unknown> = isRecord(shortcodeData)
|
|
46
|
-
? shortcodeData
|
|
47
|
-
: {};
|
|
48
|
-
|
|
49
|
-
for (const entry of emojiData) {
|
|
50
|
-
if (!isRecord(entry)) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const emoji = getString(entry.emoji);
|
|
55
|
-
const label = getString(entry.label);
|
|
56
|
-
const hexcode = getString(entry.hexcode);
|
|
57
|
-
if (emoji == null || label == null || hexcode == null) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const shortcode = getPrimaryShortcode(rawShortcodes[hexcode]);
|
|
62
|
-
if (shortcode == null) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const keywords = Array.from(
|
|
67
|
-
new Set(
|
|
68
|
-
[...getStringArray(entry.tags), ...label.toLowerCase().split(/\s+/)]
|
|
69
|
-
.map((word) => word.trim())
|
|
70
|
-
.filter((word) => word !== "")
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
suggestions.push({
|
|
75
|
-
emoji,
|
|
76
|
-
label,
|
|
77
|
-
shortcode,
|
|
78
|
-
keywords,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return suggestions;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const emojiSuggestions = buildEmojiSuggestions();
|
|
86
|
-
|
|
87
|
-
function scoreSuggestion(suggestion: EmojiSuggestion, query: string) {
|
|
88
|
-
let score = 0;
|
|
89
|
-
const normalizedLabel = suggestion.label.toLowerCase();
|
|
90
|
-
|
|
91
|
-
if (suggestion.shortcode === query) {
|
|
92
|
-
score = 1000;
|
|
93
|
-
} else if (suggestion.shortcode.startsWith(query)) {
|
|
94
|
-
score = 500;
|
|
95
|
-
} else if (suggestion.shortcode.includes(query)) {
|
|
96
|
-
score = 120;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (normalizedLabel === query) {
|
|
100
|
-
score = Math.max(score, 800);
|
|
101
|
-
} else if (normalizedLabel.startsWith(query)) {
|
|
102
|
-
score = Math.max(score, 350);
|
|
103
|
-
} else if (normalizedLabel.includes(query)) {
|
|
104
|
-
score = Math.max(score, 80);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
for (const keyword of suggestion.keywords) {
|
|
108
|
-
if (keyword === query) {
|
|
109
|
-
score = Math.max(score, 250);
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (keyword.startsWith(query)) {
|
|
114
|
-
score = Math.max(score, 150);
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (keyword.includes(query)) {
|
|
119
|
-
score = Math.max(score, 40);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return score;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function getSuggestionQuery(value: string) {
|
|
127
|
-
const match = value.toLowerCase().match(/(?:^|[\s:])([a-z][a-z0-9_+-]{0,31})$/);
|
|
128
|
-
return match?.[1] ?? "";
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function getEmojiSuggestions(value: string, limit = 5): EmojiSuggestion[] {
|
|
132
|
-
const query = getSuggestionQuery(value);
|
|
133
|
-
if (query === "") {
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return emojiSuggestions
|
|
138
|
-
.map((suggestion) => ({
|
|
139
|
-
suggestion,
|
|
140
|
-
score: scoreSuggestion(suggestion, query),
|
|
141
|
-
}))
|
|
142
|
-
.filter((entry) => entry.score > 0)
|
|
143
|
-
.sort((left, right) => {
|
|
144
|
-
if (right.score !== left.score) {
|
|
145
|
-
return right.score - left.score;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return left.suggestion.shortcode.localeCompare(right.suggestion.shortcode);
|
|
149
|
-
})
|
|
150
|
-
.slice(0, limit)
|
|
151
|
-
.map((entry) => entry.suggestion);
|
|
152
|
-
}
|
package/src/format.test.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createMessage, createReaction } from "./test-helpers.js";
|
|
3
|
-
import {
|
|
4
|
-
formatReactionSummary,
|
|
5
|
-
getMessageBody,
|
|
6
|
-
getVisibleText,
|
|
7
|
-
getVisibleTextLength,
|
|
8
|
-
renderTerminalText,
|
|
9
|
-
} from "./format.js";
|
|
10
|
-
|
|
11
|
-
describe("format", () => {
|
|
12
|
-
it("renders markdown links as visible link labels", () => {
|
|
13
|
-
const message = createMessage({
|
|
14
|
-
markdown_content:
|
|
15
|
-
"to leave comments in figma: [https://www.figma.com/design/file](https://www.figma.com/design/file)",
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(getVisibleText(getMessageBody(message))).toBe(
|
|
19
|
-
"to leave comments in figma: https://www.figma.com/design/file"
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("renders markdown links in blue without hyperlink escapes", () => {
|
|
24
|
-
const message = createMessage({
|
|
25
|
-
markdown_content: "[Figma file](https://www.figma.com/design/file)",
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(renderTerminalText(getMessageBody(message))).toBe(
|
|
29
|
-
"\u001b[34mFigma file\u001b[0m"
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("treats terminal color escape sequences as zero-width", () => {
|
|
34
|
-
const message = createMessage({
|
|
35
|
-
markdown_content: "[Figma file](https://www.figma.com/design/file)",
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(getVisibleTextLength(renderTerminalText(getMessageBody(message)))).toBe(
|
|
39
|
-
"Figma file".length
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("renders identical reactions without spacing them apart", () => {
|
|
44
|
-
const message = createMessage({
|
|
45
|
-
message_reactions: [
|
|
46
|
-
createReaction({ id: "reaction-1", emoji_text: "🔥" }),
|
|
47
|
-
createReaction({ id: "reaction-2", emoji_text: "🔥" }),
|
|
48
|
-
createReaction({ id: "reaction-3", emoji_text: "🔥" }),
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(formatReactionSummary(message)).toBe("🔥🔥🔥");
|
|
53
|
-
});
|
|
54
|
-
});
|