henchman-cli
Version:
An all-in-one, interactive command-line tool that simplifies creating, setting up, and managing development projects like Flutter and Node.js while automating repetitive tasks.
59 lines (55 loc) • 1.91 kB
JavaScript
import {Argument, program} from 'commander';
import chalk from 'chalk';
import {byeMessage, greetMessage, logo} from '../core/constants.js';
import {getArgumentByMenu, getPath, validateRequiredTools} from '../core/utils.js';
import {cleanNodeProjects} from '../languages/node.js';
import {cleanFlutterProjects} from '../languages/flutter.js';
import {cleanPythonProjects} from '../languages/python.js';
export function cleanupCLI() {
const choices = ['flutter', 'node', 'python'];
program.command('cleanup')
.addArgument(new Argument('[config]')
.choices(choices)
)
.description(
`${chalk.blue('Cleanup projects for selected language in input subfolders')}\n` +
chalk.yellow(
'' +
'[config] options: ' +
`${choices.join(', ')}`
)
)
.action(async (argument) => {
await cleanupMenu(argument);
});
}
export async function cleanupMenu(argument = undefined) {
console.log(logo);
console.log(greetMessage);
argument = await getArgumentByMenu(['flutter', 'node', 'python'], argument, false);
// Validate required tools based on cleanup type
if (argument === 'flutter') {
if (!await validateRequiredTools(['flutter'])) {
console.log(byeMessage);
process.exit(1);
}
} else if (argument === 'python') {
if (!await validateRequiredTools(['pip'])) {
console.log(byeMessage);
process.exit(1);
}
}
const dir = await getPath();
switch (argument) {
case 'flutter':
await cleanFlutterProjects(dir);
break;
case 'python':
await cleanPythonProjects(dir);
break;
case 'node':
await cleanNodeProjects(dir);
break;
}
console.log(byeMessage);
}