Skip to content

Commit

Permalink
use LUME_ENV variable, fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 12, 2023
1 parent 3591305 commit c7864dc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Any BREAKING CHANGE between minor versions will be documented here in upper case

## [Unreleased]
### Added
- The env variable `LUME_ENV=development` is created when `deno task lume --dev`.
- New `site.searcher` property with a instance of `Searcher` class.
It's used by plugins like `search`, `nav`, `sitemap` and `feed`.
(Previouly, each plugin had it's own instance).
Expand Down
2 changes: 1 addition & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const upgrade = new Command()
.action(upgradeCommand);

const create = new Command()
.description("Create a new page from a archetype.")
.description("Run an archetype to create more files.")
.example(
"lume new post 'Post title'",
"Create a new post file using the _archetypes/post.ts archetype.",
Expand Down
7 changes: 6 additions & 1 deletion cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ interface Options {
config?: string;
serve?: boolean;
watch?: boolean;
dev?: boolean;
}

export default function ({ config, serve, watch }: Options) {
export default function ({ config, serve, watch, dev }: Options) {
if (dev) {
Deno.env.set("LUME_ENV", "development");
}

return build(config, serve, watch);
}

Expand Down
6 changes: 4 additions & 2 deletions core/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,11 @@ export default class Site {
this.fs.init();

// Get the site content
const isDev = Deno.env.get("LUME_ENV") === "development";
const [_pages, _staticFiles] = await this.source.build(
this.globalComponents,
[
(_, page) => !page?.data.draft || this.options.dev,
(_, page) => !page?.data.draft || isDev,
],
);

Expand Down Expand Up @@ -572,10 +573,11 @@ export default class Site {
}

// Get the site content
const isDev = Deno.env.get("LUME_ENV") === "development";
const [_pages, _staticFiles] = await this.source.build(
this.globalComponents,
[
(_, page) => !page?.data.draft || this.options.dev,
(_, page) => !page?.data.draft || isDev,
this.scopes.getFilter(files),
],
);
Expand Down
10 changes: 8 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export default function lume(
options = merge(options, getOptionsFromCli());
}

if (options.dev) {
Deno.env.set("LUME_ENV", "development");
} else {
Deno.env.delete("LUME_ENV");
}

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

// Ignore the .git folder and .DS_Store (macOS) files by the watcher
Expand Down Expand Up @@ -83,8 +89,8 @@ function getOptionsFromCli(): DeepPartial<SiteOptions> {
overrides.quiet = options.quiet;
}

if (options.dev) {
overrides.dev = options.dev;
if (Deno.env.get("LUME_ENV") === "development") {
overrides.dev = true;
}

if (options.port) {
Expand Down
4 changes: 1 addition & 3 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ Deno.test("event listener configuration", () => {
const site = lume();
const { listeners } = site.events;

equals(listeners.size, 1);
equals(listeners.has("beforeUpdate"), true);
equals(listeners.get("beforeUpdate")?.size, 1);
equals(listeners.size, 0);

site.addEventListener("afterBuild", "afterbuild-command");
equals(listeners.get("afterBuild")?.size, 1);
Expand Down

0 comments on commit c7864dc

Please sign in to comment.