-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
cli.ts
172 lines (165 loc) · 4.76 KB
/
cli.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { Command, CompletionsCommand } from "./deps/cliffy.ts";
import { getCurrentVersion, mustNotifyUpgrade } from "./core/utils.ts";
import { printError } from "./core/errors.ts";
import initCommand from "./cli/init.ts";
import upgradeCommand from "./cli/upgrade.ts";
import runCommand from "./cli/run.ts";
import buildCommand from "./cli/build.ts";
import importMapCommand from "./cli/import_map.ts";
import { cyan, dim, green } from "./deps/colors.ts";
import ci from "./ci.ts";
const init = new Command()
.description("Create a config file for a new site.")
.example("lume init", "Creates a _config.js file in the current directory.")
.action(initCommand);
const upgrade = new Command()
.description("Upgrade your Lume executable to the latest version.")
.example("lume upgrade", "Upgrades to the latest stable version.")
.example("lume upgrade --dev", "Upgrades to the latest development version.")
.option(
"-d, --dev [dev:boolean]",
"Install the latest development version (last Git commit).",
)
.action(upgradeCommand);
const importMap = new Command()
.description("Create or update a import map file with the Lume imports.")
.example("lume import-map", "Create/update the file import_map.json.")
.example("lume import-map --file=my-map.json", "Create/update a custom file.")
.option(
"-f, --file [file:string]",
"The name of the import map file.",
{ default: "./import_map.json" },
)
.action(importMapCommand);
const run = new Command()
.description("Run one or more scripts from the config file.")
.example(
"lume run deploy",
"Runs the `deploy` script.",
)
.example(
"lume run deploy --config=_config.ts",
"Runs the `deploy` script from the _config.ts file.",
)
.example(
"lume run build deploy",
"Runs the `build` and `deploy` scripts.",
)
.option(
"--root <root>",
"The directory where Lume should work.",
{ default: "./" },
)
.option(
"--config <config>",
"The config file path.",
)
.option(
"--src <src>",
"The source directory for your site.",
{ default: "./" },
)
.option(
"--dest <dest>",
"The build destination.",
{ default: "_site" },
)
.option(
"--location <location>",
"The URL location of the site.",
{ default: "http://localhost" },
)
.option(
"--quiet [quiet:boolean]",
"Enable quiet mode (show less info).",
)
.action(runCommand);
const lume = new Command()
.name("🔥lume")
.version(getCurrentVersion)
.description(
"A static site generator for Deno. \nDocs: https://lumeland.github.io/",
)
.example("lume", "Builds the site.")
.example("lume --serve", "Serves the site in localhost.")
.example("lume upgrade", "Upgrades Lume to the latest version.")
.example("lume run <script>", "Runs a custom script.")
.example("lume [COMMAND] --help", "Shows the help for a command.")
.option(
"--root <root>",
"The directory where Lume should work.",
{ default: "./" },
)
.option(
"--config <config>",
"The config file path.",
)
.option(
"--src <src>",
"The source directory for your site.",
{ default: "./" },
)
.option(
"--dest <dest>",
"The build destination.",
{ default: "_site" },
)
.option(
"--location <location>",
"The URL location of the site.",
{ default: "http://localhost" },
)
.option(
"--quiet [quiet:boolean]",
"Enable quiet mode (show less info).",
)
.option(
"-d, --dev [dev:boolean]",
"Enable development mode (view draft pages).",
)
.option(
"-s, --serve [serve:boolean]",
"Start a live-reloading web server and watch changes.",
)
.option(
"-p, --port <port:number>",
"The port where the server runs.",
{ default: 3000, depends: ["serve"] },
)
.option(
"-o, --open [open:boolean]",
"Open the site in a browser.",
{ depends: ["serve"] },
)
.option(
"-w, --watch [watch:boolean]",
"Build and watch changes.",
)
.action(buildCommand)
.command("init", init)
.command("upgrade", upgrade)
.command("import-map", importMap)
.command("run <script...>", run)
.command("completions", new CompletionsCommand());
// If the command contains deno arguments, use ci.ts
try {
if (Deno.args.some((arg) => arg === "--")) {
await ci(Deno.args);
} else {
if (!Deno.args.includes("--quiet")) {
const info = await mustNotifyUpgrade();
if (info) {
console.log("----------------------------------------");
console.log(
`Update available ${dim(info.current)} → ${green(info.latest)}`,
);
console.log(`Run ${cyan(info.command)} to update`);
console.log("----------------------------------------");
}
}
await lume.parse(Deno.args);
}
} catch (error) {
printError(error);
Deno.exit(1);
}