discord-bot-cli
Version:
An easy way to build a command-based discord bot with discord.js.
51 lines (50 loc) • 1.84 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const meow_1 = __importDefault(require("meow"));
const helpString = `
Create a new command file.
Usage
dbc cmd path/to/file_without_extension [options]
Options
--lang, -l <js|ts> Define the language. Javascript (js) or Typescript (ts). (Default = js)
--path, -p <path> Path to the location of the command.
`;
function default_1() {
const cli = meow_1.default(helpString, {
flags: {
lang: {
type: "string",
alias: "l",
default: "js",
},
path: {
type: "string",
alias: "p",
},
},
});
if (cli.input.length < 2)
cli.showHelp();
if (!["js", "ts"].includes(cli.flags.lang)) {
console.log('--lang must be either "js" or "ts"');
cli.showHelp();
}
const ext = cli.flags.lang;
const { dir: cmdDir, base: name } = path_1.default.parse(cli.input[1]);
const dir = cli.flags.path ? path_1.default.join(cli.flags.path, cmdDir) : cmdDir;
fs_1.default.mkdirSync(dir, { recursive: true });
const filePath = path_1.default.resolve(path_1.default.format({
dir,
name,
ext: ".cmd." + ext,
}));
const templatePath = path_1.default.resolve(__dirname, "../assets/templates/command." + ext + ".template");
const template = fs_1.default.readFileSync(templatePath).toString().replace("$NAME$", name);
fs_1.default.writeFileSync(filePath, template, { flag: "wx" });
}
exports.default = default_1;