nextdevkit
Version:
A Comprehensive CLI Toolkit for Next.js Development
77 lines (76 loc) • 3 kB
JavaScript
import { Command } from 'commander';
import addFile from './commands/addFile.js';
import createCommand from './commands/createProject.js';
import displayUsage from './commands/displayUsage.js';
import generateComponents from './commands/generateComponents.js';
import initConfig from './commands/initConfig.js';
import listCommands from './commands/listCommands.js';
import removeFile from './commands/removeFile.js';
import setupLinters from './commands/setupLinters.js';
import { handleError } from './utils/handleMessages.js';
import loadPackageJson from './utils/loadPackageJson.js';
(async () => {
const program = new Command();
const packageJson = await loadPackageJson();
program
.name('nextdevkit')
.description('A Comprehensive CLI Toolkit for Next.js Development')
.version(packageJson.version, '-v, --version', 'Display the CLI version');
const commands = [
{
command: 'create [projectName]',
description: 'Create a new Next.js project with NextDevKit initialized',
action: async (projectName) => await createCommand(projectName)
},
{
command: 'init',
description: 'Initialize NextDevKit in an existing Next.js project',
action: async () => await initConfig()
},
{
command: 'add <name>',
description: 'Add a utility or React custom hook file to your project',
action: async (name) => await addFile(name)
},
{
command: 'remove <name>',
description: 'Remove a utility or hook file from your project',
action: async (name) => await removeFile(name)
},
{
command: 'generate <type> <name> [destination]',
description: 'Generate a new component or page',
action: async (type, name, destination) => await generateComponents(type, name, destination)
},
{
command: 'list',
description: 'List all available utility and hook files',
action: async () => await listCommands()
},
{
command: 'setup-linters',
description: 'Set up ESLint, Prettier, Husky, and lint-staged',
action: async () => await setupLinters()
},
{
command: 'help [command]',
description: 'Display usage for commands with examples',
action: async (command) => await displayUsage(command)
}
];
commands.forEach(({ command, description, action }) => {
program.command(command).description(description).action(action);
});
if (process.argv.length < 3) {
await displayUsage();
process.exit(0);
}
program.on('command:*', async (operands) => {
handleError(`Invalid command ${operands.join(' ')}\n`, {
exit: false
});
process.exit(1);
});
program.parse(process.argv);
})();