aboutsummaryrefslogtreecommitdiff
path: root/mod.ts
blob: 3894ffddd59fa44aafa10dd51d42883b6e7008ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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<void> => {
			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<void> => {
			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<void> => 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<void> => {
			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");
			}
		}
	}
]);