Skip to content

Commit b9ae01e

Browse files
committed
LumeCMS is automatically initialized
1 parent 4aab9e5 commit b9ae01e

File tree

6 files changed

+35
-238
lines changed

6 files changed

+35
-238
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project try to adheres to [Semantic Versioning](https://semver.org/).
66
Go to the `v2` branch to see the changelog of Lume 2.
77
Go to the `v1` branch to see the changelog of Lume 1.
88

9+
## [3.1.0] - Unreleased
10+
### Removed
11+
- `cms` command. LumeCMS is automatically initialized if the file `_cms.ts` or `_cms.js` is detected. Use `--no-cms` option to disable it.
12+
913
## [3.0.12] - Unreleased
1014
### Fixed
1115
- `feed` plugin: revert changes introduced in 3.0.7 (Use `textContent` instead of `innerHTML` to get values using CSS selectors).
@@ -264,6 +268,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
264268
[#785]: https://github.com/lumeland/lume/issues/785
265269

266270
[3.0.12]: https://github.com/lumeland/lume/compare/v3.0.11...HEAD
271+
[3.1.0]: https://github.com/lumeland/lume/compare/v3.0.11...HEAD
267272
[3.0.11]: https://github.com/lumeland/lume/compare/v3.0.10...v3.0.11
268273
[3.0.10]: https://github.com/lumeland/lume/compare/v3.0.9...v3.0.10
269274
[3.0.9]: https://github.com/lumeland/lume/compare/v3.0.8...v3.0.9

cli.ts

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -68,46 +68,6 @@ const run = new Command()
6868
await run(config, scripts);
6969
});
7070

71-
const cms = new Command()
72-
.description("Run Lume CMS.")
73-
.option(
74-
"--config <config:string>",
75-
"The config file path.",
76-
)
77-
.option(
78-
"--src <src:string>",
79-
"The source directory for your site.",
80-
{ default: "./" },
81-
)
82-
.option(
83-
"--dest <dest:string>",
84-
"The build destination.",
85-
{ default: "_site" },
86-
)
87-
.option(
88-
"--location <location>",
89-
"The URL location of the site.",
90-
{ default: "http://localhost" },
91-
)
92-
.option(
93-
"-p, --port <port:number>",
94-
"The port where the server runs.",
95-
{ default: 3000 },
96-
)
97-
.option(
98-
"--hostname <hostname>",
99-
"The hostname where the server runs.",
100-
{ default: "localhost" },
101-
)
102-
.option(
103-
"-o, --open",
104-
"Open the CMS in a browser.",
105-
)
106-
.action(async ({ config }) => {
107-
const { runCms } = await import("./cli/cms.ts");
108-
runCms(config);
109-
});
110-
11171
const lume = new Command()
11272
.name("🔥lume")
11373
.version(() => getCurrentVersion())
@@ -143,19 +103,19 @@ const lume = new Command()
143103
"Start a live-reloading web server and watch changes.",
144104
)
145105
.option(
146-
"--cms",
147-
"Run LumeCMS.",
106+
"--no-cms",
107+
"Don't start LumeCMS if _cms.ts file is detected.",
148108
{ depends: ["serve"] },
149109
)
150110
.option(
151111
"-p, --port <port:number>",
152112
"The port where the server runs.",
153-
{ default: 3000 },
113+
{ default: 3000, depends: ["serve"] },
154114
)
155115
.option(
156116
"--hostname <hostname>",
157117
"The hostname where the server runs.",
158-
{ default: "localhost" },
118+
{ default: "localhost", depends: ["serve"] },
159119
)
160120
.option(
161121
"-o, --open",
@@ -178,7 +138,6 @@ const lume = new Command()
178138
.command("new <archetype> [arguments...]", create)
179139
.command("upgrade", upgrade)
180140
.command("run <script...>", run)
181-
.command("cms", cms)
182141
.command("completions", new CompletionsCommand());
183142

184143
try {

cli/build_worker.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface BuildOptions {
3232
cms?: boolean;
3333
}
3434

35-
async function build({ type, config, serve, cms }: BuildOptions) {
35+
async function build({ type, config, serve, cms: loadCms }: BuildOptions) {
3636
// Set the live reload environment variable to add hash to the URLs in the module loader
3737
setEnv("LUME_LIVE_RELOAD", "true");
3838

@@ -41,15 +41,17 @@ async function build({ type, config, serve, cms }: BuildOptions) {
4141

4242
// Setup LumeCMS
4343
let _cms: URL | undefined;
44-
if (cms) {
44+
// deno-lint-ignore no-explicit-any
45+
let cms: any;
46+
47+
if (loadCms) {
4548
_cms = await resolveConfigFile(["_cms.ts", "_cms.js"]);
4649

47-
if (!_cms) {
48-
throw new Error("CMS config file not found");
50+
if (_cms) {
51+
const mod = await import(_cms.toString());
52+
cms = mod.default;
53+
site.use(lumeCMS({ cms }));
4954
}
50-
51-
const mod = await import(_cms.toString());
52-
site.use(lumeCMS({ cms: mod.default }));
5355
}
5456

5557
// Include the config files to the watcher
@@ -108,13 +110,27 @@ async function build({ type, config, serve, cms }: BuildOptions) {
108110
if (type === "build") {
109111
const ipAddr = localIp();
110112

111-
log.info(" Server started at:");
113+
log.info("\n Server started at:");
112114
log.info(` <green>http://${hostname}:${port}/</green> (local)`);
113115

114116
if (ipAddr) {
115117
log.info(` <green>http://${ipAddr}:${port}/</green> (network)`);
116118
}
117119

120+
if (cms) {
121+
log.info("\n LumeCMS started at:");
122+
const { basePath } = cms.options;
123+
log.info(
124+
` <green>http://${hostname}:${port}${basePath}</green> (local)`,
125+
);
126+
127+
if (ipAddr) {
128+
log.info(
129+
` <green>http://${ipAddr}:${port}${basePath}</green> (network)`,
130+
);
131+
}
132+
}
133+
118134
if (open) {
119135
openBrowser(`http://${hostname}:${port}/`);
120136
}
@@ -137,7 +153,7 @@ async function build({ type, config, serve, cms }: BuildOptions) {
137153
log.info("Reloading the site...");
138154
const url = response.headers.get("Location") || request.url;
139155
postMessage({ type: "reload" });
140-
return getWaitResponse(url);
156+
return createWaitResponse(url);
141157
}
142158

143159
return response;
@@ -157,7 +173,7 @@ async function build({ type, config, serve, cms }: BuildOptions) {
157173
server.start();
158174
}
159175

160-
function getWaitResponse(url: string): Response {
176+
function createWaitResponse(url: string): Response {
161177
return new Response(
162178
`<html>
163179
<head>

cli/cms.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

cli/cms_worker.ts

Lines changed: 0 additions & 140 deletions
This file was deleted.

serve.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export function getServeHandler(): Deno.ServeHandler {
128128
"task",
129129
"lume",
130130
"--serve",
131-
"--cms",
132131
`--port=${port}`,
133132
`--hostname=${hostname}`,
134133
`--location=${location.origin}`,

0 commit comments

Comments
 (0)