@decaf-ts/cli 0.3.5 → 0.3.7

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/LICENSE.md CHANGED
@@ -1,157 +1,22 @@
1
- # GNU LESSER GENERAL PUBLIC LICENSE
1
+ MIT License
2
2
 
3
- Version 3, 29 June 2007
3
+ Copyright (c) 2025 Tiago Venceslau and Contributors
4
4
 
5
- Copyright (C) 2025 Tiago Venceslau
6
- <https:/github.com/TiagoVenceslau>
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
7
11
 
8
- Everyone is permitted to copy and distribute verbatim copies of this
9
- license document, but changing it is not allowed.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
10
14
 
11
- This version of the GNU Lesser General Public License incorporates the
12
- terms and conditions of version 3 of the GNU General Public License,
13
- supplemented by the additional permissions listed below.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
14
22
 
15
- ## 0. Additional Definitions.
16
-
17
- As used herein, "this License" refers to version 3 of the GNU Lesser
18
- General Public License, and the "GNU GPL" refers to version 3 of the
19
- GNU General Public License.
20
-
21
- "The Library" refers to a covered work governed by this License, other
22
- than an Application or a Combined Work as defined below.
23
-
24
- An "Application" is any work that makes use of an interface provided
25
- by the Library, but which is not otherwise based on the Library.
26
- Defining a subclass of a class defined by the Library is deemed a mode
27
- of using an interface provided by the Library.
28
-
29
- A "Combined Work" is a work produced by combining or linking an
30
- Application with the Library. The particular version of the Library
31
- with which the Combined Work was made is also called the "Linked
32
- Version".
33
-
34
- The "Minimal Corresponding Source" for a Combined Work means the
35
- Corresponding Source for the Combined Work, excluding any source code
36
- for portions of the Combined Work that, considered in isolation, are
37
- based on the Application, and not on the Linked Version.
38
-
39
- The "Corresponding Application Code" for a Combined Work means the
40
- object code and/or source code for the Application, including any data
41
- and utility programs needed for reproducing the Combined Work from the
42
- Application, but excluding the System Libraries of the Combined Work.
43
-
44
- ## 1. Exception to Section 3 of the GNU GPL.
45
-
46
- You may convey a covered work under sections 3 and 4 of this License
47
- without being bound by section 3 of the GNU GPL.
48
-
49
- ## 2. Conveying Modified Versions.
50
-
51
- If you modify a copy of the Library, and, in your modifications, a
52
- facility refers to a function or data to be supplied by an Application
53
- that uses the facility (other than as an argument passed when the
54
- facility is invoked), then you may convey a copy of the modified
55
- version:
56
-
57
- - a) under this License, provided that you make a good faith effort
58
- to ensure that, in the event an Application does not supply the
59
- function or data, the facility still operates, and performs
60
- whatever part of its purpose remains meaningful, or
61
- - b) under the GNU GPL, with none of the additional permissions of
62
- this License applicable to that copy.
63
-
64
- ## 3. Object Code Incorporating Material from Library Header Files.
65
-
66
- The object code form of an Application may incorporate material from a
67
- header file that is part of the Library. You may convey such object
68
- code under terms of your choice, provided that, if the incorporated
69
- material is not limited to numerical parameters, data structure
70
- layouts and accessors, or small macros, inline functions and templates
71
- (ten or fewer lines in length), you do both of the following:
72
-
73
- - a) Give prominent notice with each copy of the object code that
74
- the Library is used in it and that the Library and its use are
75
- covered by this License.
76
- - b) Accompany the object code with a copy of the GNU GPL and this
77
- license document.
78
-
79
- ## 4. Combined Works.
80
-
81
- You may convey a Combined Work under terms of your choice that, taken
82
- together, effectively do not restrict modification of the portions of
83
- the Library contained in the Combined Work and reverse engineering for
84
- debugging such modifications, if you also do each of the following:
85
-
86
- - a) Give prominent notice with each copy of the Combined Work that
87
- the Library is used in it and that the Library and its use are
88
- covered by this License.
89
- - b) Accompany the Combined Work with a copy of the GNU GPL and this
90
- license document.
91
- - c) For a Combined Work that displays copyright notices during
92
- execution, include the copyright notice for the Library among
93
- these notices, as well as a reference directing the user to the
94
- copies of the GNU GPL and this license document.
95
- - d) Do one of the following:
96
- - 0) Convey the Minimal Corresponding Source under the terms of
97
- this License, and the Corresponding Application Code in a form
98
- suitable for, and under terms that permit, the user to
99
- recombine or relink the Application with a modified version of
100
- the Linked Version to produce a modified Combined Work, in the
101
- manner specified by section 6 of the GNU GPL for conveying
102
- Corresponding Source.
103
- - 1) Use a suitable shared library mechanism for linking with
104
- the Library. A suitable mechanism is one that (a) uses at run
105
- time a copy of the Library already present on the user's
106
- computer system, and (b) will operate properly with a modified
107
- version of the Library that is interface-compatible with the
108
- Linked Version.
109
- - e) Provide Installation Information, but only if you would
110
- otherwise be required to provide such information under section 6
111
- of the GNU GPL, and only to the extent that such information is
112
- necessary to install and execute a modified version of the
113
- Combined Work produced by recombining or relinking the Application
114
- with a modified version of the Linked Version. (If you use option
115
- 4d0, the Installation Information must accompany the Minimal
116
- Corresponding Source and Corresponding Application Code. If you
117
- use option 4d1, you must provide the Installation Information in
118
- the manner specified by section 6 of the GNU GPL for conveying
119
- Corresponding Source.)
120
-
121
- ## 5. Combined Libraries.
122
-
123
- You may place library facilities that are a work based on the Library
124
- side by side in a single library together with other library
125
- facilities that are not Applications and are not covered by this
126
- License, and convey such a combined library under terms of your
127
- choice, if you do both of the following:
128
-
129
- - a) Accompany the combined library with a copy of the same work
130
- based on the Library, uncombined with any other library
131
- facilities, conveyed under the terms of this License.
132
- - b) Give prominent notice with the combined library that part of it
133
- is a work based on the Library, and explaining where to find the
134
- accompanying uncombined form of the same work.
135
-
136
- ## 6. Revised Versions of the GNU Lesser General Public License.
137
-
138
- The Free Software Foundation may publish revised and/or new versions
139
- of the GNU Lesser General Public License from time to time. Such new
140
- versions will be similar in spirit to the present version, but may
141
- differ in detail to address new problems or concerns.
142
-
143
- Each version is given a distinguishing version number. If the Library
144
- as you received it specifies that a certain numbered version of the
145
- GNU Lesser General Public License "or any later version" applies to
146
- it, you have the option of following the terms and conditions either
147
- of that published version or of any later version published by the
148
- Free Software Foundation. If the Library as you received it does not
149
- specify a version number of the GNU Lesser General Public License, you
150
- may choose any version of the GNU Lesser General Public License ever
151
- published by the Free Software Foundation.
152
-
153
- If the Library as you received it specifies that a proxy can decide
154
- whether future versions of the GNU Lesser General Public License shall
155
- apply, that proxy's public statement of acceptance of any version is
156
- permanent authorization for you to choose that version for the
157
- Library.
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  ![Banner](./workdocs/assets/Banner.png)
2
2
 
3
- ## Decaf-ts cli
3
+ ## Decaf-ts CLI
4
+
5
+ A modular command-line interface framework for Decaf-ts that dynamically discovers and loads CLI modules from different packages. The CLI provides a unified entry point (`decaf`) for executing commands from various Decaf modules, making it easy to extend with new functionality without modifying the core CLI code.
4
6
 
5
- Exposes global cli tool that consumes other modules' clis under a standard command `decaf`
6
7
 
7
8
  ![Licence](https://img.shields.io/github/license/decaf-ts/cli.svg?style=plastic)
8
9
  ![GitHub language count](https://img.shields.io/github/languages/count/decaf-ts/cli?style=plastic)
@@ -35,14 +36,168 @@ Documentation available [here](https://decaf-ts.github.io/cli/)
35
36
 
36
37
  ### Description
37
38
 
39
+ The Decaf-ts CLI is a powerful and extensible command-line interface framework designed to provide a unified entry point for all Decaf-ts modules. It enables developers to create modular CLI commands that can be discovered and executed through a single command-line tool.
40
+
41
+ #### Core Components
42
+
43
+ 1. **CliWrapper**: The central class that manages the discovery, loading, and execution of CLI modules. It:
44
+ - Crawls the filesystem to find CLI module files
45
+ - Dynamically loads modules using JavaScript's import system
46
+ - Registers commands with Commander.js
47
+ - Provides a simple API for running commands
48
+
49
+ 2. **CLIUtils**: A utility class that provides helper methods for:
50
+ - Loading modules from files
51
+ - Normalizing imports between ESM and CommonJS formats
52
+ - Retrieving package information (name, version)
53
+ - Initializing Commander.js commands
54
+
55
+ 3. **CLI Module System**: A standardized way for Decaf-ts packages to expose CLI functionality:
56
+ - Modules are discovered by filename (cli-module.js)
57
+ - Each module exports a function that returns a Commander.js Command object
58
+ - Modules can define their own subcommands and options
59
+
60
+ #### Key Features
61
+
62
+ - **Dynamic Discovery**: Automatically finds CLI modules in the project and its dependencies
63
+ - **Modular Architecture**: Each module can define its own commands independently
64
+ - **Extensible**: New commands can be added without modifying the core CLI code
65
+ - **Unified Interface**: All commands are accessible through the single `decaf` command
66
+ - **Self-documenting**: Leverages Commander.js to provide help text and usage information
67
+
68
+ #### Technical Details
69
+
70
+ The CLI uses a recursive filesystem crawler to find modules up to a configurable depth. It handles both ESM and CommonJS module formats, making it compatible with various JavaScript environments. The command structure follows the pattern:
71
+
72
+ ```
73
+ decaf <module> <command> [options]
74
+ ```
75
+
76
+ Where `<module>` is the name of a Decaf-ts module and `<command>` is a specific command provided by that module.
38
77
 
39
78
 
40
79
  ### How to Use
41
80
 
42
- - [Initial Setup](../../workdocs/tutorials/For%20Developers.md#_initial-setup_)
43
- - [Installation](../../workdocs/tutorials/For%20Developers.md#installation)
81
+ - [Initial Setup](./workdocs/tutorials/For%20Developers.md#_initial-setup_)
82
+ - [Installation](./workdocs/tutorials/For%20Developers.md#installation)
83
+
84
+ #### Using the CLI
85
+
86
+ The Decaf-ts CLI provides a unified command-line interface for all Decaf-ts modules. Here are some examples of how to use it:
87
+
88
+ ```bash
89
+ # Get general help
90
+ npx decaf help
91
+
92
+ # List all available modules
93
+ npx decaf list
94
+
95
+ # Get help for a specific module
96
+ npx decaf help <module-name>
97
+
98
+ # Run a command from a specific module
99
+ npx decaf <module-name> <command> [options]
100
+ ```
101
+
102
+ #### Creating a CLI Module
103
+
104
+ To create a CLI module for your Decaf-ts package, follow these steps:
105
+
106
+ 1. Create a file named `cli-module.ts` in your package:
107
+
108
+ ```typescript
109
+ import { Command } from "commander";
110
+
111
+ export default function myModule(): Command {
112
+ return new Command()
113
+ .command("hello <name>")
114
+ .description("Say hello to someone")
115
+ .action((name: string) => {
116
+ console.log(`Hello, ${name}!`);
117
+ });
118
+ }
119
+ ```
120
+
121
+ 2. Configure your TypeScript build to output the CLI module:
122
+
123
+ ```json
124
+ // tsconfig.cli.json
125
+ {
126
+ "extends": "./tsconfig.json",
127
+ "compilerOptions": {
128
+ "outDir": "./dist/cli"
129
+ },
130
+ "include": ["src/cli-module.ts"]
131
+ }
132
+ ```
133
+
134
+ 3. Add a build step to your package.json:
135
+
136
+ ```json
137
+ "scripts": {
138
+ "build:cli": "tsc --project tsconfig.cli.json"
139
+ }
140
+ ```
141
+
142
+ #### Using the CliWrapper Programmatically
143
+
144
+ You can also use the CliWrapper class programmatically in your own code:
145
+
146
+ ```typescript
147
+ import { CliWrapper } from "@decaf-ts/cli";
148
+
149
+ // Create a new CLI wrapper with custom options
150
+ const cli = new CliWrapper("./src", 2);
151
+
152
+ // Run the CLI with custom arguments
153
+ cli.run(process.argv)
154
+ .then(() => {
155
+ console.log("CLI commands executed successfully");
156
+ })
157
+ .catch((error) => {
158
+ console.error("Error executing CLI commands:", error);
159
+ });
160
+ ```
161
+
162
+ #### Using CLIUtils
163
+
164
+ The CLIUtils class provides utility methods for working with CLI modules:
165
+
166
+ ```typescript
167
+ import { CLIUtils } from "@decaf-ts/cli";
168
+ import { Command } from "commander";
169
+
170
+ // Initialize a Command object with package information
171
+ const command = new Command();
172
+ CLIUtils.initialize(command, "./path/to/package");
173
+
174
+ // Get package information
175
+ const version = CLIUtils.packageVersion("./path/to/package");
176
+ const name = CLIUtils.packageName("./path/to/package");
44
177
 
178
+ // Load a CLI module from a file
179
+ const modulePath = "./path/to/cli-module.js";
180
+ CLIUtils.loadFromFile(modulePath)
181
+ .then((module) => {
182
+ const command = module();
183
+ console.log("Loaded command:", command.name());
184
+ })
185
+ .catch((error) => {
186
+ console.error("Error loading module:", error);
187
+ });
188
+ ```
189
+
190
+ #### Demo CLI Module
45
191
 
192
+ The CLI package includes a demo module that shows how to create a simple command:
193
+
194
+ ```typescript
195
+ // Run the demo command
196
+ npx decaf demo command "hello world"
197
+
198
+ // Output:
199
+ // executed demo command with type variable: hello world
200
+ ```
46
201
 
47
202
 
48
203
  ### Related