Skip to content

Commit 9baa679

Browse files
committed
removing fragile build time default theme
1 parent dc9f8cb commit 9baa679

File tree

9 files changed

+52
-66
lines changed

9 files changed

+52
-66
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
2-
*.log
32
.DS_Store
3+
4+
*.log
5+
.env*

src/core/options.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
import { env } from "node:process";
22
import z from "zod";
33
import { autoBinPath } from "./scad-bin";
4-
import { BUILD_TIME_DEFAULT_THEME, THEMES } from "./themes";
4+
import { THEMES, theme } from "./themes";
55
import type { PluginTheme } from "./themes";
66

77
const StringBoolSchema = z.union([z.boolean(), z.stringbool()]);
88

9-
const envvar = (e: string) => String(env[e]);
9+
const createStringBoolSchema = (opts: { envvar: string; default: boolean }) => {
10+
return z
11+
.preprocess((val) => val ?? env[opts.envvar], StringBoolSchema)
12+
.default(opts.default);
13+
};
1014

1115
export const PluginOptionsSchema = z.object({
1216
launchPath: z.preprocess((val) => {
1317
if (val === null || val === "auto" || val === "nightly") {
14-
return autoBinPath(val);
18+
return autoBinPath(val ?? "auto");
1519
}
1620
return val;
17-
}, z.string()),
21+
}, z.string().optional()),
1822
layout: z.string().nullish(),
1923
theme: z
2024
.enum(THEMES)
21-
// .prefault(env.ELEVENTY_SCAD_THEME)
2225
.optional()
23-
.default(
24-
parseStringEnv<PluginTheme>("ELEVENTY_SCAD_THEME") ??
25-
BUILD_TIME_DEFAULT_THEME,
26-
),
27-
collectionPage: z
28-
.prefault(StringBoolSchema, envvar("ELEVENTY_SCAD_COLLECTION_PAGE"))
29-
.default(true),
30-
verbose: z
31-
.prefault(StringBoolSchema, envvar("ELEVENTY_SCAD_VERBOSE"))
32-
.default(false),
33-
silent: z
34-
.prefault(StringBoolSchema, envvar("ELEVENTY_SCAD_VERBOSE"))
35-
.default(false),
36-
noSTL: z
37-
.prefault(StringBoolSchema, envvar("ELEVENTY_SCAD_NO_STL"))
38-
.default(false),
39-
checkLaunchPath: z
40-
.prefault(StringBoolSchema, envvar("ELEVENTY_SCAD_CHECK_LAUNCH_PATH"))
41-
.default(true),
26+
.prefault(parseStringEnv<PluginTheme>("ELEVENTY_SCAD_THEME"))
27+
.default(theme("Midnight")),
28+
collectionPage: createStringBoolSchema({
29+
envvar: "ELEVENTY_SCAD_COLLECTION_PAGE",
30+
default: true,
31+
}),
32+
verbose: createStringBoolSchema({
33+
envvar: "ELEVENTY_SCAD_VERBOSE",
34+
default: false,
35+
}),
36+
silent: createStringBoolSchema({
37+
envvar: "ELEVENTY_SCAD_SILENT",
38+
default: false,
39+
}),
40+
noSTL: createStringBoolSchema({
41+
envvar: "ELEVENTY_SCAD_NO_STL",
42+
default: false,
43+
}),
44+
checkLaunchPath: createStringBoolSchema({
45+
envvar: "ELEVENTY_SCAD_CHECK_LAUNCH_PATH",
46+
default: true,
47+
}),
4248
});
4349

4450
function parseStringEnv<T>(envvar: string): T | undefined {

src/core/themes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const THEMES = [
99
"Ultramarine",
1010
] as const;
1111

12-
export type PluginTheme = (typeof THEMES)[number];
12+
export const theme = (t: PluginTheme) => t;
1313

14-
// This is defined in `tsdown.config.js` and will be replaced during build
15-
export const BUILD_TIME_DEFAULT_THEME = "__DEFAULT_THEME__" as PluginTheme;
14+
export type PluginTheme = (typeof THEMES)[number];

src/lib/home.ts

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

src/lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ export * from "./debug";
33
export * from "./logger";
44
export * from "./register";
55
export * from "./resolve";
6-
export * from "./theme";
76
export * from "./timer";

src/lib/theme.ts

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

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export type ParsedPluginOptions = z.output<typeof PluginOptionsSchema>;
1515

1616
export type PluginOptions = z.infer<typeof PluginOptionsSchema>;
1717

18-
export type StlViewerThemes = PluginOptions["theme"];
19-
2018
export type ScadTemplateData = {
2119
layout: string;
2220
title: string;

test/core/options.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from "vitest";
2+
import { PluginOptionsSchema } from "../../src/core/options";
3+
4+
describe("PluginOptionsSchema", () => {
5+
it("has sane defaults with no options set", () => {
6+
const o = PluginOptionsSchema.parse({});
7+
8+
expect(o).toMatchObject({
9+
checkLaunchPath: true,
10+
collectionPage: true,
11+
noSTL: false,
12+
silent: false,
13+
theme: "Midnight",
14+
verbose: false,
15+
});
16+
});
17+
});

tsdown.config.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import replace from "@rollup/plugin-replace";
21
import copy from "rollup-plugin-copy";
32
import { defineConfig } from "tsdown";
4-
import type { StlViewerThemes } from "./src/lib/types";
5-
6-
const DEFAULT_THEME: StlViewerThemes = "Midnight";
73

84
export default defineConfig([
95
{
@@ -12,12 +8,6 @@ export default defineConfig([
128
platform: "node",
139
dts: true,
1410
plugins: [
15-
replace({
16-
preventAssignment: true,
17-
values: {
18-
__DEFAULT_THEME__: DEFAULT_THEME,
19-
},
20-
}),
2111
copy({
2212
targets: [
2313
{

0 commit comments

Comments
 (0)