@flowscripter/dynamic-cli-framework 1.1.4 → 1.1.5
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/bun.lock +2 -2
- package/package.json +2 -2
- package/src/api/service/core/PrinterService.ts +1 -1
- package/src/api/service/core/SyntaxHighlighterService.ts +1 -1
- package/src/service/printer/DefaultPrinterService.ts +3 -3
- package/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.ts +19 -5
- package/tests/service/printer/DefaultPrinterService.test.ts +1 -1
- package/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.ts +1 -1
package/bun.lock
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"emphasize": "^7.0.0",
|
|
8
8
|
"fastest-levenshtein": "^1.0.16",
|
|
9
|
-
"figlet": "^1.8.
|
|
9
|
+
"figlet": "^1.8.1",
|
|
10
10
|
"highlight.js": "^11.11.1",
|
|
11
11
|
"prettier": "^3.5.3",
|
|
12
12
|
"supports-color": "^10.0.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
"fastest-levenshtein": ["fastest-levenshtein@1.0.16", "", {}, "sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg=="],
|
|
45
45
|
|
|
46
|
-
"figlet": ["figlet@1.8.
|
|
46
|
+
"figlet": ["figlet@1.8.1", "", { "bin": { "figlet": "bin/index.js" } }, "sha512-kEC3Sme+YvA8Hkibv0NR1oClGcWia0VB2fC1SlMy027cwe795Xx40Xiv/nw/iFAwQLupymWh+uhAAErn/7hwPg=="],
|
|
47
47
|
|
|
48
48
|
"highlight.js": ["highlight.js@11.11.1", "", {}, "sha512-Xwwo44whKBVCYoliBQwaPvtd/2tYFkRQtXDWj1nackaV2JPXx3L0+Jvd8/qCJ2p+ML0/XVkJ2q+Mr+UVdpJK5w=="],
|
|
49
49
|
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"module": "index.ts",
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "1.1.
|
|
21
|
+
"version": "1.1.5",
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"emphasize": "^7.0.0",
|
|
33
33
|
"fastest-levenshtein": "^1.0.16",
|
|
34
|
-
"figlet": "^1.8.
|
|
34
|
+
"figlet": "^1.8.1",
|
|
35
35
|
"highlight.js": "^11.11.1",
|
|
36
36
|
"prettier": "^3.5.3",
|
|
37
37
|
"supports-color": "^10.0.0",
|
|
@@ -139,7 +139,7 @@ export default interface PrinterService {
|
|
|
139
139
|
* Has no effect if {@link colorEnabled} is `false`.
|
|
140
140
|
*
|
|
141
141
|
* @param message the message to color.
|
|
142
|
-
* @param hexFormattedColor the color to use. This should be a valid hex formatted string e.g. "
|
|
142
|
+
* @param hexFormattedColor the color to use. This should be a valid hex formatted string e.g. "#rrggbb".
|
|
143
143
|
*/
|
|
144
144
|
color(message: string, hexFormattedColor: string): string;
|
|
145
145
|
|
|
@@ -8,7 +8,7 @@ export const SYNTAX_HIGHLIGHTER_SERVICE_ID =
|
|
|
8
8
|
*
|
|
9
9
|
* The keys are the names of the defined [highlight.js scopes](https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html).
|
|
10
10
|
*
|
|
11
|
-
* The values are colors expressed as a hex formatted string e.g. "
|
|
11
|
+
* The values are colors expressed as a hex formatted string e.g. "#rrggbb".
|
|
12
12
|
*
|
|
13
13
|
* The scheme does not need to list all scopes exhaustively.
|
|
14
14
|
*/
|
|
@@ -163,13 +163,13 @@ export default class DefaultPrinterService implements PrinterService {
|
|
|
163
163
|
|
|
164
164
|
public color(message: string, hexFormattedColor: string): string {
|
|
165
165
|
if (
|
|
166
|
-
(hexFormattedColor.length !==
|
|
167
|
-
(!hexFormattedColor.toLowerCase().startsWith("
|
|
166
|
+
(hexFormattedColor.length !== 7) ||
|
|
167
|
+
(!hexFormattedColor.toLowerCase().startsWith("#"))
|
|
168
168
|
) {
|
|
169
169
|
throw new Error(`Invalid color: ${hexFormattedColor}`);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
const colorValue = parseInt(hexFormattedColor, 16);
|
|
172
|
+
const colorValue = parseInt(hexFormattedColor.slice(1), 16);
|
|
173
173
|
|
|
174
174
|
if (isNaN(colorValue) || (colorValue < 0 || colorValue > 0xffffff)) {
|
|
175
175
|
throw new Error(`Invalid color: ${hexFormattedColor}`);
|
|
@@ -2,9 +2,9 @@ import type SyntaxHighlighterService from "../../api/service/core/SyntaxHighligh
|
|
|
2
2
|
import type { LanguageFn as HighlightSyntax } from "highlight.js";
|
|
3
3
|
import { createEmphasize } from "emphasize";
|
|
4
4
|
import json from "highlight.js/lib/languages/json";
|
|
5
|
-
import { ColorScheme } from "../../api/service/core/SyntaxHighlighterService.ts";
|
|
5
|
+
import type { ColorScheme } from "../../api/service/core/SyntaxHighlighterService.ts";
|
|
6
6
|
|
|
7
|
-
type Sheet = Record<string, (string) => string> | undefined;
|
|
7
|
+
type Sheet = Record<string, (value: string) => string> | undefined;
|
|
8
8
|
|
|
9
9
|
interface Emphasize {
|
|
10
10
|
listLanguages(): ReadonlyArray<string>;
|
|
@@ -24,7 +24,8 @@ interface Emphasize {
|
|
|
24
24
|
export default class DefaultSyntaxHighlighterService
|
|
25
25
|
implements SyntaxHighlighterService {
|
|
26
26
|
colorEnabled = true;
|
|
27
|
-
colorFunction: (text: string, hexFormattedColor: string) => string
|
|
27
|
+
colorFunction: (text: string, hexFormattedColor: string) => string = (text) =>
|
|
28
|
+
text;
|
|
28
29
|
|
|
29
30
|
emphasize: Emphasize;
|
|
30
31
|
|
|
@@ -58,9 +59,22 @@ export default class DefaultSyntaxHighlighterService
|
|
|
58
59
|
if (colorScheme && this.colorFunction) {
|
|
59
60
|
sheet = {};
|
|
60
61
|
for (const [key, value] of Object.entries(colorScheme)) {
|
|
61
|
-
if (value) {
|
|
62
|
-
|
|
62
|
+
if (!value) {
|
|
63
|
+
throw new Error(`Invalid color for entry: ${key}`);
|
|
63
64
|
}
|
|
65
|
+
if (
|
|
66
|
+
(value.length !== 7) ||
|
|
67
|
+
(!value.toLowerCase().startsWith("#"))
|
|
68
|
+
) {
|
|
69
|
+
throw new Error(`Invalid color: ${value}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const colorValue = parseInt(value.slice(1), 16);
|
|
73
|
+
|
|
74
|
+
if (isNaN(colorValue) || (colorValue < 0 || colorValue > 0xffffff)) {
|
|
75
|
+
throw new Error(`Invalid color: ${value}`);
|
|
76
|
+
}
|
|
77
|
+
sheet[key] = (text: string) => this.colorFunction(text, value);
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
|
|
@@ -122,7 +122,7 @@ describe("DefaultPrinterService tests", () => {
|
|
|
122
122
|
new TtyStyler(3),
|
|
123
123
|
);
|
|
124
124
|
printerService.colorEnabled = true;
|
|
125
|
-
await printerService.info(printerService.color("hello", "
|
|
125
|
+
await printerService.info(printerService.color("hello", "#000000"));
|
|
126
126
|
expectBytesEquals(
|
|
127
127
|
dummyStderr.getString(),
|
|
128
128
|
new Uint8Array([
|