From 8b8c847457a46c3a6e6aabaf83198c0b7c1d3796 Mon Sep 17 00:00:00 2001 From: Jakob Rosenberg Date: Thu, 19 Dec 2024 17:36:48 +0100 Subject: [PATCH] feat: theme plugin --- lib/buildtime/RoutifyBuildtime.js | 3 + lib/buildtime/plugins/omitFromPath/index.js | 3 +- lib/buildtime/plugins/omitNode/index.js | 27 +++ lib/buildtime/plugins/themes/index.js | 13 ++ .../spec/example/@_lang/@at/blog/index.svelte | 1 + .../spec/example/@_lang/@at/index.svelte | 1 + .../@_lang/@de/@xmas/dexmasonly.svelte | 1 + .../example/@_lang/@de/@xmas/index.svelte | 1 + .../spec/example/@_lang/@de/index.svelte | 1 + .../plugins/themes/spec/example/about.svelte | 1 + .../themes/spec/example/blog/@de/index.svelte | 1 + .../themes/spec/example/blog/index.svelte | 1 + .../plugins/themes/spec/example/index.svelte | 1 + .../plugins/themes/spec/themes.test.js | 187 ++++++++++++++++++ lib/buildtime/plugins/themes/themes.js | 92 +++++++++ lib/buildtime/plugins/themes/utils.js | 100 ++++++++++ 16 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 lib/buildtime/plugins/omitNode/index.js create mode 100644 lib/buildtime/plugins/themes/index.js create mode 100644 lib/buildtime/plugins/themes/spec/example/@_lang/@at/blog/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/@_lang/@at/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/@_lang/@de/@xmas/dexmasonly.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/@_lang/@de/@xmas/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/@_lang/@de/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/about.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/blog/@de/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/blog/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/example/index.svelte create mode 100644 lib/buildtime/plugins/themes/spec/themes.test.js create mode 100644 lib/buildtime/plugins/themes/themes.js create mode 100644 lib/buildtime/plugins/themes/utils.js diff --git a/lib/buildtime/RoutifyBuildtime.js b/lib/buildtime/RoutifyBuildtime.js index e5240127..27fab2fe 100644 --- a/lib/buildtime/RoutifyBuildtime.js +++ b/lib/buildtime/RoutifyBuildtime.js @@ -18,6 +18,7 @@ import { devHelperPlugin } from './plugins/devHelper/helper.js' import { metaCapturePlugin } from './plugins/metaCapture/index.js' import { log, logs } from './logMsgs.js' import { omitDirFromPathPlugin } from './plugins/omitFromPath/index.js' +import { themesPlugin } from './plugins/themes/index.js' /** @returns {Partial} */ const getDefaults = () => ({ @@ -30,6 +31,7 @@ const getDefaults = () => ({ resetFiles: ['_reset'], fallbackFiles: ['_fallback'], }, + themes: { presets: {} }, logLevel: 3, routesDir: { default: 'src/routes', @@ -48,6 +50,7 @@ const getDefaults = () => ({ devHelperPlugin, metaCapturePlugin, omitDirFromPathPlugin, + themesPlugin, ], watch: false, }) diff --git a/lib/buildtime/plugins/omitFromPath/index.js b/lib/buildtime/plugins/omitFromPath/index.js index 25d51531..e97dac76 100644 --- a/lib/buildtime/plugins/omitFromPath/index.js +++ b/lib/buildtime/plugins/omitFromPath/index.js @@ -5,7 +5,8 @@ export const omitDirFromPathPlugin = { before: 'bundler', build: ({ instance }) => { // find file names that are enclosed in a parenthesis - const omittedDir = node => node.file.name.match(/\(([^)]+)\)/) + const omittedDir = node => + node.file.name.startsWith('(') && node.file.name.endsWith(')') // remove the node and move its children to the parent instance.nodeIndex.filter(omittedDir).forEach(node => { diff --git a/lib/buildtime/plugins/omitNode/index.js b/lib/buildtime/plugins/omitNode/index.js new file mode 100644 index 00000000..1a7d1a31 --- /dev/null +++ b/lib/buildtime/plugins/omitNode/index.js @@ -0,0 +1,27 @@ +/* + Always omit + + + Omit in production + + + Omit in multiple environments +