@flowscripter/dynamic-cli-framework 6.0.1 → 7.0.0
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/README.md +2 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/src/cli/BaseCLI.d.ts +8 -0
- package/dist/src/cli/BaseCLI.d.ts.map +1 -1
- package/dist/src/cli/BaseCLI.js +37 -4
- package/dist/src/launcher.d.ts +3 -3
- package/dist/src/launcher.d.ts.map +1 -1
- package/dist/src/launcher.js +6 -4
- package/dist/src/runtime/lifecycle/PriorityTaskList.d.ts +22 -0
- package/dist/src/runtime/lifecycle/PriorityTaskList.d.ts.map +1 -0
- package/dist/src/runtime/lifecycle/PriorityTaskList.js +23 -0
- package/dist/src/runtime/runner.d.ts +15 -7
- package/dist/src/runtime/runner.d.ts.map +1 -1
- package/dist/src/runtime/runner.js +82 -53
- package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts +26 -82
- package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts.map +1 -1
- package/dist/src/service/configuration/ConfigurationServiceProvider.js +68 -163
- package/dist/src/service/configuration/DefaultKeyValueService.d.ts +6 -3
- package/dist/src/service/configuration/DefaultKeyValueService.d.ts.map +1 -1
- package/dist/src/service/configuration/DefaultKeyValueService.js +7 -24
- package/dist/src/service/configuration/DefaultSecretService.d.ts +1 -3
- package/dist/src/service/configuration/DefaultSecretService.d.ts.map +1 -1
- package/dist/src/service/configuration/DefaultSecretService.js +2 -10
- package/dist/src/service/configuration/KeyValueServiceProvider.d.ts +105 -0
- package/dist/src/service/configuration/KeyValueServiceProvider.d.ts.map +1 -0
- package/dist/src/service/configuration/KeyValueServiceProvider.js +201 -0
- package/dist/src/service/configuration/command/ConfigCommand.d.ts +4 -5
- package/dist/src/service/configuration/command/ConfigCommand.d.ts.map +1 -1
- package/dist/src/service/configuration/command/ConfigCommand.js +7 -6
- package/dist/src/service/configuration/command/DumpConfigCommand.d.ts +7 -3
- package/dist/src/service/configuration/command/DumpConfigCommand.d.ts.map +1 -1
- package/dist/src/service/configuration/command/DumpConfigCommand.js +10 -5
- package/dist/src/service/fetch/DefaultFetchService.d.ts +2 -2
- package/dist/src/service/fetch/DefaultFetchService.d.ts.map +1 -1
- package/dist/src/service/fetch/DefaultFetchService.js +17 -12
- package/dist/src/service/fetch/FetchServiceProvider.d.ts.map +1 -1
- package/dist/src/service/fetch/FetchServiceProvider.js +2 -3
- package/dist/src/service/printer/PrinterServiceProvider.d.ts.map +1 -1
- package/dist/src/service/printer/PrinterServiceProvider.js +11 -7
- package/dist/src/service/printer/command/DarkModeCommand.d.ts +3 -5
- package/dist/src/service/printer/command/DarkModeCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/DarkModeCommand.js +6 -6
- package/dist/src/service/printer/command/LogLevelCommand.d.ts +3 -5
- package/dist/src/service/printer/command/LogLevelCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/LogLevelCommand.js +9 -9
- package/dist/src/service/printer/command/NoColorCommand.d.ts +3 -5
- package/dist/src/service/printer/command/NoColorCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/NoColorCommand.js +6 -6
- package/dist/src/service/printer/command/NoHyperlinksCommand.d.ts +2 -4
- package/dist/src/service/printer/command/NoHyperlinksCommand.d.ts.map +1 -1
- package/dist/src/service/printer/command/NoHyperlinksCommand.js +5 -5
- package/dist/src/service/prompter/PrompterServiceProvider.js +1 -1
- package/dist/src/service/prompter/command/NoPromptCommand.d.ts +2 -4
- package/dist/src/service/prompter/command/NoPromptCommand.d.ts.map +1 -1
- package/dist/src/service/prompter/command/NoPromptCommand.js +5 -5
- package/dist/src/service/shutdown/DefaultShutdownService.d.ts +4 -3
- package/dist/src/service/shutdown/DefaultShutdownService.d.ts.map +1 -1
- package/dist/src/service/shutdown/DefaultShutdownService.js +4 -3
- package/dist/src/service/shutdown/ShutdownServiceProvider.js +2 -2
- package/dist/src/service/spawn/DefaultSpawnService.d.ts +2 -2
- package/dist/src/service/spawn/DefaultSpawnService.d.ts.map +1 -1
- package/dist/src/service/spawn/DefaultSpawnService.js +17 -14
- package/dist/src/service/spawn/SpawnServiceProvider.d.ts.map +1 -1
- package/dist/src/service/spawn/SpawnServiceProvider.js +1 -4
- package/dist/src/service/startup/DefaultStartupService.d.ts +10 -0
- package/dist/src/service/startup/DefaultStartupService.d.ts.map +1 -0
- package/dist/src/service/startup/DefaultStartupService.js +13 -0
- package/dist/src/service/startup/StartupServiceProvider.d.ts +17 -0
- package/dist/src/service/startup/StartupServiceProvider.d.ts.map +1 -0
- package/dist/src/service/startup/StartupServiceProvider.js +26 -0
- package/dist/src/service/upgrade/DefaultUpgradeService.d.ts +10 -4
- package/dist/src/service/upgrade/DefaultUpgradeService.d.ts.map +1 -1
- package/dist/src/service/upgrade/DefaultUpgradeService.js +156 -37
- package/dist/src/service/upgrade/UpgradeServiceProvider.d.ts +10 -0
- package/dist/src/service/upgrade/UpgradeServiceProvider.d.ts.map +1 -1
- package/dist/src/service/upgrade/UpgradeServiceProvider.js +25 -6
- package/dist/src/service/upgrade/command/UpgradeSubCommand.d.ts +0 -3
- package/dist/src/service/upgrade/command/UpgradeSubCommand.d.ts.map +1 -1
- package/dist/src/service/upgrade/command/UpgradeSubCommand.js +5 -13
- package/dist/src/startup/banner/bannerStartupTask.d.ts +17 -0
- package/dist/src/startup/banner/bannerStartupTask.d.ts.map +1 -0
- package/dist/src/startup/banner/bannerStartupTask.js +66 -0
- package/dist/src/{service → startup}/banner/command/NoBannerCommand.d.ts +8 -2
- package/dist/src/startup/banner/command/NoBannerCommand.d.ts.map +1 -0
- package/dist/src/{service → startup}/banner/command/NoBannerCommand.js +4 -4
- package/index.ts +19 -3
- package/package.json +2 -2
- package/src/cli/BaseCLI.ts +49 -3
- package/src/launcher.ts +7 -2
- package/src/runtime/lifecycle/PriorityTaskList.ts +34 -0
- package/src/runtime/runner.ts +106 -67
- package/src/service/configuration/ConfigurationServiceProvider.ts +80 -180
- package/src/service/configuration/DefaultKeyValueService.ts +8 -27
- package/src/service/configuration/DefaultSecretService.ts +3 -13
- package/src/service/configuration/KeyValueServiceProvider.ts +246 -0
- package/src/service/configuration/command/ConfigCommand.ts +12 -11
- package/src/service/configuration/command/DumpConfigCommand.ts +10 -9
- package/src/service/fetch/DefaultFetchService.ts +18 -12
- package/src/service/fetch/FetchServiceProvider.ts +2 -4
- package/src/service/printer/PrinterServiceProvider.ts +11 -7
- package/src/service/printer/command/DarkModeCommand.ts +7 -8
- package/src/service/printer/command/LogLevelCommand.ts +10 -11
- package/src/service/printer/command/NoColorCommand.ts +7 -8
- package/src/service/printer/command/NoHyperlinksCommand.ts +6 -7
- package/src/service/prompter/PrompterServiceProvider.ts +1 -1
- package/src/service/prompter/command/NoPromptCommand.ts +6 -7
- package/src/service/shutdown/DefaultShutdownService.ts +5 -4
- package/src/service/shutdown/ShutdownServiceProvider.ts +2 -2
- package/src/service/spawn/DefaultSpawnService.ts +18 -14
- package/src/service/spawn/SpawnServiceProvider.ts +1 -5
- package/src/service/startup/DefaultStartupService.ts +17 -0
- package/src/service/startup/StartupServiceProvider.ts +36 -0
- package/src/service/upgrade/DefaultUpgradeService.ts +202 -42
- package/src/service/upgrade/UpgradeServiceProvider.ts +31 -8
- package/src/service/upgrade/command/UpgradeSubCommand.ts +5 -15
- package/src/startup/banner/bannerStartupTask.ts +96 -0
- package/src/{service → startup}/banner/command/NoBannerCommand.ts +12 -5
- package/dist/src/service/banner/BannerServiceProvider.d.ts +0 -29
- package/dist/src/service/banner/BannerServiceProvider.d.ts.map +0 -1
- package/dist/src/service/banner/BannerServiceProvider.js +0 -69
- package/dist/src/service/banner/command/NoBannerCommand.d.ts.map +0 -1
- package/src/service/banner/BannerServiceProvider.ts +0 -89
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Context,
|
|
3
|
+
KeyValueService,
|
|
4
|
+
PrinterService,
|
|
5
|
+
StartupTask,
|
|
6
|
+
UpgradeCheckResult,
|
|
7
|
+
} from "@flowscripter/dynamic-cli-framework-api";
|
|
8
|
+
import {
|
|
9
|
+
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
10
|
+
CONFIGURATION_SERVICE_ID,
|
|
11
|
+
KEY_VALUE_SERVICE_ID,
|
|
12
|
+
PRINTER_SERVICE_ID,
|
|
13
|
+
} from "@flowscripter/dynamic-cli-framework-api";
|
|
14
|
+
import type { AsciiBannerGeneratorService } from "@flowscripter/dynamic-cli-framework-api";
|
|
15
|
+
import type { ConfigurationService } from "@flowscripter/dynamic-cli-framework-api";
|
|
16
|
+
import { UPGRADE_CHECK_CACHE_KEY } from "../../service/upgrade/DefaultUpgradeService.ts";
|
|
17
|
+
import NoBannerCommand, { type BannerState } from "./command/NoBannerCommand.ts";
|
|
18
|
+
|
|
19
|
+
export const BANNER_STARTUP_TASK_ID = "@flowscripter/dynamic-cli-framework/banner-startup-task";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Build the ascii banner {@link StartupTask}, replacing the old `BannerServiceProvider`.
|
|
23
|
+
*
|
|
24
|
+
* A consumer opts in by passing the result of this function in the `serviceProviders` array
|
|
25
|
+
* argument of {@link launchMultiCommandCLI}/{@link launchSingleCommandCLI} (or via
|
|
26
|
+
* `BaseCLI.addStartupTask`), the same way `new BannerServiceProvider(priority)` used to be passed
|
|
27
|
+
* in that array - there's no default/automatic banner registration.
|
|
28
|
+
*
|
|
29
|
+
* @param priority the priority of the task (higher runs earlier - the same semantics
|
|
30
|
+
* `BannerServiceProvider.servicePriority` had).
|
|
31
|
+
* @param fontName an optional [FIGlet](http://www.figlet.org) font name to use for the banner,
|
|
32
|
+
* defaults to "standard".
|
|
33
|
+
*/
|
|
34
|
+
export default function createBannerStartupTask(
|
|
35
|
+
priority: number,
|
|
36
|
+
fontName = "standard",
|
|
37
|
+
): StartupTask {
|
|
38
|
+
const state: BannerState = { printBanner: true };
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
id: BANNER_STARTUP_TASK_ID,
|
|
42
|
+
priority,
|
|
43
|
+
mode: "blocking",
|
|
44
|
+
modifierCommands: [new NoBannerCommand(state, priority)],
|
|
45
|
+
run: async (context: Context): Promise<void> => {
|
|
46
|
+
if (!state.printBanner) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
51
|
+
|
|
52
|
+
const asciiBannerGeneratorService = context.getServiceById(
|
|
53
|
+
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
54
|
+
) as AsciiBannerGeneratorService;
|
|
55
|
+
|
|
56
|
+
const { cliConfig } = context;
|
|
57
|
+
const bannerText = await asciiBannerGeneratorService.generate(cliConfig.name.toUpperCase(), {
|
|
58
|
+
fontName,
|
|
59
|
+
subMessage: cliConfig.subMessage,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await printerService.info(printerService.blue(bannerText));
|
|
63
|
+
if (cliConfig.description !== undefined) {
|
|
64
|
+
await printerService.info(` ${printerService.primary(cliConfig.description)}\n`);
|
|
65
|
+
}
|
|
66
|
+
if (cliConfig.version.length > 0) {
|
|
67
|
+
let versionLine = "version: " + cliConfig.version;
|
|
68
|
+
// Cheap cache read only - never calls checkForUpgrade()/getUpgradeCheckResult() live,
|
|
69
|
+
// since that could stall startup on a network/spawn call. A first-ever run (no cached
|
|
70
|
+
// key yet) simply shows no upgrade-available suffix - that's expected, not a bug.
|
|
71
|
+
if (context.doesServiceExist(KEY_VALUE_SERVICE_ID)) {
|
|
72
|
+
const keyValueService = context.getServiceById(KEY_VALUE_SERVICE_ID) as KeyValueService;
|
|
73
|
+
if (await keyValueService.has(UPGRADE_CHECK_CACHE_KEY)) {
|
|
74
|
+
const result = (await keyValueService.get(
|
|
75
|
+
UPGRADE_CHECK_CACHE_KEY,
|
|
76
|
+
)) as unknown as UpgradeCheckResult;
|
|
77
|
+
if (result.status === "checked" && result.updateAvailable) {
|
|
78
|
+
versionLine += ` (${result.latestVersion} available, run '${cliConfig.name} upgrade')`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
await printerService.info(` ${printerService.secondary(versionLine)}\n`);
|
|
83
|
+
}
|
|
84
|
+
if (context.doesServiceExist(CONFIGURATION_SERVICE_ID)) {
|
|
85
|
+
const configurationService = context.getServiceById(
|
|
86
|
+
CONFIGURATION_SERVICE_ID,
|
|
87
|
+
) as ConfigurationService;
|
|
88
|
+
const configLocation = configurationService.configLocation;
|
|
89
|
+
if (configLocation && configLocation.length > 0) {
|
|
90
|
+
await printerService.info(` ${printerService.secondary("config: " + configLocation)}\n`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
await printerService.info("\n");
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -2,7 +2,14 @@ import type { GlobalModifierCommand } from "@flowscripter/dynamic-cli-framework-
|
|
|
2
2
|
import { type SingleValueType, ValueTypeName } from "@flowscripter/dynamic-cli-framework-api";
|
|
3
3
|
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
4
4
|
import type { GlobalCommandArgument } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Task-local, mutable state shared between {@link NoBannerCommand} and the banner
|
|
8
|
+
* {@link StartupTask}'s `run()`, in place of a held `BannerServiceProvider` reference.
|
|
9
|
+
*/
|
|
10
|
+
export interface BannerState {
|
|
11
|
+
printBanner: boolean;
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
/**
|
|
8
15
|
* Command to disable banner output for the CLI application.
|
|
@@ -18,15 +25,15 @@ export default class NoBannerCommand implements GlobalModifierCommand {
|
|
|
18
25
|
};
|
|
19
26
|
readonly executePriority: number;
|
|
20
27
|
|
|
21
|
-
readonly #
|
|
28
|
+
readonly #state: BannerState;
|
|
22
29
|
|
|
23
|
-
public constructor(
|
|
24
|
-
this.#
|
|
30
|
+
public constructor(state: BannerState, executePriority: number) {
|
|
31
|
+
this.#state = state;
|
|
25
32
|
this.executePriority = executePriority;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
public execute(_context: Context, argumentValue: SingleValueType): Promise<void> {
|
|
29
|
-
this.#
|
|
36
|
+
this.#state.printBanner = !(argumentValue as boolean);
|
|
30
37
|
|
|
31
38
|
return Promise.resolve();
|
|
32
39
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
|
-
import type { ServiceInfo, ServiceProvider } from "@flowscripter/dynamic-cli-framework-api";
|
|
3
|
-
import type ConfigurationServiceProvider from "../configuration/ConfigurationServiceProvider.ts";
|
|
4
|
-
import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
|
-
export declare const BANNER_SERVICE_ID = "@flowscripter/dynamic-cli-framework/banner-service";
|
|
6
|
-
/**
|
|
7
|
-
* Provides ascii banner functionality.
|
|
8
|
-
*/
|
|
9
|
-
export default class BannerServiceProvider implements ServiceProvider {
|
|
10
|
-
#private;
|
|
11
|
-
private readonly fontName;
|
|
12
|
-
readonly serviceId: string;
|
|
13
|
-
readonly servicePriority: number;
|
|
14
|
-
/**
|
|
15
|
-
* Whether or not to print the banner, defaults to true.
|
|
16
|
-
*/
|
|
17
|
-
printBanner: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Create an instance of the service provider with the specified details.
|
|
20
|
-
*
|
|
21
|
-
* @param servicePriority the priority of the service.
|
|
22
|
-
* @param configurationServiceProvider an optional {@link ConfigurationServiceProvider} to make use of.
|
|
23
|
-
* @param fontName an optional [FIGlet](http://www.figlet.org) font name to use for the banner, defaults to "standard".
|
|
24
|
-
*/
|
|
25
|
-
constructor(servicePriority: number, configurationServiceProvider?: ConfigurationServiceProvider, fontName?: string);
|
|
26
|
-
getServiceInfo(_cliConfig: CLIConfig): Promise<ServiceInfo>;
|
|
27
|
-
initService(context: Context): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=BannerServiceProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BannerServiceProvider.d.ts","sourceRoot":"","sources":["../../../../src/service/banner/BannerServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAI5F,OAAO,KAAK,4BAA4B,MAAM,kDAAkD,CAAC;AAGjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,eAAO,MAAM,iBAAiB,uDAAuD,CAAC;AAEtF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,eAAe;;IAoBjE,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAnB3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAqB;IAC/C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAGjC;;OAEG;IACH,WAAW,UAAQ;IAEnB;;;;;;OAMG;IACH,YACE,eAAe,EAAE,MAAM,EACvB,4BAA4B,CAAC,EAAE,4BAA4B,EAC1C,QAAQ,GAAE,MAAmB,EAI/C;IAEM,cAAc,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAIjE;IAEK,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCjD;CACF"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import NoBannerCommand from "./command/NoBannerCommand.js";
|
|
2
|
-
import { PRINTER_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
3
|
-
import { ASCII_BANNER_GENERATOR_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
4
|
-
import { UPGRADE_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
|
-
export const BANNER_SERVICE_ID = "@flowscripter/dynamic-cli-framework/banner-service";
|
|
6
|
-
/**
|
|
7
|
-
* Provides ascii banner functionality.
|
|
8
|
-
*/
|
|
9
|
-
export default class BannerServiceProvider {
|
|
10
|
-
fontName;
|
|
11
|
-
serviceId = BANNER_SERVICE_ID;
|
|
12
|
-
servicePriority;
|
|
13
|
-
#configurationServiceProvider;
|
|
14
|
-
/**
|
|
15
|
-
* Whether or not to print the banner, defaults to true.
|
|
16
|
-
*/
|
|
17
|
-
printBanner = true;
|
|
18
|
-
/**
|
|
19
|
-
* Create an instance of the service provider with the specified details.
|
|
20
|
-
*
|
|
21
|
-
* @param servicePriority the priority of the service.
|
|
22
|
-
* @param configurationServiceProvider an optional {@link ConfigurationServiceProvider} to make use of.
|
|
23
|
-
* @param fontName an optional [FIGlet](http://www.figlet.org) font name to use for the banner, defaults to "standard".
|
|
24
|
-
*/
|
|
25
|
-
constructor(servicePriority, configurationServiceProvider, fontName = "standard") {
|
|
26
|
-
this.fontName = fontName;
|
|
27
|
-
this.servicePriority = servicePriority;
|
|
28
|
-
this.#configurationServiceProvider = configurationServiceProvider;
|
|
29
|
-
}
|
|
30
|
-
getServiceInfo(_cliConfig) {
|
|
31
|
-
return Promise.resolve({
|
|
32
|
-
commands: [new NoBannerCommand(this, this.servicePriority)],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async initService(context) {
|
|
36
|
-
if (this.printBanner === false) {
|
|
37
|
-
return Promise.resolve();
|
|
38
|
-
}
|
|
39
|
-
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
40
|
-
const asciiBannerGeneratorService = context.getServiceById(ASCII_BANNER_GENERATOR_SERVICE_ID);
|
|
41
|
-
const { cliConfig } = context;
|
|
42
|
-
const bannerText = await asciiBannerGeneratorService.generate(cliConfig.name.toUpperCase(), {
|
|
43
|
-
fontName: this.fontName,
|
|
44
|
-
subMessage: cliConfig.subMessage,
|
|
45
|
-
});
|
|
46
|
-
await printerService.info(printerService.blue(bannerText));
|
|
47
|
-
if (cliConfig.description !== undefined) {
|
|
48
|
-
await printerService.info(` ${printerService.primary(cliConfig.description)}\n`);
|
|
49
|
-
}
|
|
50
|
-
if (cliConfig.version.length > 0) {
|
|
51
|
-
let versionLine = "version: " + cliConfig.version;
|
|
52
|
-
if (context.doesServiceExist(UPGRADE_SERVICE_ID)) {
|
|
53
|
-
const upgradeService = context.getServiceById(UPGRADE_SERVICE_ID);
|
|
54
|
-
const result = await upgradeService.getUpgradeCheckResult();
|
|
55
|
-
if (result.status === "checked" && result.updateAvailable) {
|
|
56
|
-
versionLine += ` (${result.latestVersion} available, run '${cliConfig.name} upgrade')`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
await printerService.info(` ${printerService.secondary(versionLine)}\n`);
|
|
60
|
-
}
|
|
61
|
-
if (this.#configurationServiceProvider) {
|
|
62
|
-
const configLocation = this.#configurationServiceProvider.configLocation;
|
|
63
|
-
if (configLocation && configLocation.length > 0) {
|
|
64
|
-
await printerService.info(` ${printerService.secondary("config: " + configLocation)}\n`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
await printerService.info("\n");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NoBannerCommand.d.ts","sourceRoot":"","sources":["../../../../../src/service/banner/command/NoBannerCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,yCAAyC,CAAC;AAC9F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,KAAK,qBAAqB,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,YAAW,qBAAqB;;IACnE,QAAQ,CAAC,IAAI,eAAe;IAC5B,QAAQ,CAAC,WAAW,8BAA8B;IAClD,QAAQ,CAAC,mBAAmB,QAAQ;IACpC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAItC;IACF,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAIjC,YAAmB,qBAAqB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,EAGvF;IAEM,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/E;CACF"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
|
-
import type { ServiceInfo, ServiceProvider } from "@flowscripter/dynamic-cli-framework-api";
|
|
3
|
-
import NoBannerCommand from "./command/NoBannerCommand.ts";
|
|
4
|
-
import type { PrinterService } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
|
-
import { PRINTER_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
6
|
-
import type ConfigurationServiceProvider from "../configuration/ConfigurationServiceProvider.ts";
|
|
7
|
-
import type { AsciiBannerGeneratorService } from "@flowscripter/dynamic-cli-framework-api";
|
|
8
|
-
import { ASCII_BANNER_GENERATOR_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
9
|
-
import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
|
|
10
|
-
import { UPGRADE_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
11
|
-
import type { UpgradeService } from "@flowscripter/dynamic-cli-framework-api";
|
|
12
|
-
export const BANNER_SERVICE_ID = "@flowscripter/dynamic-cli-framework/banner-service";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Provides ascii banner functionality.
|
|
16
|
-
*/
|
|
17
|
-
export default class BannerServiceProvider implements ServiceProvider {
|
|
18
|
-
readonly serviceId: string = BANNER_SERVICE_ID;
|
|
19
|
-
readonly servicePriority: number;
|
|
20
|
-
readonly #configurationServiceProvider: ConfigurationServiceProvider | undefined;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Whether or not to print the banner, defaults to true.
|
|
24
|
-
*/
|
|
25
|
-
printBanner = true;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Create an instance of the service provider with the specified details.
|
|
29
|
-
*
|
|
30
|
-
* @param servicePriority the priority of the service.
|
|
31
|
-
* @param configurationServiceProvider an optional {@link ConfigurationServiceProvider} to make use of.
|
|
32
|
-
* @param fontName an optional [FIGlet](http://www.figlet.org) font name to use for the banner, defaults to "standard".
|
|
33
|
-
*/
|
|
34
|
-
public constructor(
|
|
35
|
-
servicePriority: number,
|
|
36
|
-
configurationServiceProvider?: ConfigurationServiceProvider,
|
|
37
|
-
private readonly fontName: string = "standard",
|
|
38
|
-
) {
|
|
39
|
-
this.servicePriority = servicePriority;
|
|
40
|
-
this.#configurationServiceProvider = configurationServiceProvider;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public getServiceInfo(_cliConfig: CLIConfig): Promise<ServiceInfo> {
|
|
44
|
-
return Promise.resolve({
|
|
45
|
-
commands: [new NoBannerCommand(this, this.servicePriority)],
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async initService(context: Context): Promise<void> {
|
|
50
|
-
if (this.printBanner === false) {
|
|
51
|
-
return Promise.resolve();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
55
|
-
|
|
56
|
-
const asciiBannerGeneratorService = context.getServiceById(
|
|
57
|
-
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
58
|
-
) as AsciiBannerGeneratorService;
|
|
59
|
-
|
|
60
|
-
const { cliConfig } = context;
|
|
61
|
-
const bannerText = await asciiBannerGeneratorService.generate(cliConfig.name.toUpperCase(), {
|
|
62
|
-
fontName: this.fontName,
|
|
63
|
-
subMessage: cliConfig.subMessage,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
await printerService.info(printerService.blue(bannerText));
|
|
67
|
-
if (cliConfig.description !== undefined) {
|
|
68
|
-
await printerService.info(` ${printerService.primary(cliConfig.description)}\n`);
|
|
69
|
-
}
|
|
70
|
-
if (cliConfig.version.length > 0) {
|
|
71
|
-
let versionLine = "version: " + cliConfig.version;
|
|
72
|
-
if (context.doesServiceExist(UPGRADE_SERVICE_ID)) {
|
|
73
|
-
const upgradeService = context.getServiceById(UPGRADE_SERVICE_ID) as UpgradeService;
|
|
74
|
-
const result = await upgradeService.getUpgradeCheckResult();
|
|
75
|
-
if (result.status === "checked" && result.updateAvailable) {
|
|
76
|
-
versionLine += ` (${result.latestVersion} available, run '${cliConfig.name} upgrade')`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
await printerService.info(` ${printerService.secondary(versionLine)}\n`);
|
|
80
|
-
}
|
|
81
|
-
if (this.#configurationServiceProvider) {
|
|
82
|
-
const configLocation = this.#configurationServiceProvider.configLocation;
|
|
83
|
-
if (configLocation && configLocation.length > 0) {
|
|
84
|
-
await printerService.info(` ${printerService.secondary("config: " + configLocation)}\n`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
await printerService.info("\n");
|
|
88
|
-
}
|
|
89
|
-
}
|