codecrypto-cli 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.
@@ -0,0 +1,49 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+
5
+ export const deployCommand = new Command('deploy')
6
+ .description('Deploy your application to different environments')
7
+ .option('-e, --env <environment>', 'Environment to deploy (dev, staging, prod)', 'dev')
8
+ .option('-b, --branch <branch>', 'Git branch to deploy', 'main')
9
+ .option('-r, --region <region>', 'AWS region', 'us-east-1')
10
+ .option('--skip-tests', 'Skip running tests before deployment', false)
11
+ .option('--dry-run', 'Simulate deployment without actually deploying', false)
12
+ .action(async (options) => {
13
+ console.log(chalk.blue('\nšŸš€ CodeCrypto Deployment\n'));
14
+
15
+ console.log(chalk.gray('Deployment Configuration:'));
16
+ console.log(chalk.white(` Environment: ${chalk.green(options.env)}`));
17
+ console.log(chalk.white(` Branch: ${chalk.green(options.branch)}`));
18
+ console.log(chalk.white(` Region: ${chalk.green(options.region)}`));
19
+ console.log(chalk.white(` Skip Tests: ${options.skipTests ? chalk.yellow('Yes') : chalk.green('No')}`));
20
+ console.log(chalk.white(` Dry Run: ${options.dryRun ? chalk.yellow('Yes') : chalk.green('No')}`));
21
+
22
+ if (options.dryRun) {
23
+ console.log(chalk.yellow('\nāš ļø Running in dry-run mode. No actual deployment will occur.\n'));
24
+ }
25
+
26
+ // Simular proceso de deployment
27
+ const spinner = ora('Preparing deployment...').start();
28
+
29
+ await sleep(1000);
30
+ spinner.text = 'Building application...';
31
+
32
+ await sleep(1500);
33
+ if (!options.skipTests) {
34
+ spinner.text = 'Running tests...';
35
+ await sleep(1000);
36
+ }
37
+
38
+ await sleep(1000);
39
+ spinner.text = `Deploying to ${options.env}...`;
40
+
41
+ await sleep(2000);
42
+ spinner.succeed(chalk.green(`āœ… Successfully deployed to ${options.env}!`));
43
+
44
+ console.log(chalk.gray('\nšŸ“¦ Deployment URL:'), chalk.cyan(`https://${options.env}.codecrypto.com`));
45
+ });
46
+
47
+ function sleep(ms: number): Promise<void> {
48
+ return new Promise(resolve => setTimeout(resolve, ms));
49
+ }
@@ -0,0 +1,122 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import inquirer from 'inquirer';
4
+
5
+ export const userCommand = new Command('user')
6
+ .description('Manage users in the system');
7
+
8
+ // Subcomando: crear usuario
9
+ userCommand
10
+ .command('create')
11
+ .description('Create a new user')
12
+ .option('-u, --username <username>', 'Username')
13
+ .option('-e, --email <email>', 'Email address')
14
+ .option('-r, --role <role>', 'User role (admin, user, guest)', 'user')
15
+ .option('--interactive', 'Interactive mode', false)
16
+ .action(async (options) => {
17
+ console.log(chalk.blue('\nšŸ‘¤ Create New User\n'));
18
+
19
+ let userData = {
20
+ username: options.username,
21
+ email: options.email,
22
+ role: options.role
23
+ };
24
+
25
+ // Modo interactivo
26
+ if (options.interactive || !options.username || !options.email) {
27
+ const answers = await inquirer.prompt([
28
+ {
29
+ type: 'input',
30
+ name: 'username',
31
+ message: 'Enter username:',
32
+ default: options.username,
33
+ validate: (input) => input.length > 0 || 'Username is required'
34
+ },
35
+ {
36
+ type: 'input',
37
+ name: 'email',
38
+ message: 'Enter email:',
39
+ default: options.email,
40
+ validate: (input) => {
41
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
42
+ return emailRegex.test(input) || 'Invalid email format';
43
+ }
44
+ },
45
+ {
46
+ type: 'list',
47
+ name: 'role',
48
+ message: 'Select role:',
49
+ choices: ['admin', 'user', 'guest'],
50
+ default: options.role
51
+ }
52
+ ]);
53
+
54
+ userData = { ...userData, ...answers };
55
+ }
56
+
57
+ console.log(chalk.green('\nāœ… User created successfully!'));
58
+ console.log(chalk.gray('User details:'));
59
+ console.log(chalk.white(` Username: ${chalk.cyan(userData.username)}`));
60
+ console.log(chalk.white(` Email: ${chalk.cyan(userData.email)}`));
61
+ console.log(chalk.white(` Role: ${chalk.cyan(userData.role)}`));
62
+ });
63
+
64
+ // Subcomando: listar usuarios
65
+ userCommand
66
+ .command('list')
67
+ .description('List all users')
68
+ .option('-r, --role <role>', 'Filter by role')
69
+ .option('-l, --limit <number>', 'Limit number of results', '10')
70
+ .action((options) => {
71
+ console.log(chalk.blue('\nšŸ“‹ User List\n'));
72
+
73
+ if (options.role) {
74
+ console.log(chalk.gray(`Filtering by role: ${chalk.cyan(options.role)}`));
75
+ }
76
+
77
+ // Datos de ejemplo
78
+ const users = [
79
+ { id: 1, username: 'john_doe', email: 'john@example.com', role: 'admin' },
80
+ { id: 2, username: 'jane_smith', email: 'jane@example.com', role: 'user' },
81
+ { id: 3, username: 'bob_wilson', email: 'bob@example.com', role: 'user' }
82
+ ];
83
+
84
+ const filteredUsers = options.role
85
+ ? users.filter(u => u.role === options.role)
86
+ : users;
87
+
88
+ const limitedUsers = filteredUsers.slice(0, parseInt(options.limit));
89
+
90
+ limitedUsers.forEach(user => {
91
+ console.log(chalk.white(` ${user.id}. ${chalk.cyan(user.username)} (${user.email}) - ${chalk.yellow(user.role)}`));
92
+ });
93
+
94
+ console.log(chalk.gray(`\nTotal: ${limitedUsers.length} users\n`));
95
+ });
96
+
97
+ // Subcomando: eliminar usuario
98
+ userCommand
99
+ .command('delete <userId>')
100
+ .description('Delete a user by ID')
101
+ .option('-f, --force', 'Skip confirmation', false)
102
+ .action(async (userId, options) => {
103
+ console.log(chalk.blue('\nšŸ—‘ļø Delete User\n'));
104
+
105
+ if (!options.force) {
106
+ const { confirm } = await inquirer.prompt([
107
+ {
108
+ type: 'confirm',
109
+ name: 'confirm',
110
+ message: `Are you sure you want to delete user ${userId}?`,
111
+ default: false
112
+ }
113
+ ]);
114
+
115
+ if (!confirm) {
116
+ console.log(chalk.yellow('āŒ Operation cancelled\n'));
117
+ return;
118
+ }
119
+ }
120
+
121
+ console.log(chalk.green(`āœ… User ${userId} deleted successfully!\n`));
122
+ });
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { deployCommand } from './commands/deploy';
5
+ import { userCommand } from './commands/user';
6
+ import { configCommand } from './commands/config';
7
+ import { dbCommand } from './commands/database';
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .name('codecrypto')
13
+ .description('CLI tool for CodeCrypto operations')
14
+ .version('1.0.0');
15
+
16
+ // Registrar comandos
17
+ program.addCommand(deployCommand);
18
+ program.addCommand(userCommand);
19
+ program.addCommand(configCommand);
20
+ program.addCommand(dbCommand);
21
+
22
+ program.parse(process.argv);
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }