-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·103 lines (87 loc) · 4.22 KB
/
cli.js
File metadata and controls
executable file
·103 lines (87 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env node
const { Command } = require('commander');
const inquirer = require('inquirer').default;
const fs = require('fs');
const path = require('path');
const os = require('os');
const { exec } = require('child_process');
const { loadPluginsAndCommands } = require('./utils/plugin-loader');
const program = new Command();
const pluginsDir = path.join(os.homedir(), '.li-fe-cli/plugins');
async function loadCommands() {
const commandsDir = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsDir).filter(file => file.endsWith('.js'));
const pluginsConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugins.json'), 'utf8'));
commandFiles.forEach(file => {
const command = require(`./commands/${file}`);
const pluginConfig = pluginsConfig.commands[command.command];
if (pluginConfig) {
program
.command(command.command)
.description(command.description)
.action(async (...args) => {
const versions = args.slice(0, -1).length > 0 ? args.slice(0, -1) : pluginConfig.versions || [];
await command.execute(versions);
});
}
});
return Object.keys(pluginsConfig.commands);
}
async function selectCommandInteractively() {
const plugins = loadPluginsAndCommands();
const choices = plugins
.filter(plugin => plugin.command && plugin.description)
.map(plugin => ({
name: `[${plugin.type}]: ${plugin.command} - ${plugin.description}`,
value: plugin
}));
if (choices.length === 0) {
console.log("Nenhum plugin válido encontrado.");
return;
}
const { selectedPlugin } = await inquirer.prompt([
{
type: 'list',
name: 'selectedPlugin',
message: 'Selecione um plugin para executar:',
choices
}
]);
if (selectedPlugin.prompt) {
const { userInput } = await inquirer.prompt([
{
type: selectedPlugin.prompt.type,
name: 'userInput',
message: selectedPlugin.prompt.message,
default: selectedPlugin.prompt.default || null
}
]);
const processedInput = selectedPlugin.prompt.processInput
? selectedPlugin.prompt.processInput(userInput)
: [userInput];
console.log(`Executando plugin: ${selectedPlugin.name} com args: ${processedInput}`);
await selectedPlugin.execute(processedInput);
} else {
console.log(`Executando plugin: ${selectedPlugin.name}`);
await selectedPlugin.execute();
}
}
// Função inicial do CLI
async function initCLI() {
console.log(`
░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓████████▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓██████▓▒░ ░▒▓█▓▒▒▓█▓▒░░▒▓███████▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓███████▓▒░░▒▓████████▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
`);
const commands = await loadCommands();
if (process.argv.length <= 2) {
await selectCommandInteractively(commands);
} else {
program.parse(process.argv);
}
}
initCLI();