From 0f6468ce01d9aaa2a82a5d566845b33244dc86ad Mon Sep 17 00:00:00 2001 From: scarf Date: Sat, 23 Dec 2023 12:38:13 +0900 Subject: [PATCH 1/2] refactor: extract `getOptionsFromCli` --- core/utils/cli_options.ts | 42 +++++++++++++++++++++++++++++++++++++++ mod.ts | 41 +------------------------------------- 2 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 core/utils/cli_options.ts diff --git a/core/utils/cli_options.ts b/core/utils/cli_options.ts new file mode 100644 index 000000000..9c47edb61 --- /dev/null +++ b/core/utils/cli_options.ts @@ -0,0 +1,42 @@ +import { parseArgs } from "../../deps/cli.ts"; +import type { DeepPartial } from "./object.ts"; +import type { SiteOptions } from "../site.ts"; + +export function getOptionsFromCli(): DeepPartial { + const options = parseArgs(Deno.args, { + string: ["src", "dest", "location", "port"], + boolean: ["serve", "open"], + alias: { dev: "d", serve: "s", port: "p", open: "o" }, + ["--"]: true, + }); + + const overrides: DeepPartial = {}; + + if (options.src) { + overrides.src = options.src; + } + + if (options.dest) { + overrides.dest = options.dest; + } + + if (options.location) { + overrides.location = new URL(options.location); + } else if (options.serve) { + overrides.location = new URL(`http://localhost:${options.port || 3000}/`); + } + + if (options.port) { + (overrides.server ||= {}).port = parseInt(options.port); + + if (overrides.location) { + overrides.location.port = options.port; + } + } + + if (options.open) { + (overrides.server ||= {}).open = options.open; + } + + return overrides; +} diff --git a/mod.ts b/mod.ts index 3403d4d02..ddf20a3d0 100644 --- a/mod.ts +++ b/mod.ts @@ -1,4 +1,3 @@ -import { parseArgs } from "./deps/cli.ts"; import Site from "./core/site.ts"; import url, { Options as UrlOptions } from "./plugins/url.ts"; import json, { Options as JsonOptions } from "./plugins/json.ts"; @@ -13,6 +12,7 @@ import { merge } from "./core/utils/object.ts"; import type { DeepPartial } from "./core/utils/object.ts"; import type { SiteOptions } from "./core/site.ts"; +import { getOptionsFromCli } from "./core/utils/cli_options.ts"; export interface PluginOptions { url?: UrlOptions; @@ -60,42 +60,3 @@ export default function lume( .use(toml(pluginOptions.toml)) .use(yaml(pluginOptions.yaml)); } - -function getOptionsFromCli(): DeepPartial { - const options = parseArgs(Deno.args, { - string: ["src", "dest", "location", "port"], - boolean: ["serve", "open"], - alias: { dev: "d", serve: "s", port: "p", open: "o" }, - ["--"]: true, - }); - - const overrides: DeepPartial = {}; - - if (options.src) { - overrides.src = options.src; - } - - if (options.dest) { - overrides.dest = options.dest; - } - - if (options.location) { - overrides.location = new URL(options.location); - } else if (options.serve) { - overrides.location = new URL(`http://localhost:${options.port || 3000}/`); - } - - if (options.port) { - (overrides.server ||= {}).port = parseInt(options.port); - - if (overrides.location) { - overrides.location.port = options.port; - } - } - - if (options.open) { - (overrides.server ||= {}).open = options.open; - } - - return overrides; -} From e1e8509db5331f53fbb136026d8cff18dcaf1e43 Mon Sep 17 00:00:00 2001 From: scarf Date: Sun, 24 Dec 2023 11:02:29 +0900 Subject: [PATCH 2/2] docs: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4ed1a02..64cee521f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Go to the `v1` branch to see the changelog of Lume 1. ### Changed - `decap_cms` plugin: Add a script in the homepage to redirect to /admin/ when an invite token or recovery token is detected from netlify identity. +- `getOptionsFromCli` is moved from `mod.ts` to `utils/cli_options.ts`. ### Fixed - `sitemap` plugin: Add the `xmlns` namespace for localized urls.