-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
79 lines (70 loc) · 2.84 KB
/
main.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
/**
* @module
* Main entry point for the ASN Generator System.
*
* Note that the system makes assumptions about configuration being present in the environment variables.
* Alternatively, you can provide a `.env` file in the CWD which will be loaded automatically.
*
* Apart from that, we try to expose every method that might be useful for programmatic use.
*
* This enables many different use-cases, such as:
* - Running the server programmatically in a different environment, like an existing web server.
* - Running the generator programmatically in a different environment, like a CI/CD pipeline or a
* Raspberry PI connected to a label printer.
* - Running the generator as a standalone script, for example to automate buying sets of labels.
* - Integrating the system into a different system, such as a Slack Bot.
* - Load Balancing the system across multiple instances.
* - Extending the system with additional functionality.
*
* Depending on your use-case, you may want to take a look at using the
* [KV Connect Protocol](https://github.com/denoland/denokv/blob/main/proto/kv-connect.md)
* to connect to a remote KV store for shared state. You can self-host the KV store or use a
* managed service like [Deno Deploy](https://deno.com/deploy).
* In this case, you'll need to configure your `DB_FILE_NAME` variable to point to the http[s] URL.
*
* Alternatively, if all systems run on the same machine, you can use a shared `DATA_DIR` to store
* the data locally.
*
* ---
*
* This module also serves as the main entry point for the CLI and Web Application.
* The Web Application is nothing more than a specific CLI command that starts a web server.
* To make it easier to run the web server, this command also gets run when no command is specified.
*
* Note that this only gets run when the module is the main module (`import.meta.main === true`).
* Therefore, the CLI won't run by itself when you import this module in another module.
*/
import "@std/dotenv/load";
import { parseArgs } from "@std/cli/parse-args";
import { initConfig, validateDB } from "$common/mod.ts";
import { runServer } from "$cli/server.ts";
import { printHelp } from "$cli/help.ts";
import { runGenerate } from "$cli/generate.ts";
import { runStats } from "$cli/stats.ts";
import { runBump } from "$cli/bump.ts";
export * from "$common/mod.ts";
export * from "./lib/http/mod.ts";
export * from "$cli/mod.ts";
if (import.meta.main) {
// Load config
await initConfig();
await validateDB();
// CLI Stuff
const args = parseArgs(Deno.args);
if (args.help) {
printHelp();
Deno.exit();
}
if (args._[0] === "generate") {
await runGenerate(args);
}
if (args._[0] === "stats") {
await runStats(args);
}
if (args._[0] === "bump") {
await runBump(args);
}
if (args._[0] === "server" || args._.length === 0) {
await runServer(args);
}
}