From 1258a5ce84e7ed230594e2ea3be70d512a31b814 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 6 Mar 2021 17:25:06 -0800 Subject: :star: --- Makefile | 10 +++++ deps.ts | 10 +++++ mod.ts | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 Makefile create mode 100644 deps.ts create mode 100644 mod.ts diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fb6fce0 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: version help run + +run: + deno run --allow-net --allow-read --allow-write --allow-run --unstable mod.ts + +help: + deno run --allow-net --allow-read --allow-write --allow-run --unstable mod.ts --help + +version: + deno run --allow-net --allow-read --allow-write --allow-run --unstable mod.ts --version diff --git a/deps.ts b/deps.ts new file mode 100644 index 0000000..673349b --- /dev/null +++ b/deps.ts @@ -0,0 +1,10 @@ +export { Command } from "https://deno.land/x/cliffy/command/mod.ts"; +export { + // Checkbox, + // Confirm, + Input, + // Number, + prompt, + Select, + Toggle +} from "https://deno.land/x/cliffy/prompt/mod.ts"; diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..3894ffd --- /dev/null +++ b/mod.ts @@ -0,0 +1,126 @@ +import { Command } from "./deps.ts"; +import { + // Checkbox, + // Confirm, + Input, + // Number, + prompt, + Select, + Toggle +} from "./deps.ts"; + +await new Command() + .name("discordeno") + .version("1.0.0") + .description("The unofficial and powerful Discordeno CLI.") + .parse(Deno.args); + +await prompt([ + { + name: "name", + message: "What would you like to call your project?", + type: Input, + // TODO: Get directory name and use it as the default name. + // default: Deno.cwd().split('\\').reverse()[0], + default: "my-discordeno-bot", + // suggestions: [ + // Deno.cwd().split('\\').reverse()[0], + // ], + minLength: 1 + }, + { + /** + * Forgot that the reason people are using this plugin is + * for generating templates... + * + * Going to leave this question in for now though. + */ + name: "use_template", + message: "Would you like to use a template?", + type: Toggle, + default: false, + validate: ((value) => value == "Yes"), + after: async ({ use_template }, next): Promise => { + use_template + ? await next() + : await next("confirm"); + } + }, + { + name: "custom_template", + message: "Would you like to use a custom template from Git?", + type: Toggle, + default: false, + after: async ({ custom_template }, next): Promise => { + custom_template + ? await next("template_url") + : await next("template_name"); + } + }, + { + name: "template_url", + message: "Please enter the Git URL for the template", + type: Input, + suggestions: [ + "https://", + "https://github.com", + "https://gitlab.com", + "https://bitbuckit.org" + ], + validate: ((value) => /^(ftp|http|https):\/\/[^ "]+$/.test(value)), + after: async ({}, next): Promise => await next("confirm") + }, + { + name: "template_name", + message: "Please choose a template", + type: Select, + options: [ + { + name: "basic", + value: "https://github.com/discordeno/slash-commands-boilerplate" + }, + { + name: "serverless-slash-commands", + value: "https://github.com/discordeno/slash-commands-boilerplate" + } + ] + }, + { + name: "confirm", + message: "Confirm settings?", + type: Toggle, + default: true, + after: async ( + { confirm, custom_template, template_name, template_url, name }, + next + ): Promise => { + if (confirm) { + if (custom_template) { + // @ts-ignore IntelliJ cannot find Deno. + await Deno.run({ + cmd: [ + "git", + "clone", + "--single-branch", + template_url as string, + name as string + ] + }).status(); + } else { + // @ts-ignore IntelliJ cannot find Deno. + await Deno.run({ + cmd: [ + "git", + "clone", + "--single-branch", + template_name as string, + name as string + ] + }).status(); + } + } else { + await next("name"); + } + } + } +]); -- cgit v1.2.3