@flowscripter/dynamic-cli-framework 1.1.0 → 1.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/bun.lock +3 -3
- package/index.ts +5 -0
- package/package.json +2 -2
- package/src/api/service/core/PrettyPrinterService.ts +3 -3
- package/src/service/prettyPrinter/DefaultPrettyPrinterService.ts +9 -9
- package/src/service/printer/command/LogLevelCommand.ts +8 -4
- package/src/util/logger.ts +9 -20
- package/tests/fixtures/prettierPluginFoo.ts +8 -4
package/bun.lock
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"ts-log": "^2.2.7",
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@types/bun": "^1.2.
|
|
16
|
+
"@types/bun": "^1.2.8",
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"typescript": "^5.8.2",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
"packages": {
|
|
24
|
-
"@types/bun": ["@types/bun@1.2.
|
|
24
|
+
"@types/bun": ["@types/bun@1.2.8", "", { "dependencies": { "bun-types": "1.2.7" } }, "sha512-t8L1RvJVUghW5V+M/fL3Thbxcs0HwNsXsnTEBEfEVqGteiJToOlZ/fyOEaR1kZsNqnu+3XA4RI/qmnX4w6+S+w=="],
|
|
25
25
|
|
|
26
26
|
"@types/hast": ["@types/hast@3.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ=="],
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
|
|
33
33
|
|
|
34
|
-
"bun-types": ["bun-types@1.2.
|
|
34
|
+
"bun-types": ["bun-types@1.2.7", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-P4hHhk7kjF99acXqKvltyuMQ2kf/rzIw3ylEDpCxDS9Xa0X0Yp/gJu/vDCucmWpiur5qJ0lwB2bWzOXa2GlHqA=="],
|
|
35
35
|
|
|
36
36
|
"chalk": ["chalk@5.4.1", "", {}, "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w=="],
|
|
37
37
|
|
package/index.ts
CHANGED
|
@@ -67,6 +67,11 @@ export type { default as SyntaxHighlighterService } from "./src/api/service/core
|
|
|
67
67
|
export { default as DefaultSyntaxHighlighterService } from "./src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.ts";
|
|
68
68
|
export { default as SyntaxHighlighterServiceProvider } from "./src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.ts";
|
|
69
69
|
|
|
70
|
+
export { PRETTY_PRINTER_SERVICE_ID } from "./src/api/service/core/PrettyPrinterService.ts";
|
|
71
|
+
export type { default as PrettyPrinterService } from "./src/api/service/core/PrettyPrinterService.ts";
|
|
72
|
+
export { default as DefaultPrettyPrinterService } from "./src/service/prettyPrinter/DefaultPrettyPrinterService.ts";
|
|
73
|
+
export { default as PrettyPrinterServiceProvider } from "./src/service/prettyPrinter/PrettyPrinterServiceProvider.ts";
|
|
74
|
+
|
|
70
75
|
// CLI API
|
|
71
76
|
export type { InvalidArgument } from "./src/api/RunResult.ts";
|
|
72
77
|
export type { default as Context } from "./src/api/Context.ts";
|
package/package.json
CHANGED
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
],
|
|
19
19
|
"module": "index.ts",
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "1.1.
|
|
21
|
+
"version": "1.1.2",
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/bun": "^1.2.
|
|
26
|
+
"@types/bun": "^1.2.8"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"typescript": "^5.8.2"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const PRETTY_PRINTER_SERVICE_ID =
|
|
2
2
|
"@flowscripter/dynamic-cli-framework/pretty-printer-service";
|
|
3
3
|
|
|
4
|
-
import type { Plugin
|
|
4
|
+
import type { Plugin } from "prettier";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Service providing syntax based pretty printing of text for the CLI using [prettier](https://github.com/prettier/prettier).
|
|
@@ -20,11 +20,11 @@ export default interface PrettyPrinterService {
|
|
|
20
20
|
* * https://prettier.io/docs/plugins
|
|
21
21
|
*
|
|
22
22
|
* @param syntaxName the name used to refer to the syntax.
|
|
23
|
-
* @param syntaxDefinition the definition for the syntax conforming to the Prettier plugin
|
|
23
|
+
* @param syntaxDefinition the definition for the syntax conforming to the Prettier plugin interface.
|
|
24
24
|
*/
|
|
25
25
|
registerSyntax(
|
|
26
26
|
syntaxName: string,
|
|
27
|
-
syntaxDefinition:
|
|
27
|
+
syntaxDefinition: Plugin<unknown>,
|
|
28
28
|
): Promise<void>;
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type PrettyPrinterService from "../../api/service/core/PrettyPrinterService.ts";
|
|
2
2
|
import * as prettier from "prettier";
|
|
3
|
-
import type { Plugin
|
|
3
|
+
import type { Plugin } from "prettier";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Default implementation of {@link PrettyPrinterService} which
|
|
7
|
-
*
|
|
6
|
+
* Default implementation of {@link PrettyPrinterService} which provides by default the
|
|
7
|
+
* syntaxes built into prettier.
|
|
8
8
|
*/
|
|
9
9
|
export default class DefaultPrettyPrinterService
|
|
10
10
|
implements PrettyPrinterService {
|
|
11
11
|
#registeredSyntaxes = new Array<string>();
|
|
12
|
-
#
|
|
12
|
+
#syntaxNameToPluginnMap = new Map<string, Plugin>();
|
|
13
13
|
|
|
14
14
|
async #populateBuiltInSyntaxes(): Promise<void> {
|
|
15
15
|
const languages = (await prettier.getSupportInfo()).languages;
|
|
@@ -38,11 +38,11 @@ export default class DefaultPrettyPrinterService
|
|
|
38
38
|
|
|
39
39
|
const options: prettier.Options = { parser: syntaxName };
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const syntaxPlugin = this.#syntaxNameToPluginnMap.get(
|
|
42
42
|
name,
|
|
43
43
|
);
|
|
44
|
-
if (
|
|
45
|
-
options.plugins = [
|
|
44
|
+
if (syntaxPlugin) {
|
|
45
|
+
options.plugins = [syntaxPlugin];
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return prettier.format(text, options);
|
|
@@ -50,7 +50,7 @@ export default class DefaultPrettyPrinterService
|
|
|
50
50
|
|
|
51
51
|
async registerSyntax(
|
|
52
52
|
syntaxName: string,
|
|
53
|
-
|
|
53
|
+
syntaxPlugin: Plugin,
|
|
54
54
|
): Promise<void> {
|
|
55
55
|
if (this.#registeredSyntaxes.length === 0) {
|
|
56
56
|
await this.#populateBuiltInSyntaxes();
|
|
@@ -62,6 +62,6 @@ export default class DefaultPrettyPrinterService
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
this.#registeredSyntaxes.push(name);
|
|
65
|
-
this.#
|
|
65
|
+
this.#syntaxNameToPluginnMap.set(name, syntaxPlugin);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -46,21 +46,25 @@ export default class LogLevelCommand implements GlobalModifierCommand {
|
|
|
46
46
|
|
|
47
47
|
switch (logLevel) {
|
|
48
48
|
case "DEBUG":
|
|
49
|
-
|
|
49
|
+
this.#printerServiceProvider.printerService!.setLevel(
|
|
50
50
|
Level.DEBUG,
|
|
51
51
|
);
|
|
52
|
+
break;
|
|
52
53
|
case "INFO":
|
|
53
|
-
|
|
54
|
+
this.#printerServiceProvider.printerService!.setLevel(
|
|
54
55
|
Level.INFO,
|
|
55
56
|
);
|
|
57
|
+
break;
|
|
56
58
|
case "WARN":
|
|
57
|
-
|
|
59
|
+
this.#printerServiceProvider.printerService!.setLevel(
|
|
58
60
|
Level.WARN,
|
|
59
61
|
);
|
|
62
|
+
break;
|
|
60
63
|
case "ERROR":
|
|
61
|
-
|
|
64
|
+
this.#printerServiceProvider.printerService!.setLevel(
|
|
62
65
|
Level.ERROR,
|
|
63
66
|
);
|
|
67
|
+
break;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
return Promise.resolve();
|
package/src/util/logger.ts
CHANGED
|
@@ -28,28 +28,17 @@ let maxLoggerNameLength = 0;
|
|
|
28
28
|
const LOGGER_NAME_PADDINGS: Record<string, string> = {};
|
|
29
29
|
|
|
30
30
|
function getDefaultLogger(): Logger {
|
|
31
|
-
if (debugEnabled) {
|
|
32
|
-
return {
|
|
33
|
-
trace: () => {},
|
|
34
|
-
debug: (message, ...optionalParams) => {
|
|
35
|
-
console.debug(message, ...optionalParams);
|
|
36
|
-
},
|
|
37
|
-
info: (message, ...optionalParams) => {
|
|
38
|
-
console.info(message, ...optionalParams);
|
|
39
|
-
},
|
|
40
|
-
warn: (message, ...optionalParams) => {
|
|
41
|
-
console.warn(message, ...optionalParams);
|
|
42
|
-
},
|
|
43
|
-
error: (message, ...optionalParams) => {
|
|
44
|
-
console.error(message, ...optionalParams);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
31
|
return {
|
|
49
32
|
trace: () => {},
|
|
50
|
-
debug: () => {
|
|
51
|
-
|
|
52
|
-
|
|
33
|
+
debug: (message, ...optionalParams) => {
|
|
34
|
+
console.debug(message, ...optionalParams);
|
|
35
|
+
},
|
|
36
|
+
info: (message, ...optionalParams) => {
|
|
37
|
+
console.info(message, ...optionalParams);
|
|
38
|
+
},
|
|
39
|
+
warn: (message, ...optionalParams) => {
|
|
40
|
+
console.warn(message, ...optionalParams);
|
|
41
|
+
},
|
|
53
42
|
error: (message, ...optionalParams) => {
|
|
54
43
|
console.error(message, ...optionalParams);
|
|
55
44
|
},
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Parser, Plugin, Printer, SupportLanguage } from "prettier";
|
|
2
|
+
|
|
3
|
+
const languages: SupportLanguage[] = [
|
|
2
4
|
{
|
|
3
5
|
name: "foo",
|
|
4
6
|
parsers: ["foo"],
|
|
5
7
|
},
|
|
6
8
|
];
|
|
7
9
|
|
|
8
|
-
const parsers = {
|
|
10
|
+
const parsers: Record<string, Parser> = {
|
|
9
11
|
foo: {
|
|
10
12
|
astFormat: "foo",
|
|
11
13
|
parse: () => "",
|
|
@@ -14,14 +16,16 @@ const parsers = {
|
|
|
14
16
|
},
|
|
15
17
|
};
|
|
16
18
|
|
|
17
|
-
const printers = {
|
|
19
|
+
const printers: Record<string, Printer> = {
|
|
18
20
|
"foo": {
|
|
19
21
|
print: () => "foo",
|
|
20
22
|
},
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
const prettierPluginFoo: Plugin = {
|
|
24
26
|
languages,
|
|
25
27
|
parsers,
|
|
26
28
|
printers,
|
|
27
29
|
};
|
|
30
|
+
|
|
31
|
+
export default prettierPluginFoo;
|