From 3bb73c0bd9e60cee6f7e2f49521d60562dcf207f Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 15 Nov 2023 09:27:04 +0100 Subject: [PATCH] Move plant configuration to different files (one per plant) --- package-lock.json | 19 -------- package.json | 1 - .../{plants.toml => plants/aloe-vera.toml} | 10 ++--- src/lib/assets/plants/monstera-deliciosa.toml | 36 ++++++++++++++++ src/lib/plants.ts | 43 +++++++++++++++++++ src/lib/types/index.d.ts | 5 +++ src/routes/plants/[plant]/+page.ts | 33 +------------- tsconfig.json | 7 +-- 8 files changed, 92 insertions(+), 62 deletions(-) rename src/lib/assets/{plants.toml => plants/aloe-vera.toml} (93%) create mode 100644 src/lib/assets/plants/monstera-deliciosa.toml create mode 100644 src/lib/plants.ts create mode 100644 src/lib/types/index.d.ts diff --git a/package-lock.json b/package-lock.json index 70cbbbb..42711d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "svelte-check": "^3.6.0", "tslib": "^2.4.1", "typescript": "^5.0.0", - "typescript-plugin-toml": "^0.3.1", "vite": "^4.4.2", "vite-plugin-toml": "^0.6.0" } @@ -1718,12 +1717,6 @@ "node": ">=8.0" } }, - "node_modules/toml": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", - "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", - "dev": true - }, "node_modules/toml-eslint-parser": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/toml-eslint-parser/-/toml-eslint-parser-0.6.1.tgz", @@ -1767,18 +1760,6 @@ "node": ">=14.17" } }, - "node_modules/typescript-plugin-toml": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/typescript-plugin-toml/-/typescript-plugin-toml-0.3.1.tgz", - "integrity": "sha512-pBRKcuidbQyGQZOejx3abJtjX2NRemYCIBImWAJ/Lek6byUJObw/j/jPwdlrOWEcIo37t4AHHeh9fXAgQ8FZzA==", - "dev": true, - "dependencies": { - "toml": "^3.0.0" - }, - "peerDependencies": { - "typescript": "^5.0.2" - } - }, "node_modules/undici": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici/-/undici-5.26.5.tgz", diff --git a/package.json b/package.json index 61e988d..04bded6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "svelte-check": "^3.6.0", "tslib": "^2.4.1", "typescript": "^5.0.0", - "typescript-plugin-toml": "^0.3.1", "vite": "^4.4.2", "vite-plugin-toml": "^0.6.0" }, diff --git a/src/lib/assets/plants.toml b/src/lib/assets/plants/aloe-vera.toml similarity index 93% rename from src/lib/assets/plants.toml rename to src/lib/assets/plants/aloe-vera.toml index 846dab9..4ed349b 100644 --- a/src/lib/assets/plants.toml +++ b/src/lib/assets/plants/aloe-vera.toml @@ -1,8 +1,8 @@ -[aloe-vera] +slug = "aloe-vera" name = "Aloe Vera" bin_name = "Aloe Vera" -[aloe-vera.image] +[image] small = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Aloe_Vera_%284700054020%29.jpg/320px-Aloe_Vera_%284700054020%29.jpg" medium = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Aloe_Vera_%284700054020%29.jpg/1024px-Aloe_Vera_%284700054020%29.jpg" large = "https://upload.wikimedia.org/wikipedia/commons/d/d2/Aloe_Vera_%284700054020%29.jpg" @@ -13,12 +13,12 @@ Tentacle-like succulent leaves sprout out from the base of the plant \ going up at multiple angles. """ -[aloe-vera.temp] +[temp] death = 5 lower = 12 upper = 29 -[aloe-vera.site] +[site] description = """ Aloe Vera prefers to grow in direct sunlight at temperatures between 12°C and 29°C. Temperatures below 5°C might kill the plant. Aloe Vera doesn't have any special humidity preferences. """ @@ -26,7 +26,7 @@ light = "full or part sun" humidity = "any" -[aloe-vera.care] +[care] description = """ Aloe Vera needs to be watered about ever 16 days. Make sure the soil is almost completely dry before watering it as it can be overwatered easily. """ diff --git a/src/lib/assets/plants/monstera-deliciosa.toml b/src/lib/assets/plants/monstera-deliciosa.toml new file mode 100644 index 0000000..f770237 --- /dev/null +++ b/src/lib/assets/plants/monstera-deliciosa.toml @@ -0,0 +1,36 @@ +slug = "monstera-deliciosa" +name = "Monstera Deliciosa" +bin_name = "Monstera Deliciosa" + +[image] +small = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/New_Monstera_Deliciosa_Leaf.jpg/360px-New_Monstera_Deliciosa_Leaf.jpg" +medium = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/New_Monstera_Deliciosa_Leaf.jpg/768px-New_Monstera_Deliciosa_Leaf.jpg" +large = "https://upload.wikimedia.org/wikipedia/commons/d/d4/New_Monstera_Deliciosa_Leaf.jpg" +source = "https://commons.wikimedia.org/wiki/File:New_Monstera_Deliciosa_Leaf.jpg" +alt = """ +Monstera deliciosa. \ +A big leaf with gaps is shown in the middle \ +with other leaves in the back. The leaf is heart-shaped. \ +The plant is potted in a pot with a moss stick.\ +""" + +[temp] +death = 10 +lower = 18 +upper = 24 + +[site] +description = """ +Monstera is best positioned in an area with changing shade and sunny conditions. It is best kept indoors at temperatures between 18°C and 24°C. Temperatures below 10°C might damage the plant. Monstera prefers high humidity which can be achieved by misting the plant regularly. Every 16 days common plant fertilizer can be applied. +""" +light = "shade, some sun" +humidity = "high" + +[care] +description = """ + On average Monstera needs to be watered every 8 days. Ideally when the top layer of the dirt has dried out. Monstera is used to growing in high humidity climate. Misting every week will increase the health of the plant as it rasises the humditity. Make sure to remove dead leaves and branches about every 3 months. +""" +water_schedule = "8 days" +mist_schedule = "week" +fertilize_schedule = "16 days" +clean_schedule = "3 months" diff --git a/src/lib/plants.ts b/src/lib/plants.ts new file mode 100644 index 0000000..7f8742c --- /dev/null +++ b/src/lib/plants.ts @@ -0,0 +1,43 @@ +import aloeVera from "$lib/assets/plants/aloe-vera.toml"; +import monsteraDeliciosa from "$lib/assets/plants/monstera-deliciosa.toml"; + +export type PlantData = { + slug: string; + name: string; + bin_name: string; + + image: { + small: string; + medium: string; + large: string; + source: string; + alt: string; + }; + temp: { + death: number; + lower: number; + upper: number; + }; + care: { + description: string; + water_schedule: string; + mist_schedule?: string; + fertilize_schedule?: string; + clean_schedule?: string; + }; + site: { + description: string; + light: string; + humidity?: string; + }; +}; + +type PlantMap = { [key: PlantData["slug"]]: PlantData }; + +export const plants: PlantMap = [aloeVera, monsteraDeliciosa].reduce( + (acc, cur) => { + acc[cur.slug] = cur; + return acc; + }, + {} as PlantMap, +); diff --git a/src/lib/types/index.d.ts b/src/lib/types/index.d.ts new file mode 100644 index 0000000..5d4aa18 --- /dev/null +++ b/src/lib/types/index.d.ts @@ -0,0 +1,5 @@ +declare module "$lib/assets/plants/*.toml" { + import type { PlantData } from "$lib/plants"; + const value: PlantData; + export default value; +} diff --git a/src/routes/plants/[plant]/+page.ts b/src/routes/plants/[plant]/+page.ts index ef951df..850b65a 100644 --- a/src/routes/plants/[plant]/+page.ts +++ b/src/routes/plants/[plant]/+page.ts @@ -1,37 +1,6 @@ import { error } from "@sveltejs/kit"; import type { PageLoad } from "./$types"; -// @ts-ignore -import plants from "$lib/assets/plants.toml"; - -export type PlantData = { - name: string; - bin_name: string; - - image: { - small: string; - medium: string; - large: string; - source: string; - alt: string; - }; - temp: { - death: number; - lower: number; - upper: number; - }; - care: { - description: string; - water_schedule: string; - mist_schedule?: string; - fertilize_schedule?: string; - clean_schedule?: string; - }; - site: { - description: string; - light: string; - humidity?: string; - }; -}; +import { plants, type PlantData } from "$lib/plants"; export const load: PageLoad = ({ params }) => { console.log(plants); diff --git a/tsconfig.json b/tsconfig.json index 6ae0c8c..bf65d1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,6 @@ "skipLibCheck": true, "sourceMap": true, "strict": true - } - // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias - // - // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes - // from the referenced tsconfig.json - TypeScript does not merge them in + }, + "typeRoots": ["src/lib/types/"] }