Files
manyplug/src/commands/init.js
synt-xerror bbc44bec52 feat: initial CLI structure
- init: create plugin boilerplate
- install: install from local path with deps
- list: show installed plugins
- validate: check manyplug.json syntax
2026-04-09 01:15:00 -03:00

76 lines
1.9 KiB
JavaScript

import fs from 'fs-extra';
import path from 'path';
import chalk from 'chalk';
const PLUGIN_TEMPLATE = `/**
* {{name}} plugin
*/
/**
* Main plugin function - called on every message
* @param {Object} ctx - { msg, chat, api }
*/
export default async function {{name}}Plugin({ msg, chat, api }) {
// Your plugin logic here
// Return true to stop further processing
return false;
}
/**
* Optional setup function - called once on bot initialization
* @param {Object} api - API without message context
*/
export async function setup(api) {
// Initialize databases, schedules, etc.
}
/**
* Optional API exports for other plugins
*/
export const api = {
// Expose methods for other plugins
};
`;
export async function initCommand(name, options) {
const pluginDir = path.resolve(name);
if (await fs.pathExists(pluginDir)) {
console.error(chalk.red(`❌ Directory "${name}" already exists`));
process.exit(1);
}
console.log(chalk.blue(`Creating plugin "${name}"...`));
await fs.ensureDir(pluginDir);
// Create manyplug.json
const manifest = {
name,
version: '1.0.0',
category: options.category || 'utility',
service: false,
description: '',
author: '',
dependencies: {}
};
await fs.writeJson(path.join(pluginDir, 'manyplug.json'), manifest, { spaces: 2 });
// Create index.js
const indexContent = PLUGIN_TEMPLATE.replace(/\{\{name\}\}/g, name);
await fs.writeFile(path.join(pluginDir, 'index.js'), indexContent);
// Create locale directory
await fs.ensureDir(path.join(pluginDir, 'locale'));
await fs.writeJson(
path.join(pluginDir, 'locale', 'pt.json'),
{ plugin: { name } },
{ spaces: 2 }
);
console.log(chalk.green(`✅ Plugin "${name}" created at ./${name}`));
console.log(chalk.gray(` Category: ${options.category}`));
console.log(chalk.gray(` Edit manyplug.json to add dependencies`));
}