ibrahi-cli-mangeer 1.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.
Files changed (3) hide show
  1. package/index.js +180 -0
  2. package/package.json +21 -0
  3. package/projects.json +22 -0
package/index.js ADDED
@@ -0,0 +1,180 @@
1
+
2
+ #! /usr/bin/env node
3
+
4
+ import { Command } from 'commander';
5
+ import inquirer from 'inquirer';
6
+ import fs from 'fs/promises';
7
+ import path from 'path';
8
+
9
+ const program = new Command();
10
+ const DATA_FILE = path.join(process.cwd(), 'projects.json');
11
+
12
+ // دالة لقراءة البيانات من الملف
13
+ async function readProjects() {
14
+ try {
15
+ const data = await fs.readFile(DATA_FILE, 'utf-8');
16
+ return JSON.parse(data);
17
+ } catch (error) {
18
+ return [];
19
+ }
20
+ }
21
+
22
+ // دالة لحفظ البيانات في الملف
23
+ async function saveProjects(projects) {
24
+ await fs.writeFile(DATA_FILE, JSON.stringify(projects, null, 2), 'utf-8');
25
+ }
26
+
27
+ // دالة لرسم جدول بسيط
28
+ function printTable(projects) {
29
+ console.log('\n' + '='.repeat(100));
30
+ console.log('| # | Project Name | Price | Status | Created At |');
31
+ console.log('='.repeat(100));
32
+
33
+ projects.forEach((project, index) => {
34
+ const num = String(index + 1).padEnd(2);
35
+ const name = (project.name || 'Unknown').substring(0, 20).padEnd(20);
36
+ const price = `$${(project.price || 0).toFixed(2)}`.padEnd(10);
37
+ const status = (project.status || 'Pending').padEnd(13);
38
+ const date = new Date(project.createdAt || Date.now()).toLocaleDateString('en-GB').padEnd(16);
39
+
40
+ console.log(`| ${num} | ${name} | ${price} | ${status} | ${date} |`);
41
+ });
42
+
43
+ console.log('='.repeat(100));
44
+
45
+ // الإحصائيات
46
+ const total = projects.reduce((sum, p) => sum + (p.price || 0), 0);
47
+ console.log(`\nTotal Projects: ${projects.length} | Total Value: $${total.toFixed(2)}\n`);
48
+ }
49
+
50
+ program
51
+ .name('ibrahim-manager')
52
+ .description('CLI to manage ibrahim projects')
53
+ .version('1.8.0');
54
+
55
+ program
56
+ .command('create <projectName>')
57
+ .description('Create a new ibrahim project')
58
+ .alias('c')
59
+ .action(async (projectName) => {
60
+ console.log('\nCreating a new ibrahim project...\n');
61
+
62
+ const answers = await inquirer.prompt([
63
+ {
64
+ type: 'confirm',
65
+ name: 'proceed',
66
+ message: `Do you want to create project "${projectName}"?`,
67
+ default: true
68
+ },
69
+ {
70
+ type: 'input',
71
+ name: 'price',
72
+ message: 'Enter the project price:',
73
+ validate: (input) => {
74
+ const num = parseFloat(input);
75
+ if (isNaN(num)) {
76
+ return 'Please enter a valid number';
77
+ }
78
+ return true;
79
+ }
80
+ },
81
+ {
82
+ type: 'list',
83
+ name: 'status',
84
+ message: 'Select project status:',
85
+ choices: ['Pending', 'In Progress', 'Completed'],
86
+ default: 'Pending'
87
+ }
88
+ ]);
89
+
90
+ if (answers.proceed) {
91
+ const projects = await readProjects();
92
+
93
+ const newProject = {
94
+ id: Date.now(),
95
+ name: projectName,
96
+ price: parseFloat(answers.price),
97
+ status: answers.status,
98
+ createdAt: new Date().toISOString()
99
+ };
100
+
101
+ projects.push(newProject);
102
+ await saveProjects(projects);
103
+
104
+ console.log(`\n✅ Project "${projectName}" created successfully!\n`);
105
+ } else {
106
+ console.log('\n❌ Project creation cancelled.\n');
107
+ }
108
+ });
109
+
110
+ // أمر لعرض جميع المشاريع
111
+ program
112
+ .command('list')
113
+ .description('List all projects')
114
+ .alias('l')
115
+ .action(async () => {
116
+ const projects = await readProjects();
117
+
118
+ if (projects.length === 0) {
119
+ console.log('\n⚠️ No projects found.\n');
120
+ return;
121
+ }
122
+
123
+ printTable(projects);
124
+ });
125
+
126
+ // أمر لحذف مشروع
127
+ program
128
+ .command('delete <projectName>')
129
+ .description('Delete a project')
130
+ .alias('d')
131
+ .action(async (projectName) => {
132
+ const projects = await readProjects();
133
+ const projectIndex = projects.findIndex(p => p.name === projectName);
134
+
135
+ if (projectIndex === -1) {
136
+ console.log(`\n❌ Project "${projectName}" not found.\n`);
137
+ return;
138
+ }
139
+
140
+ const confirm = await inquirer.prompt([
141
+ {
142
+ type: 'confirm',
143
+ name: 'delete',
144
+ message: `Are you sure you want to delete "${projectName}"?`,
145
+ default: false
146
+ }
147
+ ]);
148
+
149
+ if (confirm.delete) {
150
+ projects.splice(projectIndex, 1);
151
+ await saveProjects(projects);
152
+ console.log(`\n✅ Project "${projectName}" deleted successfully!\n`);
153
+ } else {
154
+ console.log('\n❌ Deletion cancelled.\n');
155
+ }
156
+ });
157
+
158
+ // أمر لمسح جميع المشاريع
159
+ program
160
+ .command('clear')
161
+ .description('Clear all projects')
162
+ .action(async () => {
163
+ const confirm = await inquirer.prompt([
164
+ {
165
+ type: 'confirm',
166
+ name: 'clear',
167
+ message: 'Are you sure you want to delete ALL projects?',
168
+ default: false
169
+ }
170
+ ]);
171
+
172
+ if (confirm.clear) {
173
+ await saveProjects([]);
174
+ console.log('\n✅ All projects cleared!\n');
175
+ } else {
176
+ console.log('\n❌ Operation cancelled.\n');
177
+ }
178
+ });
179
+
180
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "ibrahi-cli-mangeer",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "bin": "./index.js",
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "chalk": "^5.6.2",
14
+ "cli-table3": "^0.6.5",
15
+ "commander": "^14.0.2",
16
+ "inquirer": "^13.2.1"
17
+ },
18
+ "devDependencies": {},
19
+ "keywords": [],
20
+ "description": ""
21
+ }
package/projects.json ADDED
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "id": 1769379217415,
4
+ "name": "f",
5
+ "price": 432,
6
+ "createdAt": "2026-01-25T22:13:37.415Z"
7
+ },
8
+ {
9
+ "id": 1769379621977,
10
+ "name": "f",
11
+ "price": 3,
12
+ "status": "23",
13
+ "createdAt": "2026-01-25T22:20:21.978Z"
14
+ },
15
+ {
16
+ "id": 1769379717108,
17
+ "name": "hi",
18
+ "price": 43,
19
+ "status": "t",
20
+ "createdAt": "2026-01-25T22:21:57.108Z"
21
+ }
22
+ ]