-
Notifications
You must be signed in to change notification settings - Fork 5
/
eggs.ts
110 lines (97 loc) · 2.53 KB
/
eggs.ts
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
import {
Command,
CompletionsCommand,
HelpCommand,
log,
NestLand,
UpdateNotifier,
} from "./deps.ts";
import type { DefaultOptions } from "./src/commands.ts";
import { linkCommand } from "./src/commands/link.ts";
import { initCommand } from "./src/commands/init.ts";
import { publishCommand } from "./src/commands/publish.ts";
import { updateCommand } from "./src/commands/update.ts";
import { installCommand } from "./src/commands/install.ts";
import { upgradeCommand } from "./src/commands/upgrade.ts";
import { infoCommand } from "./src/commands/info.ts";
import { version } from "./src/version.ts";
import {
errorOccurred,
handleError,
setupLog,
writeLogFile,
} from "./src/utilities/log.ts";
const commands = {
link: linkCommand,
init: initCommand,
publish: publishCommand,
update: updateCommand,
install: installCommand,
upgrade: upgradeCommand,
info: infoCommand,
};
await setupLog();
const notifier = new UpdateNotifier({
name: "eggs",
registry: NestLand,
currentVersion: version,
});
const checkForUpdates = notifier.checkForUpdates();
const eggs = new Command<DefaultOptions, []>()
.throwErrors()
.name("eggs")
.version(version)
.description(
"nest.land - A module registry and CDN for Deno, on the permaweb",
)
.option("-D, --debug", "Print additional information.", { global: true })
.option(
"-o, --output-log",
"Create a log file after command completion.",
{ global: true },
)
.action(() => {
eggs.showHelp();
})
.command("help", new HelpCommand())
.command("completions", new CompletionsCommand())
.command("link", linkCommand)
.command("init", initCommand)
.command("publish", publishCommand)
.command("update", updateCommand)
.command("install", installCommand)
.command("info", infoCommand)
.command("upgrade", upgradeCommand);
try {
const { options } = await eggs.parse(Deno.args);
if (options.outputLog) {
await writeLogFile();
}
await notification();
if (errorOccurred) {
Deno.exit(1);
}
Deno.exit();
} catch (err) {
if (
err.message.match(
/^(Unknown option:|Unknown command:|Option --|Missing value for option:|Missing argument\(s\):)/,
)
) {
const command = Deno.args[0] as keyof typeof commands;
if (command in commands) {
commands[command].showHelp();
} else {
eggs.showHelp();
}
log.error(err.message);
} else {
await handleError(err);
}
await notification();
Deno.exit(1);
}
async function notification() {
await checkForUpdates;
notifier.notify("eggs upgrade");
}