Skip to content

Commit

Permalink
fix the issue #607
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 10, 2024
1 parent cc4b6a4 commit a2e83c0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
### Deprecated
- `liquid` plugin. It never worked well with `search.pages()` [#600].

### Deleted
### Removed
- PostCSS plugin: Don't use nesting plugin by default since CSS nesting feature works across the latest devices and browser versions.

### Fixed
Expand All @@ -32,6 +32,8 @@ Go to the `v1` branch to see the changelog of Lume 1.
- Resolve bare specifiers mapped to `npm:`.
- Renamed imports to `.js` when bundle is `false` [#594].
- Redirect plugin: resolve urls when site location has a subfolder [#606].
- Bug merging options from CLI and _config file [#607].
- The option `--port` no longer depends on `--serve`.

## [2.1.4] - 2024-04-17
### Added
Expand Down Expand Up @@ -376,6 +378,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
[#600]: https://github.com/lumeland/lume/issues/600
[#603]: https://github.com/lumeland/lume/issues/603
[#606]: https://github.com/lumeland/lume/issues/606
[#607]: https://github.com/lumeland/lume/issues/607

[2.2.0]: https://github.com/lumeland/lume/compare/v2.1.4...HEAD
[2.1.4]: https://github.com/lumeland/lume/compare/v2.1.3...v2.1.4
Expand Down
2 changes: 1 addition & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const lume = new Command()
.option(
"-p, --port <port:number>",
"The port where the server runs.",
{ default: 3000, depends: ["serve"] },
{ default: 3000 },
)
.option(
"-o, --open",
Expand Down
1 change: 1 addition & 0 deletions core/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class Site {

constructor(options: Partial<SiteOptions> = {}) {
this.options = merge(defaults, options);
this.options.location.port ||= this.options.server.port.toString();

const src = this.src();
const dest = this.dest();
Expand Down
38 changes: 19 additions & 19 deletions core/utils/cli_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ import { parseArgs } from "../../deps/cli.ts";
import type { DeepPartial } from "./object.ts";
import type { SiteOptions } from "../site.ts";

export function getOptionsFromCli(): DeepPartial<SiteOptions> {
const options = parseArgs(Deno.args, {
export function getOptionsFromCli(
options: DeepPartial<SiteOptions>,
): DeepPartial<SiteOptions> {
const cli = parseArgs(Deno.args, {
string: ["src", "dest", "location", "port"],
boolean: ["serve", "open"],
alias: { dev: "d", serve: "s", port: "p", open: "o" },
["--"]: true,
});

const overrides: DeepPartial<SiteOptions> = {};

if (options.src) {
overrides.src = options.src;
if (cli.src) {
options.src = cli.src;
}

if (options.dest) {
overrides.dest = options.dest;
if (cli.dest) {
options.dest = cli.dest;
}

if (options.location) {
overrides.location = new URL(options.location);
} else if (options.serve || options._[0] === "cms") {
overrides.location = new URL(`http://localhost:${options.port || 3000}/`);
if (cli.location) {
options.location = new URL(cli.location);
} else if (cli.serve || cli._[0] === "cms") {
options.location = new URL(`http://localhost:${cli.port || 3000}/`);
}

if (options.port) {
(overrides.server ||= {}).port = parseInt(options.port);
if (cli.port) {
(options.server ||= {}).port = parseInt(cli.port);

if (overrides.location) {
overrides.location.port = options.port;
if (options.location) {
options.location.port = cli.port;
}
}

if (options.open) {
(overrides.server ||= {}).open = options.open;
if (cli.open) {
(options.server ||= {}).open = cli.open;
}

return overrides;
return options;
}
3 changes: 1 addition & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import search, { Options as SearchOptions } from "./plugins/search.ts";
import paginate, { Options as PaginateOptions } from "./plugins/paginate.ts";
import toml, { Options as TomlOptions } from "./plugins/toml.ts";
import yaml, { Options as YamlOptions } from "./plugins/yaml.ts";
import { merge } from "./core/utils/object.ts";

import type { DeepPartial } from "./core/utils/object.ts";
import type { SiteOptions } from "./core/site.ts";
Expand All @@ -32,7 +31,7 @@ export default function lume(
cliOptions = true,
): Site {
if (cliOptions) {
options = merge(options, getOptionsFromCli());
getOptionsFromCli(options);
}

const site = new Site(options as Partial<SiteOptions>);
Expand Down

0 comments on commit a2e83c0

Please sign in to comment.