@flowscripter/example-cli-plugin 0.0.1

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 ADDED
@@ -0,0 +1,102 @@
1
+ # example-cli-plugin
2
+
3
+ [![version](https://img.shields.io/github/v/release/flowscripter/example-cli-plugin?sort=semver)](https://github.com/flowscripter/example-cli-plugin/releases)
4
+ [![build](https://img.shields.io/github/actions/workflow/status/flowscripter/example-cli-plugin/release-bun-library.yml)](https://github.com/flowscripter/example-cli-plugin/actions/workflows/release-bun-library.yml)
5
+ [![coverage](https://codecov.io/gh/flowscripter/example-cli-plugin/branch/main/graph/badge.svg?token=EMFT2938ZF)](https://codecov.io/gh/flowscripter/example-cli-plugin)
6
+ [![docs](https://img.shields.io/badge/docs-API-blue)](https://flowscripter.github.io/example-cli-plugin/index.html)
7
+ [![license: MIT](https://img.shields.io/github/license/flowscripter/example-cli-plugin)](https://github.com/flowscripter/example-cli-plugin/blob/main/LICENSE)
8
+
9
+ > Example CLI plugin for the
10
+ > [dynamic-cli-framework](https://github.com/flowscripter/dynamic-cli-framework)
11
+
12
+ ## Development
13
+
14
+ Build (produces `dist/` for Node.js and TypeScript consumers; Bun uses raw source directly):
15
+
16
+ `bun run build`
17
+
18
+ Test:
19
+
20
+ `bun test`
21
+
22
+ Format:
23
+
24
+ `bunx oxfmt`
25
+
26
+ Lint:
27
+
28
+ `bunx oxlint index.ts src/ tests/`
29
+
30
+ Generate HTML API Documentation:
31
+
32
+ `bunx typedoc index.ts`
33
+
34
+ ## Documentation
35
+
36
+ ### Overview
37
+
38
+ ```mermaid
39
+ classDiagram
40
+ class Plugin {
41
+ <<interface>>
42
+ +extensionDescriptors: ExtensionDescriptor[]
43
+ }
44
+
45
+ class DemoCommandFactory {
46
+ <<CommandFactory>>
47
+ +getCommands() SubCommand[]
48
+ }
49
+
50
+ class DemoServiceProviderFactory {
51
+ <<ServiceProviderFactory>>
52
+ +getServiceProviders() ServiceProvider[]
53
+ }
54
+
55
+ class DemoServiceProvider {
56
+ <<ServiceProvider>>
57
+ +serviceId: string
58
+ +servicePriority: number
59
+ +getServiceInfo(cliConfig) ServiceInfo
60
+ +initService(context) void
61
+ }
62
+
63
+ class DemoService {
64
+ <<interface>>
65
+ +greet(name: string) string
66
+ }
67
+
68
+ class DefaultDemoService {
69
+ +greet(name: string) string
70
+ }
71
+
72
+ class helloCommand {
73
+ <<SubCommand>>
74
+ +name: "hello"
75
+ +positionals: name
76
+ +execute(context, argumentValues) void
77
+ }
78
+
79
+ Plugin --> DemoCommandFactory : extensionDescriptor
80
+ Plugin --> DemoServiceProviderFactory : extensionDescriptor
81
+ DemoCommandFactory --> helloCommand : getCommands()
82
+ DemoServiceProviderFactory --> DemoServiceProvider : getServiceProviders()
83
+ DemoServiceProvider --> DefaultDemoService : creates
84
+ DefaultDemoService ..|> DemoService
85
+ helloCommand --> DemoService : uses via context
86
+ ```
87
+
88
+ ### Framework API
89
+
90
+ Refer to the
91
+ [dynamic-cli-framework](https://github.com/flowscripter/dynamic-cli-framework)
92
+ for an overview of what this example is demonstrating.
93
+
94
+ ### API
95
+
96
+ Link to auto-generated API docs:
97
+
98
+ [API Documentation](https://flowscripter.github.io/example-cli-plugin/index.html)
99
+
100
+ ## License
101
+
102
+ MIT © Flowscripter
@@ -0,0 +1,2 @@
1
+ export { default } from "./src/plugin.ts";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ // @bun
2
+ // ../dynamic-cli-framework/src/api/plugin/CommandFactory.ts
3
+ var DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT = "DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY";
4
+ // ../dynamic-cli-framework/src/api/plugin/ServiceProviderFactory.ts
5
+ var DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT = "DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY";
6
+ // src/service/DemoService.ts
7
+ var DEMO_SERVICE_ID = "DEMO_SERVICE";
8
+
9
+ // src/command/HelloCommand.ts
10
+ var helloCommand = {
11
+ name: "hello",
12
+ description: "Greet someone using the demo service",
13
+ enableConfiguration: false,
14
+ options: [],
15
+ positionals: [
16
+ {
17
+ name: "name",
18
+ description: "Name to greet",
19
+ type: 0 /* STRING */,
20
+ isVarargOptional: true
21
+ }
22
+ ],
23
+ execute: async (context, argumentValues) => {
24
+ const demoService = context.getServiceById(DEMO_SERVICE_ID);
25
+ const name = argumentValues["name"] ?? "World";
26
+ const greeting = demoService ? demoService.greet(name) : `Hello, ${name}!`;
27
+ console.log(greeting);
28
+ }
29
+ };
30
+ var HelloCommand_default = helloCommand;
31
+
32
+ // src/factory/DemoCommandFactory.ts
33
+ class DemoCommandFactory {
34
+ getCommands() {
35
+ return [HelloCommand_default];
36
+ }
37
+ }
38
+
39
+ // src/service/DefaultDemoService.ts
40
+ class DefaultDemoService {
41
+ greet(name) {
42
+ return `Hello, ${name}!`;
43
+ }
44
+ }
45
+
46
+ // src/service/DemoServiceProvider.ts
47
+ class DemoServiceProvider {
48
+ serviceId = DEMO_SERVICE_ID;
49
+ servicePriority = 10;
50
+ async getServiceInfo(_cliConfig) {
51
+ return { service: new DefaultDemoService, commands: [] };
52
+ }
53
+ async initService(_context) {}
54
+ }
55
+
56
+ // src/factory/DemoServiceProviderFactory.ts
57
+ class DemoServiceProviderFactory {
58
+ getServiceProviders() {
59
+ return [new DemoServiceProvider];
60
+ }
61
+ }
62
+
63
+ // src/plugin.ts
64
+ var plugin = {
65
+ extensionDescriptors: [
66
+ {
67
+ extensionPoint: DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
68
+ factory: { create: async () => new DemoCommandFactory }
69
+ },
70
+ {
71
+ extensionPoint: DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
72
+ factory: { create: async () => new DemoServiceProviderFactory }
73
+ }
74
+ ]
75
+ };
76
+ var plugin_default = plugin;
77
+ export {
78
+ plugin_default as default
79
+ };
@@ -0,0 +1,4 @@
1
+ import type { SubCommand } from "@flowscripter/dynamic-cli-framework/plugin";
2
+ declare const helloCommand: SubCommand;
3
+ export default helloCommand;
4
+ //# sourceMappingURL=HelloCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HelloCommand.d.ts","sourceRoot":"","sources":["../../../src/command/HelloCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAGX,MAAM,4CAA4C,CAAC;AAKpD,QAAA,MAAM,YAAY,EAAE,UAmBnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { CommandFactory } from "@flowscripter/dynamic-cli-framework/plugin";
2
+ export default class DemoCommandFactory implements CommandFactory {
3
+ getCommands(): import("@flowscripter/dynamic-cli-framework/plugin").SubCommand[];
4
+ }
5
+ //# sourceMappingURL=DemoCommandFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoCommandFactory.d.ts","sourceRoot":"","sources":["../../../src/factory/DemoCommandFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAGjF,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,cAAc;IAC/D,WAAW;CAGZ"}
@@ -0,0 +1,6 @@
1
+ import type { ServiceProviderFactory } from "@flowscripter/dynamic-cli-framework/plugin";
2
+ import DemoServiceProvider from "../service/DemoServiceProvider.ts";
3
+ export default class DemoServiceProviderFactory implements ServiceProviderFactory {
4
+ getServiceProviders(): DemoServiceProvider[];
5
+ }
6
+ //# sourceMappingURL=DemoServiceProviderFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoServiceProviderFactory.d.ts","sourceRoot":"","sources":["../../../src/factory/DemoServiceProviderFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,mBAAmB,MAAM,mCAAmC,CAAC;AAEpE,MAAM,CAAC,OAAO,OAAO,0BAA2B,YAAW,sBAAsB;IAC/E,mBAAmB;CAGpB"}
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "@flowscripter/dynamic-plugin-framework";
2
+ declare const plugin: Plugin;
3
+ export default plugin;
4
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AAQrE,QAAA,MAAM,MAAM,EAAE,MAWb,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type DemoService from "./DemoService.ts";
2
+ export default class DefaultDemoService implements DemoService {
3
+ greet(name: string): string;
4
+ }
5
+ //# sourceMappingURL=DefaultDemoService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultDemoService.d.ts","sourceRoot":"","sources":["../../../src/service/DefaultDemoService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,WAAW;IAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAG5B"}
@@ -0,0 +1,5 @@
1
+ export declare const DEMO_SERVICE_ID = "DEMO_SERVICE";
2
+ export default interface DemoService {
3
+ greet(name: string): string;
4
+ }
5
+ //# sourceMappingURL=DemoService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoService.d.ts","sourceRoot":"","sources":["../../../src/service/DemoService.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,iBAAiB,CAAC;AAE9C,MAAM,CAAC,OAAO,WAAW,WAAW;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,8 @@
1
+ import type { ServiceProvider, ServiceInfo, CLIConfig, Context } from "@flowscripter/dynamic-cli-framework/plugin";
2
+ export default class DemoServiceProvider implements ServiceProvider {
3
+ readonly serviceId = "DEMO_SERVICE";
4
+ readonly servicePriority = 10;
5
+ getServiceInfo(_cliConfig: CLIConfig): Promise<ServiceInfo>;
6
+ initService(_context: Context): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=DemoServiceProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoServiceProvider.d.ts","sourceRoot":"","sources":["../../../src/service/DemoServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,SAAS,EACT,OAAO,EACR,MAAM,4CAA4C,CAAC;AAIpD,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,eAAe;IACjE,QAAQ,CAAC,SAAS,kBAAmB;IACrC,QAAQ,CAAC,eAAe,MAAM;IAExB,cAAc,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC;IAI3D,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CACpD"}
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from "./src/plugin.ts";
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@flowscripter/example-cli-plugin",
3
+ "version": "0.0.1",
4
+ "description": "Example CLI plugin for the https://github.com/flowscripter/dynamic-cli-framework",
5
+ "keywords": [
6
+ "bun",
7
+ "cli",
8
+ "dynamic",
9
+ "dynamic-cli-framework",
10
+ "example",
11
+ "plugin"
12
+ ],
13
+ "homepage": "https://github.com/flowscripter/example-cli-plugin#readme",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/flowscripter/example-cli-plugin.git"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src",
22
+ "index.ts",
23
+ "cli-plugin.ts",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "type": "module",
28
+ "main": "dist/index.js",
29
+ "module": "dist/index.js",
30
+ "types": "dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "bun": "./index.ts",
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "build": "bun build index.ts --outdir dist --target bun && tsc -p tsconfig.build.json"
43
+ },
44
+ "dependencies": {
45
+ "@flowscripter/dynamic-plugin-framework": "1.9.0"
46
+ },
47
+ "devDependencies": {
48
+ "@flowscripter/dynamic-cli-framework": "1.6.1",
49
+ "@types/bun": "^1.3.14",
50
+ "oxfmt": "0.56.0",
51
+ "oxlint": "1.71.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@flowscripter/dynamic-cli-framework": "*",
55
+ "typescript": "^6.0.3"
56
+ },
57
+ "dynamic-cli-framework": {
58
+ "extensionPoints": [
59
+ "DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY",
60
+ "DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY"
61
+ ]
62
+ }
63
+ }
@@ -0,0 +1,31 @@
1
+ import type {
2
+ SubCommand,
3
+ Context,
4
+ ArgumentValues,
5
+ } from "@flowscripter/dynamic-cli-framework/plugin";
6
+ import { ArgumentValueTypeName } from "@flowscripter/dynamic-cli-framework/plugin";
7
+ import { DEMO_SERVICE_ID } from "../service/DemoService.ts";
8
+ import type DemoService from "../service/DemoService.ts";
9
+
10
+ const helloCommand: SubCommand = {
11
+ name: "hello",
12
+ description: "Greet someone using the demo service",
13
+ enableConfiguration: false,
14
+ options: [],
15
+ positionals: [
16
+ {
17
+ name: "name",
18
+ description: "Name to greet",
19
+ type: ArgumentValueTypeName.STRING,
20
+ isVarargOptional: true,
21
+ },
22
+ ],
23
+ execute: async (context: Context, argumentValues: ArgumentValues) => {
24
+ const demoService = context.getServiceById(DEMO_SERVICE_ID) as DemoService | undefined;
25
+ const name = (argumentValues["name"] as string | undefined) ?? "World";
26
+ const greeting = demoService ? demoService.greet(name) : `Hello, ${name}!`;
27
+ console.log(greeting);
28
+ },
29
+ };
30
+
31
+ export default helloCommand;
@@ -0,0 +1,8 @@
1
+ import type { CommandFactory } from "@flowscripter/dynamic-cli-framework/plugin";
2
+ import helloCommand from "../command/HelloCommand.ts";
3
+
4
+ export default class DemoCommandFactory implements CommandFactory {
5
+ getCommands() {
6
+ return [helloCommand];
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import type { ServiceProviderFactory } from "@flowscripter/dynamic-cli-framework/plugin";
2
+ import DemoServiceProvider from "../service/DemoServiceProvider.ts";
3
+
4
+ export default class DemoServiceProviderFactory implements ServiceProviderFactory {
5
+ getServiceProviders() {
6
+ return [new DemoServiceProvider()];
7
+ }
8
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from "@flowscripter/dynamic-plugin-framework";
2
+ import {
3
+ DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
4
+ DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
5
+ } from "@flowscripter/dynamic-cli-framework/plugin";
6
+ import DemoCommandFactory from "./factory/DemoCommandFactory.ts";
7
+ import DemoServiceProviderFactory from "./factory/DemoServiceProviderFactory.ts";
8
+
9
+ const plugin: Plugin = {
10
+ extensionDescriptors: [
11
+ {
12
+ extensionPoint: DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
13
+ factory: { create: async () => new DemoCommandFactory() },
14
+ },
15
+ {
16
+ extensionPoint: DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
17
+ factory: { create: async () => new DemoServiceProviderFactory() },
18
+ },
19
+ ],
20
+ };
21
+
22
+ export default plugin;
@@ -0,0 +1,7 @@
1
+ import type DemoService from "./DemoService.ts";
2
+
3
+ export default class DefaultDemoService implements DemoService {
4
+ greet(name: string): string {
5
+ return `Hello, ${name}!`;
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ export const DEMO_SERVICE_ID = "DEMO_SERVICE";
2
+
3
+ export default interface DemoService {
4
+ greet(name: string): string;
5
+ }
@@ -0,0 +1,19 @@
1
+ import type {
2
+ ServiceProvider,
3
+ ServiceInfo,
4
+ CLIConfig,
5
+ Context,
6
+ } from "@flowscripter/dynamic-cli-framework/plugin";
7
+ import { DEMO_SERVICE_ID } from "./DemoService.ts";
8
+ import DefaultDemoService from "./DefaultDemoService.ts";
9
+
10
+ export default class DemoServiceProvider implements ServiceProvider {
11
+ readonly serviceId = DEMO_SERVICE_ID;
12
+ readonly servicePriority = 10;
13
+
14
+ async getServiceInfo(_cliConfig: CLIConfig): Promise<ServiceInfo> {
15
+ return { service: new DefaultDemoService(), commands: [] };
16
+ }
17
+
18
+ async initService(_context: Context): Promise<void> {}
19
+ }