rcnlx
Version:
A cli to generate discord.js projects
101 lines (95 loc) • 3.02 kB
JavaScript
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const symbols = require("log-symbols");
const res = path.resolve;
const exist = fs.existsSync;
module.exports = async function (token, prefix) {
if (exist(res("src")))
return console.log(
chalk.red(`${symbols.error} Please delete the "src" directory`)
);
await fs.mkdirSync(res("src"));
//package json
fs.readFile(
res(path.join(__dirname, `..`, "projectFiles", "package.json")),
"utf8",
async (err, data) => {
if (err) throw err;
await fs.writeFileSync(res("package.json"), data, (err) =>
console.log(err)
);
console.log(chalk.green(`${symbols.success} package.json was created!`));
}
);
// config.json
const config = res("src/config.json");
await fs.writeFileSync(config,
`{
"token": "${token}",
"prefix": "${prefix}"
}`);
console.log(chalk.green(`${symbols.success} config.json was created!`));
// index.js
const index = res("src/index.js");
fs.readFile(
path.join(__dirname, "..", "projectFiles", "index.js"),
"utf8",
async (err, data) => {
if (err) throw err;
await fs.writeFileSync(index, data, (err) => console.log(err));
console.log(chalk.green(`${symbols.success} index.js was created!`));
}
);
// handler folder and files
fs.mkdirSync(res("src/handlers"));
fs.readFile(
path.join(__dirname, "..", "projectFiles", "command.js"),
"utf8",
async (err, data) => {
if (err) throw err;
await fs.writeFileSync(res("src/handlers/command.js"), data, (err) =>
console.log(err)
);
console.log(chalk.green(`${symbols.success} command.js was created!`));
}
);
// events folder and files
fs.mkdirSync(res("src/events"));
fs.readFile(
path.join(__dirname, "..", "projectFiles", "ready.js"),
"utf8",
async (err, data) => {
if (err) throw err;
await fs.writeFileSync(res("src/events/ready.js"), data, (err) =>
console.log(err)
);
console.log(chalk.green(`${symbols.success} ready.js was created!`));
}
);
fs.readFile(
path.join(__dirname, "..", "projectFiles", "message.js"),
"utf8",
async (err, data) => {
if (err) throw err;
await fs.writeFileSync(res("src/events/message.js"), data, (err) =>
console.log(err)
);
console.log(chalk.green(`${symbols.success} message.js was created!`));
}
);
// commands folder and files
fs.mkdirSync(res("src/commands"));
fs.mkdirSync(res("src/commands/info"));
fs.readFile(
path.join(__dirname, "..", "projectFiles", "ping.js"),
"utf8",
async (err, data) => {
if (err) throw err;
await fs.writeFileSync(res("src/commands/info/ping.js"), data, (err) =>
console.log(err)
);
console.log(chalk.green(`${symbols.success} ping.js was created!`));
}
);
};