Skip to content

Commit 0ae1bfd

Browse files
committed
BREAKING CHANGE: Total refactor with cli colors, extensible plugins and npm package.
1 parent 3d3d986 commit 0ae1bfd

38 files changed

+8398
-1584
lines changed

.env

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
LANGUAGE=en
2-
DEBUG_LOG=false
1+
MENU_LANGUAGE=en
2+
DEBUG_LOG=false
3+
DIR_PLUGINS=./src/plugins

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write # Permette push di tag e modifiche al repository
10+
issues: write # Permette di creare/modificare issue (per note di rilascio)
11+
pull-requests: write # Opzionale, per gestire PR
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '22'
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Build
33+
run: npm run build
34+
35+
- name: Release
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
run: npx semantic-release
40+
41+
- name: Sync dev branch with main
42+
if: success()
43+
run: |
44+
git fetch origin dev:dev || git checkout -b dev
45+
git checkout dev
46+
git pull origin dev || true
47+
git merge main --ff-only || (git merge main && git push origin dev)
48+
git push origin dev

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
src/
2+
*.ts
3+
tests/
4+
node_modules/
5+
.gitignore
6+
.github/
7+
tsconfig.json

.releaserc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"branches": ["main"],
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
"@semantic-release/release-notes-generator",
6+
"@semantic-release/changelog",
7+
"@semantic-release/npm",
8+
"@semantic-release/git",
9+
"@semantic-release/github"
10+
]
11+
}

README.md

Lines changed: 199 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,232 @@
1-
# Modular CLI Menu System
1+
# Modular CLI Menu
22

3-
A flexible and extensible command-line interface menu system built with TypeScript, designed to be easily extendable through plugins.
3+
A TypeScript library for creating modular and interactive CLI menus with plugin support and internationalization.
44

5-
## Overview
5+
## Installation
66

7-
This project provides a modular framework for creating interactive CLI menus with support for:
7+
```bash
8+
npm install modular-cli-menu
9+
```
810

9-
- Multi-language support (currently English and Italian)
10-
- Plugin-based architecture for easy extension
11-
- Hierarchical menu navigation
12-
- Environment configuration
11+
## Key Features
1312

14-
## Features
13+
- 🔌 Modular plugin system
14+
- 🌍 Multi-language support (i18n)
15+
- 🎨 Customizable menu colors
16+
- 🔄 Hierarchical menu navigation
17+
- ⌨️ Interactive input with different question types
18+
- 📦 Easily extensible
1519

16-
- **Plugin System**: Extend functionality by adding new plugins with their own menus and actions
17-
- **Internationalization**: Full multi-language support with automatic translation loading
18-
- **Configurable Navigation**: Define how users navigate through menus after actions complete
19-
- **Dynamic Menu Loading**: Menus and actions are loaded dynamically at runtime
20+
## Basic Usage
2021

21-
## Project Structure
22+
```typescript
23+
import { print, write } from 'modular-cli-menu';
2224

25+
// Start the main menu
26+
print();
27+
28+
// Use write for custom messages
29+
write('Hello World', 'green');
2330
```
24-
.
25-
├── languages/ # Global translations
26-
│ ├── en.json # English translations
27-
│ └── it.json # Italian translations
28-
├── plugins/ # Plugin modules
29-
│ ├── settings/ # Settings plugin
30-
│ └── show-info/ # Information display plugin
31-
├── src/
32-
│ ├── actions/ # Core actions
33-
│ ├── classes/ # Core classes (Menu, MenuItem, etc.)
34-
│ ├── interfaces/ # TypeScript interfaces
35-
│ ├── utils/ # Utility functions
36-
│ └── index.ts # Application entry point
37-
├── .env # Default environment configuration
38-
└── .env.local # Local environment overrides
31+
32+
### Using print and write Methods
33+
34+
The library provides two main methods for output:
35+
36+
- `print()`: Initializes and displays the menu interface
37+
- `write(message: string, color?: ColorName)`: Prints custom messages with optional styling
38+
```typescript
39+
write('Success!', 'green');
40+
write('Error!', 'red');
41+
```
42+
43+
## Creating and Registering Plugins
44+
45+
To create a new plugin, define an object implementing the `PluginType` interface:
46+
47+
```typescript
48+
import { addPlugin } from 'modular-cli-menu';
49+
import type { PluginType, ActionType } from 'modular-cli-menu';
50+
51+
const myPlugin: PluginType = {
52+
menu: {
53+
name: 'myplugin', // Unique menu name
54+
parent: 'main', // Parent menu (optional)
55+
color: 'blue', // Menu color (optional)
56+
choices: [ // Array of available actions
57+
'menu.myplugin.action1',
58+
'menu.myplugin.action2',
59+
'menu.action.back'
60+
]
61+
},
62+
actions: {
63+
'menu.myplugin.action1': {
64+
type: 'function',
65+
name: 'menu.myplugin.action1',
66+
color: 'green',
67+
options: {
68+
message: {
69+
text: 'Action 1 executed!',
70+
color: 'green'
71+
}
72+
}
73+
}
74+
},
75+
languages: {
76+
en: {
77+
'menu.myplugin.question': 'My Plugin',
78+
'menu.myplugin.action1': 'Execute Action 1',
79+
'menu.myplugin.action2': 'Execute Action 2'
80+
}
81+
}
82+
};
3983
```
4084

41-
## How It Works
85+
In the main file remember to register the plugin
86+
```typescript
87+
import module1 from './plugins/myPlugin/index.ts';
88+
import { addPlugin, print } from 'modular-cli-menu';
4289

43-
The application loads menus from configuration files (`menu.json`) found in both the core application and plugins. Each menu item can either lead to a submenu or execute an action.
90+
addPlugin(myPlugin);
4491

45-
### Environment Variables
92+
print();
93+
```
4694

47-
- `LANGUAGE`: Sets the default language (e.g., "en" or "it")
48-
- `DEBUG_LOG`: When set to "true", enables detailed logging
95+
## Navigation and Control Methods
4996

50-
## Adding a New Plugin
97+
The library provides several methods for menu navigation and control:
5198

52-
To add a new plugin:
99+
### actionExit
53100

54-
1. Create a new directory under `/plugins/`
55-
2. Add a `menu.json` file defining menu structure
56-
3. Add language files under `/languages/` directory
57-
4. Implement actions as TypeScript files in an `actions/` subdirectory
101+
`menu.action.exit` can be used to terminate the application.
102+
Add it to your menu's choices:
58103

59-
## Getting Started
104+
```typescript
105+
import { actionExit } from 'modular-cli-menu';
60106

61-
### Prerequisites
107+
const myPlugin: PluginType = {
108+
menu: {
109+
name: 'myplugin',
110+
choices: [
111+
'menu.myplugin.action1',
112+
'menu.action.exit' // This will add an exit option to your menu
113+
]
114+
},
115+
// ... rest of the plugin configuration
116+
};
117+
```
62118

63-
- Node.js (v14 or higher)
64-
- npm or yarn
119+
### actionGoBack
65120

66-
### Installation
121+
`menu.action.back` can be used to navigate to the previous menu.
122+
Add it to your menu's choices:
67123

68-
```bash
69-
# Clone the repository
70-
git clone https://github.com/BlorisL/modular-cli-menu.git
124+
```typescript
125+
import { actionGoBack } from 'modular-cli-menu';
71126

72-
# Navigate to project directory
73-
cd modular-cli-menu
127+
const myPlugin: PluginType = {
128+
menu: {
129+
name: 'myplugin',
130+
choices: [
131+
'menu.myplugin.action1',
132+
'menu.action.back' // This will add a "back" option to your menu
133+
]
134+
},
135+
// ... rest of the plugin configuration
136+
};
137+
```
74138

75-
# Install dependencies
76-
npm install
139+
### waitForKeyPress
77140

78-
# Start the application
79-
npm start
141+
Use `waitForKeyPress()` to pause execution until the user presses a key:
142+
143+
```typescript
144+
import { waitForKeyPress } from 'modular-cli-menu';
145+
146+
const myAction: ActionType = {
147+
type: 'function',
148+
options: {
149+
callback: async (parent?:) => {
150+
await waitForKeyPress();
151+
// Continue with the next actions
152+
}
153+
}
154+
};
80155
```
81156

82-
## Configuration
157+
## Action Types
158+
159+
The library supports different types of actions:
160+
161+
1. **function**: Executes a callback function
162+
2. **input**: Requests user input
163+
3. **checkbox**: Allows multiple selections
164+
4. **goto**: Navigates to another menu
165+
166+
### Function Action Example
167+
168+
```typescript
169+
{
170+
type: 'function',
171+
name: 'myAction',
172+
color: 'green',
173+
options: {
174+
message: {
175+
text: 'Action executed!',
176+
color: 'green'
177+
},
178+
callback: async () => {
179+
// Your logic here
180+
}
181+
}
182+
}
183+
```
83184

84-
You can customize the application by creating a `.env.local` file based on the `.env.example` template.
185+
### Input Action Example
186+
187+
```typescript
188+
{
189+
type: 'input',
190+
name: 'inputAction',
191+
color: 'yellow',
192+
options: {
193+
message: {
194+
text: 'Enter a value:',
195+
color: 'yellow'
196+
},
197+
callback: async (value, parent) => {
198+
console.log(`Entered value: ${value}`);
199+
}
200+
}
201+
}
202+
```
85203

86-
## License
204+
### Checkbox Action Example
205+
206+
```typescript
207+
{
208+
type: 'checkbox',
209+
name: 'checkboxAction',
210+
options: {
211+
choices: ['Option 1', 'Option 2', 'Option 3'],
212+
callback: async (selected) => {
213+
console.log('Selected options:', selected);
214+
}
215+
}
216+
}
217+
```
218+
219+
### Goto Action Example
87220

88-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
221+
```typescript
222+
{
223+
type: 'goto',
224+
name: 'gotoAction',
225+
options: {
226+
menu: 'targetMenuName'
227+
}
228+
}
229+
```
89230

90231
## Support me
91232

0 commit comments

Comments
 (0)