diff --git a/README.md b/README.md index 1528faa..649228f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # Create Discord App -Super fast discord bot project generator. \ No newline at end of file +A Simple CLI to generate discord bot projects easily! + +# Example +```sh +$ npx create-discord-app . +``` + +# Specific dir +```sh +$ npx create-discord-app --create --dir=dirName +``` + +# Join Our Discord Server +[![](https://i.imgur.com/f6hNUfc.png)](https://discord.gg/2SUybzb) \ No newline at end of file diff --git a/command.js b/command.js index 494870b..20c645b 100644 --- a/command.js +++ b/command.js @@ -11,9 +11,11 @@ const help = ` ${chalk.whiteBright("--discord")} : Shows discord support server invite ${chalk.whiteBright("--help")} : Shows help menu ${chalk.whiteBright("--version")} : Shows CDA version + ${chalk.whiteBright("--create")} : Create Project - - Example: ${chalk.gray("$")} ${chalk.blueBright("create-discord-app .")} + Examples: + ${chalk.gray("$")} ${chalk.blueBright("create-discord-app .")} + ${chalk.gray("$")} ${chalk.blueBright("create-discord-app --create --dir=projectDirName")} `; module.exports = async (args) => { @@ -24,6 +26,7 @@ module.exports = async (args) => { } else if (args.discord) { console.log(`${chalk.whiteBright("Join Our Discord Server")}: ${chalk.blueBright("https://discord.gg/2SUybzb")}`); } else if (args.create || (args._[0] && args._[0] === ".")) { + if (args.create && !args.dir) return console.log(chalk.redBright("dir was not specified!")); const { ok, type, language, lib, token } = await prompt([ prompts.dir, prompts.type, @@ -50,7 +53,7 @@ module.exports = async (args) => { // none else return console.log(chalk.redBright("[Error] Couldn't locate template files!")); - const cda = new create(path.join(process.cwd(), args._[0] === "." ? "" : args.dir), projectdir); + const cda = new create(args._[0] === "." ? "" : args.dir, projectdir); const lang = () => { let l; @@ -60,9 +63,6 @@ module.exports = async (args) => { case "typescript": l = "node"; break; - case "python": - l = "py"; - break; default: l = null; } diff --git a/package.json b/package.json index 7e55f03..c730d59 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "create-discord-app", "version": "2.0.0", - "description": "Discord bot project generator.", + "description": "A Simple CLI to generate discord bot projects easily!", "main": "index.js", "preferGlobal": true, "bin": { diff --git a/src/create.js b/src/create.js index 1f9dc40..32f26f5 100644 --- a/src/create.js +++ b/src/create.js @@ -12,6 +12,19 @@ class Create { this.source = source; } + initGit() { + const commands = ["git init", "git add .", "git commit -m \"initial commit\""]; + const finalizingLoader = ora(chalk.blueBright("Finalizing...")).start(); + + for (const command of commands) { + try { + cp.execSync(this.path === "." ? command : `cd ${this.path} && ${command}`); + } catch(e) { /* Do nothing */ } + } + + finalizingLoader.succeed(chalk.greenBright("Successfully created discord bot project!")) + } + async init(token = null, ops = { language: null }) { if (!this.source) return console.log(symbols.error, chalk.redBright("No source file(s) specified!")); let path = this.path === "." ? process.cwd() : `${process.cwd()}/${this.path}`; @@ -28,14 +41,16 @@ class Create { } copyFileLoader.succeed(chalk.cyanBright("Finished copying files!")); - const finalizingLoader = ora(chalk.blueBright("Finalizing...")).start(); + const depInstaller = ora(chalk.blueBright("Installing dependencies...")).start(); const command = this.getInstallCommand(ops.language); - if (!command) return finalizingLoader.warn(chalk.yellowBright("Generated project but couldn't install dependencies, please try again manually!")); + if (!command) return depInstaller.warn(chalk.yellowBright("Generated project but couldn't install dependencies, please try again manually!")); + + cp.exec(this.path === "." ? command : `cd ${this.path} && ${command}`, (error) => { + if (error) return depInstaller.warn(chalk.yellowBright("Generated project but couldn't install dependencies, please try again manually!")); + depInstaller.succeed(chalk.greenBright("Successfully Installed dependencies!")); - cp.exec(command, (error) => { - if (error) return finalizingLoader.warn(chalk.yellowBright("Generated project but couldn't install dependencies, please try again manually!")); - return finalizingLoader.succeed(chalk.greenBright("Successfully created discord bot project!")); + return this.initGit(); }); }); } @@ -47,9 +62,6 @@ class Create { case "js": cmd = "npm i"; break; - case "py": - cmd = "pip3 install -r requirements.txt"; - break; default: cmd = null; }