#!/usr/bin/env node import { glob } from "glob"; import { promisify } from "util"; const PG = promisify(glob); import fs, { readdir } from "fs"; import path from "path"; import inquirer from "inquirer"; interface Choices { language: "JavaScript" | "TypeScript"; dir: string; lib: "Vanilla" | "DartCommands" | "WOKCommands"; } inquirer .prompt([ { name: "language", message: "Choose a language", type: "list", choices: ["JavaScript", "TypeScript"], }, { name: "lib", message: "Choose a library to base the bot off of", type: "list", choices: ["Vanilla", "DartCommands", "WOKCommands"], }, { name: "dir", message: "Enter a directory name to write to", type: "input", }, ]) .then((answers) => { Main(answers); }); async function Main(choices: Choices) { const ext = choices.language == "TypeScript" ? "ts" : "js"; ( await PG( `${path.join(__dirname, "read")}/${choices.language}/${ choices.lib }/**/*.${ext}` ) ).map((file: any) => { const dir = choices.dir == "." ? `${process.cwd()}` : `${path.join(process.cwd(), choices.dir)}`; const L = file.split("/"); let fileName = L[L.length - 1]; const readDirName = L.slice(0, L.length - 1); if ( !readDirName[readDirName.length - 1].includes("TypeScript") && !readDirName[readDirName.length - 1].includes("JavaScript") && !readDirName[readDirName.length - 1].includes("Vanilla") && !readDirName[readDirName.length - 1].includes("WOKCommands") && !readDirName[readDirName.length - 1].includes("DartCommands") ) { const newDirName = readDirName[readDirName.length - 1]; fs.mkdir(`${path.join(dir, newDirName)}`, () => {}); fs.readFile(file, (err, data) => { fs.writeFile( `${path.join(dir, newDirName, `${fileName}`)}`, data.toString(), () => {} ); }); } else { fs.readFile(file, (err, data) => { fs.writeFile( `${path.join(dir, `${fileName}`)}`, data.toString(), () => {} ); }); } }); }