-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
executable file
·72 lines (60 loc) · 1.67 KB
/
index.js
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
#!/usr/bin/env node
import { Command } from "commander";
import utils from "./utils/index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import fs from "fs";
const program = new Command();
const version = JSON.parse(
fs.readFileSync(new URL("./package.json", import.meta.url))
).version;
program
.name("Mailsy")
.version(version, "-v, --version", "Output the current version")
.description(
"⚡️ Quickly generate a disposable email straight from terminal."
);
// Generate a new email
program
.command("g")
.description("Generate a new email")
.action(() => utils.createAccount());
// fetch messages from the inbox
program
.command("m")
.description("Fetch messages from the inbox")
.action(async () => {
try {
const emails = await utils.fetchMessages();
if (!emails) return;
// show the emails using inquirer
const { email } = await inquirer.prompt([
{
type: "list",
name: "email",
message: "Select an email",
choices: emails.map((email, index) => ({
name: `${index + 1}. ${chalk.underline.blue(
email.subject
)} - ${chalk.yellow("From:")} ${email.from.address}`,
value: index + 1,
})),
},
]);
// open the email
await utils.openEmail(email);
} catch (error) {
console.error(error.message);
}
});
// delete account
program
.command("d")
.description("Delete account")
.action(() => utils.deleteAccount());
// show details of the account
program
.command("me")
.description("Show details of the account")
.action(() => utils.showDetails());
program.parse();