From 8b50a30e384830b9c5990e8b596b6d31b552c4c3 Mon Sep 17 00:00:00 2001 From: jycouet Date: Tue, 31 Oct 2023 20:07:26 +0200 Subject: [PATCH 01/10] :tada: NEW: kit-routes is born --- .changeset/polite-ghosts-carry.md | 5 ++ packages/vite-plugin-kit-routes/.eslintrc.cjs | 3 + packages/vite-plugin-kit-routes/.gitignore | 11 +++ packages/vite-plugin-kit-routes/.npmrc | 1 + packages/vite-plugin-kit-routes/CHANGELOG.md | 1 + packages/vite-plugin-kit-routes/README.md | 5 ++ packages/vite-plugin-kit-routes/package.json | 65 ++++++++++++++ packages/vite-plugin-kit-routes/src/app.d.ts | 12 +++ packages/vite-plugin-kit-routes/src/app.html | 12 +++ .../vite-plugin-kit-routes/src/lib/ROUTES.ts | 10 +++ packages/vite-plugin-kit-routes/src/lib/fs.ts | 26 ++++++ .../vite-plugin-kit-routes/src/lib/index.ts | 84 ++++++++++++++++++ .../src/lib/plugins.spec.ts | 31 +++++++ .../src/routes/+layout.svelte | 20 +++++ .../src/routes/+page.svelte | 1 + .../src/routes/site/[id]/+page.svelte | 1 + .../routes/site/[param]/[yop]/+page.svelte | 1 + .../vite-plugin-kit-routes/static/favicon.png | Bin 0 -> 1571 bytes .../vite-plugin-kit-routes/svelte.config.js | 18 ++++ packages/vite-plugin-kit-routes/tsconfig.json | 14 +++ .../vite-plugin-kit-routes/vite.config.ts | 15 ++++ pnpm-lock.yaml | 44 +++++++++ .../docs/tools/06_vite-plugin-kit-routes.mdx | 36 ++++++++ website/src/pages/docs/tools/_meta.ts | 1 + 24 files changed, 417 insertions(+) create mode 100644 .changeset/polite-ghosts-carry.md create mode 100644 packages/vite-plugin-kit-routes/.eslintrc.cjs create mode 100644 packages/vite-plugin-kit-routes/.gitignore create mode 100644 packages/vite-plugin-kit-routes/.npmrc create mode 100644 packages/vite-plugin-kit-routes/CHANGELOG.md create mode 100644 packages/vite-plugin-kit-routes/README.md create mode 100644 packages/vite-plugin-kit-routes/package.json create mode 100644 packages/vite-plugin-kit-routes/src/app.d.ts create mode 100644 packages/vite-plugin-kit-routes/src/app.html create mode 100644 packages/vite-plugin-kit-routes/src/lib/ROUTES.ts create mode 100644 packages/vite-plugin-kit-routes/src/lib/fs.ts create mode 100644 packages/vite-plugin-kit-routes/src/lib/index.ts create mode 100644 packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts create mode 100644 packages/vite-plugin-kit-routes/src/routes/+layout.svelte create mode 100644 packages/vite-plugin-kit-routes/src/routes/+page.svelte create mode 100644 packages/vite-plugin-kit-routes/src/routes/site/[id]/+page.svelte create mode 100644 packages/vite-plugin-kit-routes/src/routes/site/[param]/[yop]/+page.svelte create mode 100644 packages/vite-plugin-kit-routes/static/favicon.png create mode 100644 packages/vite-plugin-kit-routes/svelte.config.js create mode 100644 packages/vite-plugin-kit-routes/tsconfig.json create mode 100644 packages/vite-plugin-kit-routes/vite.config.ts create mode 100644 website/src/pages/docs/tools/06_vite-plugin-kit-routes.mdx diff --git a/.changeset/polite-ghosts-carry.md b/.changeset/polite-ghosts-carry.md new file mode 100644 index 000000000..72a0b68e7 --- /dev/null +++ b/.changeset/polite-ghosts-carry.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-kit-routes': patch +--- + +init plugin diff --git a/packages/vite-plugin-kit-routes/.eslintrc.cjs b/packages/vite-plugin-kit-routes/.eslintrc.cjs new file mode 100644 index 000000000..13b901e03 --- /dev/null +++ b/packages/vite-plugin-kit-routes/.eslintrc.cjs @@ -0,0 +1,3 @@ +module.exports = { + extends: ['eslint-config-kitql'], +} diff --git a/packages/vite-plugin-kit-routes/.gitignore b/packages/vite-plugin-kit-routes/.gitignore new file mode 100644 index 000000000..ac7211b40 --- /dev/null +++ b/packages/vite-plugin-kit-routes/.gitignore @@ -0,0 +1,11 @@ +.DS_Store +node_modules +/build +/dist +/.svelte-kit +/package +.env +.env.* +!.env.example +vite.config.js.timestamp-* +vite.config.ts.timestamp-* diff --git a/packages/vite-plugin-kit-routes/.npmrc b/packages/vite-plugin-kit-routes/.npmrc new file mode 100644 index 000000000..b6f27f135 --- /dev/null +++ b/packages/vite-plugin-kit-routes/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/packages/vite-plugin-kit-routes/CHANGELOG.md b/packages/vite-plugin-kit-routes/CHANGELOG.md new file mode 100644 index 000000000..1e9f0478a --- /dev/null +++ b/packages/vite-plugin-kit-routes/CHANGELOG.md @@ -0,0 +1 @@ +# vite-plugin-kit-routes diff --git a/packages/vite-plugin-kit-routes/README.md b/packages/vite-plugin-kit-routes/README.md new file mode 100644 index 000000000..db0c1cd7b --- /dev/null +++ b/packages/vite-plugin-kit-routes/README.md @@ -0,0 +1,5 @@ +# ⚡vite-plugin-watch-and-run + +_Part of [KitQL](https://github.com/jycouet/kitql#kitql), a set of tools helping **you** building efficient apps in a fast way._ + +### 👉 Check the [⚡Doc⚡](https://kitql.dev/docs/tools/06_vite-plugin-kit-routes) diff --git a/packages/vite-plugin-kit-routes/package.json b/packages/vite-plugin-kit-routes/package.json new file mode 100644 index 000000000..a31a386fb --- /dev/null +++ b/packages/vite-plugin-kit-routes/package.json @@ -0,0 +1,65 @@ +{ + "name": "vite-plugin-kit-routes", + "description": "vite-plugin that will help you maintain your routes in a single file", + "keywords": [ + "vite" + ], + "version": "0.0.1", + "license": "MIT", + "type": "module", + "repository": { + "type": "git", + "url": "https://github.com/jycouet/kitql", + "directory": "packages/vite-plugin-kit-routes", + "homepage": "https://github.com/jycouet/kitql/tree/main/packages/vite-plugin-kit-routes#readme" + }, + "scripts": { + "prepare": "svelte-kit sync", + "dev": "vite dev", + "build": "vite build && svelte-package && node ../../scripts/package.js", + "preview": "vite preview", + "package": "svelte-package && publint", + "check": "svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch", + "test": "vitest", + "test:ci": "vitest --coverage", + "lint": "kitql-lint", + "format": "kitql-lint --fix" + }, + "devDependencies": { + "eslint-config-kitql": "workspace:*", + "@sveltejs/adapter-auto": "2.1.0", + "@sveltejs/kit": "1.25.2", + "@sveltejs/package": "2.2.2", + "publint": "0.2.4", + "svelte": "4.2.1", + "svelte-check": "3.5.2", + "tslib": "2.6.2", + "typescript": "5.2.2", + "vite": "4.4.2", + "vitest": "0.34.6" + }, + "dependencies": { + "@kitql/helpers": "workspace:*", + "vite-plugin-watch-and-run": "workspace:*" + }, + "sideEffects": false, + "publishConfig": { + "directory": "dist", + "access": "public" + }, + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*" + ], + "svelte": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js", + "svelte": "./dist/index.js" + } + } +} diff --git a/packages/vite-plugin-kit-routes/src/app.d.ts b/packages/vite-plugin-kit-routes/src/app.d.ts new file mode 100644 index 000000000..0425013af --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/app.d.ts @@ -0,0 +1,12 @@ +// See https://kit.svelte.dev/docs/types#app +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface Platform {} + } +} + +export {} diff --git a/packages/vite-plugin-kit-routes/src/app.html b/packages/vite-plugin-kit-routes/src/app.html new file mode 100644 index 000000000..85d6c8f6b --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts new file mode 100644 index 000000000..aca524832 --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts @@ -0,0 +1,10 @@ +export const ROUTES = { + "/": (sp?: Record) => { return `/${appendSp(sp)}` }, + "/site/[id]": (id: string, sp?: Record) => { return `/site/${id}${appendSp(sp)}` }, + "/site/[param]/[yop]": (param: string, yop: string, sp?: Record) => { return `/site/${param}/${yop}${appendSp(sp)}` } +} + +const appendSp = (sp?: Record) => { + if (sp === undefined) return '' + return `?${new URLSearchParams(sp || {}).toString()}` +} diff --git a/packages/vite-plugin-kit-routes/src/lib/fs.ts b/packages/vite-plugin-kit-routes/src/lib/fs.ts new file mode 100644 index 000000000..56ead09bf --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/lib/fs.ts @@ -0,0 +1,26 @@ +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs' +import { dirname, join } from 'node:path' + +export function read(pathFile: string) { + return readFileSync(pathFile, { encoding: 'utf8' }) +} + +export function write(pathFile: string, data: string[]) { + const fullDataToWrite = Array.isArray(data) ? data.join('\n') : data + createFolderIfNotExists(dirname(pathFile)) + // Don't write if nothing changed! + if (existsSync(pathFile)) { + const currentFileData = read(pathFile) + if (fullDataToWrite === currentFileData) { + return false + } + } + writeFileSync(join(pathFile), fullDataToWrite) + return true +} + +function createFolderIfNotExists(dir: string) { + if (!existsSync(dir)) { + mkdirSync(dir, { recursive: true }) + } +} diff --git a/packages/vite-plugin-kit-routes/src/lib/index.ts b/packages/vite-plugin-kit-routes/src/lib/index.ts new file mode 100644 index 000000000..c12323e22 --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/lib/index.ts @@ -0,0 +1,84 @@ +import { readdirSync } from 'fs' +import { Log, yellow } from '@kitql/helpers' +import type { Plugin } from 'vite' +import watch_and_run from 'vite-plugin-watch-and-run' +import { write } from './fs.js' + +const nbOverlap = (a1: readonly any[], a2: readonly any[]) => { + return a1.filter(value => a2?.includes(value)).length +} + +export type Options = {} + +const routes_path = 'src/lib/ROUTES.ts' +const log = new Log('Kit Routes') + +const getFiles = (dirPath: string) => { + const files = readdirSync(dirPath, { recursive: true }) as string[] + return files + .filter(file => file.endsWith('+page.svelte')) + .map(file => `/` + file.replace('/+page.svelte', '').replace('+page.svelte', '')) +} + +export function extractParamsFromPath(path: string): string[] { + // Use a regular expression to match parameter placeholders like '[param]' + const paramPattern = /\[([^\]]+)]/g + const params = [] + + let match + while ((match = paramPattern.exec(path)) !== null) { + // The matched parameter name is in the first capturing group + params.push(match[1]) + } + + return params +} + +const run = () => { + const files = getFiles(`${process.cwd()}/src/routes`) + + const res = write(routes_path, [ + `export const ROUTES = { + ${files + .map(file_path => { + const params = extractParamsFromPath(file_path).map(c => `${c}: string`) + params.push(`sp?: Record`) + return ( + `"${file_path}": (${params.join(', ')}) => ` + + `{ return \`${file_path.replaceAll('[', '${').replaceAll(']', '}')}\${appendSp(sp)}\` }` + ) + }) + .join(',\n ')} +} + +const appendSp = (sp?: Record) => { + if (sp === undefined) return '' + return \`?\${new URLSearchParams(sp || {}).toString()}\` +} +`, + ]) + if (res) { + log.success(`${yellow(routes_path)} updated`) + } +} + +export function kit_routes(params?: Options): Plugin[] { + return [ + // Run the thing at startup + { + name: 'kit-routes', + configureServer() { + run() + }, + }, + // Run the thing when any change in a +page.svelte (add, remove, ...) + watch_and_run([ + { + name: 'kit-routes-watch', + logs: [], + watch: '**/+page.svelte', + run, + }, + ]), + ] +} diff --git a/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts b/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts new file mode 100644 index 000000000..83eae4175 --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/lib/plugins.spec.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from 'vitest' +import { extractParamsFromPath } from './index.js' + +describe('vite-plugin-kit-routes', () => { + it('get id', async () => { + expect(extractParamsFromPath('/site/[id]')).toMatchInlineSnapshot(` + [ + "id", + ] + `) + }) + + it('get params & id', async () => { + expect(extractParamsFromPath('/site/[param]/[id]')).toMatchInlineSnapshot(` + [ + "param", + "id", + ] + `) + }) + + it('get params & id', async () => { + expect(extractParamsFromPath('/[param]site/[yop](group)/[id]')).toMatchInlineSnapshot(` + [ + "param", + "yop", + "id", + ] + `) + }) +}) diff --git a/packages/vite-plugin-kit-routes/src/routes/+layout.svelte b/packages/vite-plugin-kit-routes/src/routes/+layout.svelte new file mode 100644 index 000000000..98bf556fa --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/routes/+layout.svelte @@ -0,0 +1,20 @@ + + + + + + +

vite-plugin-kit-routes

+ +
+ + + +
+ + diff --git a/packages/vite-plugin-kit-routes/src/routes/+page.svelte b/packages/vite-plugin-kit-routes/src/routes/+page.svelte new file mode 100644 index 000000000..277f8e93b --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/routes/+page.svelte @@ -0,0 +1 @@ +

Home

diff --git a/packages/vite-plugin-kit-routes/src/routes/site/[id]/+page.svelte b/packages/vite-plugin-kit-routes/src/routes/site/[id]/+page.svelte new file mode 100644 index 000000000..5f468cf20 --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/routes/site/[id]/+page.svelte @@ -0,0 +1 @@ +

site [id]

diff --git a/packages/vite-plugin-kit-routes/src/routes/site/[param]/[yop]/+page.svelte b/packages/vite-plugin-kit-routes/src/routes/site/[param]/[yop]/+page.svelte new file mode 100644 index 000000000..6779db80c --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/routes/site/[param]/[yop]/+page.svelte @@ -0,0 +1 @@ +

site [param] [yop]

diff --git a/packages/vite-plugin-kit-routes/static/favicon.png b/packages/vite-plugin-kit-routes/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..825b9e65af7c104cfb07089bb28659393b4f2097 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UHNever be out of sync with your routes again 🥳 + +## Installation + +```sh npm2yarn +npm i -D vite-plugin-kit-routes +``` + +## Configuration + +Add `kit-routes` plugin with the following configuration: + +```js filename="vite.config.js" +import { kit_routes } from 'vite-plugin-kit-routes' + +/** @type {import('vite').UserConfig} */ +const config = { + plugins: [ + // This is the plugin to add + kit_routes() + ] +} + +export default config +``` + +It will create a file `./src/lib/ROUTES.ts` at the start of your dev server & any update of any of +your `+page.svelte`. + +## Side Notes + +- It's very early, things might change! 😉 diff --git a/website/src/pages/docs/tools/_meta.ts b/website/src/pages/docs/tools/_meta.ts index 59926046c..8232f9642 100644 --- a/website/src/pages/docs/tools/_meta.ts +++ b/website/src/pages/docs/tools/_meta.ts @@ -1,5 +1,6 @@ export default { '04_helpers': 'Helpers', '03_vite-plugin-watch-and-run': 'Vite - Watch and Run', + '06_vite-plugin-kit-routes': 'Vite - Kit Routes', '05_handles': 'SvelteKit - Handles', } From 7a9d0b3a1e00ddc538b28935f4c41dd9b36689cb Mon Sep 17 00:00:00 2001 From: jycouet Date: Tue, 31 Oct 2023 20:15:52 +0200 Subject: [PATCH 02/10] :bug: FIX: get the last version of watch-and-run --- packages/vite-plugin-kit-routes/src/lib/index.ts | 4 ---- scripts/package.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/vite-plugin-kit-routes/src/lib/index.ts b/packages/vite-plugin-kit-routes/src/lib/index.ts index c12323e22..3db1193be 100644 --- a/packages/vite-plugin-kit-routes/src/lib/index.ts +++ b/packages/vite-plugin-kit-routes/src/lib/index.ts @@ -4,10 +4,6 @@ import type { Plugin } from 'vite' import watch_and_run from 'vite-plugin-watch-and-run' import { write } from './fs.js' -const nbOverlap = (a1: readonly any[], a2: readonly any[]) => { - return a1.filter(value => a2?.includes(value)).length -} - export type Options = {} const routes_path = 'src/lib/ROUTES.ts' diff --git a/scripts/package.js b/scripts/package.js index 27b998eac..53b10a1d3 100644 --- a/scripts/package.js +++ b/scripts/package.js @@ -14,6 +14,17 @@ const packageDirPath = process.cwd() const packageJsonPath = path.join(packageDirPath, 'package.json') const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) +// getting vite-plugin-watch-and-run version (should be generated by the build script) +const pkgVitePluginWatchAndRun = JSON.parse( + fs.readFileSync( + path.join(packageDirPath, '../vite-plugin-watch-and-run', 'package.json'), + 'utf-8', + ), +) +if (pkg?.dependencies?.['vite-plugin-watch-and-run']) { + pkg.dependencies['vite-plugin-watch-and-run'] = pkgVitePluginWatchAndRun.version +} + // getting @kitql/helpers version (should be generated by the build script) const pkgHelper = JSON.parse( fs.readFileSync(path.join(packageDirPath, '../helpers', 'package.json'), 'utf-8'), From 95fedd7e8ff154952348ac5b26c5ccbafa897bbd Mon Sep 17 00:00:00 2001 From: jycouet Date: Tue, 31 Oct 2023 20:19:14 +0200 Subject: [PATCH 03/10] :ok_hand: FIX: prettier --- .prettierignore | 2 ++ packages/vite-plugin-kit-routes/vite.config.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index 273d59d72..14389e065 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,6 +12,8 @@ CHANGELOG.md package.json build +ROUTES.ts + $houdini $kitql stats.html \ No newline at end of file diff --git a/packages/vite-plugin-kit-routes/vite.config.ts b/packages/vite-plugin-kit-routes/vite.config.ts index 9e21660cd..334189154 100644 --- a/packages/vite-plugin-kit-routes/vite.config.ts +++ b/packages/vite-plugin-kit-routes/vite.config.ts @@ -1,4 +1,3 @@ -import path from 'path' import { sveltekit } from '@sveltejs/kit/vite' import { defineConfig } from 'vite' import { kit_routes } from './src/lib/index.js' From 14923e5f9b203064e0c615d44ebc2f6d81bce3cf Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:25:23 +0200 Subject: [PATCH 04/10] :tada: NEW: watch can look at an array of globs now --- .changeset/eleven-lies-behave.md | 5 ++ .../src/lib/index.ts | 4 +- .../src/lib/micromatch.spec.ts | 59 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .changeset/eleven-lies-behave.md create mode 100644 packages/vite-plugin-watch-and-run/src/lib/micromatch.spec.ts diff --git a/.changeset/eleven-lies-behave.md b/.changeset/eleven-lies-behave.md new file mode 100644 index 000000000..99efb3cf4 --- /dev/null +++ b/.changeset/eleven-lies-behave.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-watch-and-run': patch +--- + +watch can look at an array of globs now diff --git a/packages/vite-plugin-watch-and-run/src/lib/index.ts b/packages/vite-plugin-watch-and-run/src/lib/index.ts index 0b2058839..9ceb377bd 100644 --- a/packages/vite-plugin-watch-and-run/src/lib/index.ts +++ b/packages/vite-plugin-watch-and-run/src/lib/index.ts @@ -11,7 +11,7 @@ export type Options = { /** * watch files to trigger the run action (glob format) */ - watch?: string + watch?: string | string[] /** * watch files to trigger the run action (function format) @@ -69,7 +69,7 @@ export type StateDetail = { delay: number isRunning: boolean watchFile?: (filepath: string) => boolean | Promise - watch?: string + watch?: string | string[] name?: string | null shell: string | boolean formatErrors?: (e: unknown, afterError?: (e: Error) => void) => void diff --git a/packages/vite-plugin-watch-and-run/src/lib/micromatch.spec.ts b/packages/vite-plugin-watch-and-run/src/lib/micromatch.spec.ts new file mode 100644 index 000000000..98d0766b9 --- /dev/null +++ b/packages/vite-plugin-watch-and-run/src/lib/micromatch.spec.ts @@ -0,0 +1,59 @@ +// micromatch.isMatch(absolutePath, info.watch) + +import micromatch from 'micromatch' +import { describe, expect, it } from 'vitest' + +describe('micromatch', () => { + it('1', async () => { + expect( + micromatch.isMatch( + '/home/asbPath/site/[id]/one/[hello]/+page.server.ts', + '**/+page.server.ts', + ), + ).toBe(true) + }) + + it('2', async () => { + expect( + micromatch.isMatch( + '/home/asbPath/site/[id]/one/[hello]/+page.server.ts', + '**/(+page.server.ts)', + ), + ).toBe(true) + }) + + it('3', async () => { + expect( + micromatch.isMatch('/home/asbPath/site/[id]/one/[hello]/+page.server.ts', [ + '**/+page.server.ts', + '**/+page.svelte', + ]), + ).toBe(true) + }) + + it('4', async () => { + expect( + micromatch.isMatch('/home/asbPath/site/[id]/one/[hello]/+page.server.ts', [ + '**/+page.svelte', + ]), + ).toBe(false) + }) + + it('5', async () => { + expect( + micromatch.isMatch('/home/asbPath/site/[id]/one/[hello]/+page.svelte', [ + '**/+page.server.ts', + '**/+page.svelte', + ]), + ).toBe(true) + }) + + it('5', async () => { + expect( + micromatch.isMatch('/home/asbPath/site/[id]/one/[hello]/+page.svelteNOT', [ + '**/+page.server.ts', + '**/+page.svelte', + ]), + ).toBe(false) + }) +}) From 061879b38f997f0a40212e7f3bac1a89c7b7f7e9 Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:25:33 +0200 Subject: [PATCH 05/10] :construction: UPDATE: I need to commit sometime! --- .prettierignore | 2 - .../vite-plugin-kit-routes/src/lib/ROUTES.ts | 20 ++++- .../vite-plugin-kit-routes/src/lib/index.ts | 76 +++++++++++++++---- .../src/routes/+layout.svelte | 6 +- .../site/[id]/two/[hello]/+page.server.ts | 0 .../vite-plugin-kit-routes/vite.config.ts | 2 +- 6 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+page.server.ts diff --git a/.prettierignore b/.prettierignore index 14389e065..273d59d72 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,8 +12,6 @@ CHANGELOG.md package.json build -ROUTES.ts - $houdini $kitql stats.html \ No newline at end of file diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts index aca524832..f4542f7b1 100644 --- a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts +++ b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts @@ -1,7 +1,19 @@ -export const ROUTES = { - "/": (sp?: Record) => { return `/${appendSp(sp)}` }, - "/site/[id]": (id: string, sp?: Record) => { return `/site/${id}${appendSp(sp)}` }, - "/site/[param]/[yop]": (param: string, yop: string, sp?: Record) => { return `/site/${param}/${yop}${appendSp(sp)}` } +export const PAGES = { + '/': (sp?: Record) => { + return `/${appendSp(sp)}` + }, + '/site/[id]': (id: string, sp?: Record) => { + return `/site/${id}${appendSp(sp)}` + }, + '/site/[param]/[yop]': (param: string, yop: string, sp?: Record) => { + return `/site/${param}/${yop}${appendSp(sp)}` + }, +} + +export const SERVER_PAGES = { + '/site/[id]/two/[hello]': (id: string, hello: string, sp?: Record) => { + return `/site/${id}/two/${hello}${appendSp(sp)}` + }, } const appendSp = (sp?: Record) => { diff --git a/packages/vite-plugin-kit-routes/src/lib/index.ts b/packages/vite-plugin-kit-routes/src/lib/index.ts index 3db1193be..1e30b7cd2 100644 --- a/packages/vite-plugin-kit-routes/src/lib/index.ts +++ b/packages/vite-plugin-kit-routes/src/lib/index.ts @@ -1,19 +1,30 @@ import { readdirSync } from 'fs' -import { Log, yellow } from '@kitql/helpers' +import { spawn } from 'node:child_process' +import { green, Log, yellow } from '@kitql/helpers' import type { Plugin } from 'vite' import watch_and_run from 'vite-plugin-watch-and-run' import { write } from './fs.js' -export type Options = {} +export type Options = { + /** + * run command after file updated + * + * @example + * ```ts + * 'npm exec prettier ./src/lib/ROUTES.ts -- -w' + * ``` + */ + post_update_run?: string +} const routes_path = 'src/lib/ROUTES.ts' const log = new Log('Kit Routes') -const getFiles = (dirPath: string) => { +const getFiles = (dirPath: string, lookFor: '+page.svelte' | '+page.server.ts') => { const files = readdirSync(dirPath, { recursive: true }) as string[] return files - .filter(file => file.endsWith('+page.svelte')) - .map(file => `/` + file.replace('/+page.svelte', '').replace('+page.svelte', '')) + .filter(file => file.endsWith(lookFor)) + .map(file => `/` + file.replace(`/${lookFor}`, '').replace(lookFor, '')) } export function extractParamsFromPath(path: string): string[] { @@ -30,12 +41,26 @@ export function extractParamsFromPath(path: string): string[] { return params } -const run = () => { - const files = getFiles(`${process.cwd()}/src/routes`) +const run = (params?: Options) => { + const files_pages = getFiles(`${process.cwd()}/src/routes`, '+page.svelte') + const files_server_pages = getFiles(`${process.cwd()}/src/routes`, '+page.server.ts') - const res = write(routes_path, [ - `export const ROUTES = { - ${files + const result = write(routes_path, [ + `export const PAGES = { + ${files_pages + .map(file_path => { + const params = extractParamsFromPath(file_path).map(c => `${c}: string`) + params.push(`sp?: Record`) + return ( + `"${file_path}": (${params.join(', ')}) => ` + + `{ return \`${file_path.replaceAll('[', '${').replaceAll(']', '}')}\${appendSp(sp)}\` }` + ) + }) + .join(',\n ')} +} + +export const SERVER_PAGES = { + ${files_server_pages .map(file_path => { const params = extractParamsFromPath(file_path).map(c => `${c}: string`) params.push(`sp?: Record`) @@ -53,8 +78,28 @@ const appendSp = (sp?: Record) => { } `, ]) - if (res) { - log.success(`${yellow(routes_path)} updated`) + + // TODO: optimize this later. We want to write the new file only if different after prettier?! (having a tmp file somewhere?) + if (params?.post_update_run) { + log.info(`${yellow(`post_update_run`)} "${green(params?.post_update_run)}" running...`) + const child = spawn(params.post_update_run, { shell: true }) + child.stdout.on('data', data => { + if (data.toString()) { + log.info(data.toString()) + } + }) + child.stderr.on('data', data => { + log.error(data.toString()) + }) + child.on('close', code => { + if (result) { + log.success(`${yellow(routes_path)} updated`) + } + }) + } else { + if (result) { + log.success(`${yellow(routes_path)} updated`) + } } } @@ -64,16 +109,17 @@ export function kit_routes(params?: Options): Plugin[] { { name: 'kit-routes', configureServer() { - run() + run(params) }, }, + // Run the thing when any change in a +page.svelte (add, remove, ...) watch_and_run([ { name: 'kit-routes-watch', logs: [], - watch: '**/+page.svelte', - run, + watch: ['**/+page.svelte', '**/+page.server.ts'], + run: () => run(params), }, ]), ] diff --git a/packages/vite-plugin-kit-routes/src/routes/+layout.svelte b/packages/vite-plugin-kit-routes/src/routes/+layout.svelte index 98bf556fa..8007a9eda 100644 --- a/packages/vite-plugin-kit-routes/src/routes/+layout.svelte +++ b/packages/vite-plugin-kit-routes/src/routes/+layout.svelte @@ -1,5 +1,5 @@ @@ -11,8 +11,8 @@

diff --git a/packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+page.server.ts b/packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+page.server.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/vite-plugin-kit-routes/vite.config.ts b/packages/vite-plugin-kit-routes/vite.config.ts index 334189154..33dc7a80a 100644 --- a/packages/vite-plugin-kit-routes/vite.config.ts +++ b/packages/vite-plugin-kit-routes/vite.config.ts @@ -6,7 +6,7 @@ export default defineConfig({ plugins: [ sveltekit(), // demo - kit_routes(), + kit_routes({ post_update_run: 'npm exec prettier ./src/lib/ROUTES.ts -- -w' }), ], test: { include: ['src/**/*.{test,spec}.{js,ts}'], From 8ce91d6a8535ce4124df463421baca684fadcfb9 Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:35:26 +0200 Subject: [PATCH 06/10] :construction: NEW: PAGES / SERVERS / ACTIONS --- .../vite-plugin-kit-routes/src/lib/ROUTES.ts | 10 +++++++- .../vite-plugin-kit-routes/src/lib/index.ts | 23 +++++++++++++++---- .../routes/site/[id]/two/[hello]/+server.ts | 5 ++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+server.ts diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts index f4542f7b1..ae57c0e26 100644 --- a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts +++ b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts @@ -10,12 +10,20 @@ export const PAGES = { }, } -export const SERVER_PAGES = { +// TODO: SERVERS methods? +export const SERVERS = { '/site/[id]/two/[hello]': (id: string, hello: string, sp?: Record) => { return `/site/${id}/two/${hello}${appendSp(sp)}` }, } +// TODO: name actions +export const ACTIONS = { + '/site/[id]/two/[hello]': (id: string, hello: string) => { + return `/site/${id}/two/${hello}` + }, +} + const appendSp = (sp?: Record) => { if (sp === undefined) return '' return `?${new URLSearchParams(sp || {}).toString()}` diff --git a/packages/vite-plugin-kit-routes/src/lib/index.ts b/packages/vite-plugin-kit-routes/src/lib/index.ts index 1e30b7cd2..d9b5277a5 100644 --- a/packages/vite-plugin-kit-routes/src/lib/index.ts +++ b/packages/vite-plugin-kit-routes/src/lib/index.ts @@ -20,7 +20,7 @@ export type Options = { const routes_path = 'src/lib/ROUTES.ts' const log = new Log('Kit Routes') -const getFiles = (dirPath: string, lookFor: '+page.svelte' | '+page.server.ts') => { +const getFiles = (dirPath: string, lookFor: '+page.svelte' | '+page.server.ts' | '+server.ts') => { const files = readdirSync(dirPath, { recursive: true }) as string[] return files .filter(file => file.endsWith(lookFor)) @@ -44,6 +44,7 @@ export function extractParamsFromPath(path: string): string[] { const run = (params?: Options) => { const files_pages = getFiles(`${process.cwd()}/src/routes`, '+page.svelte') const files_server_pages = getFiles(`${process.cwd()}/src/routes`, '+page.server.ts') + const files_server = getFiles(`${process.cwd()}/src/routes`, '+server.ts') const result = write(routes_path, [ `export const PAGES = { @@ -59,8 +60,9 @@ const run = (params?: Options) => { .join(',\n ')} } -export const SERVER_PAGES = { - ${files_server_pages +// TODO: SERVERS methods? +export const SERVERS = { + ${files_server .map(file_path => { const params = extractParamsFromPath(file_path).map(c => `${c}: string`) params.push(`sp?: Record`) @@ -72,6 +74,19 @@ export const SERVER_PAGES = { .join(',\n ')} } +// TODO: name actions +export const ACTIONS = { + ${files_server_pages + .map(file_path => { + const params = extractParamsFromPath(file_path).map(c => `${c}: string`) + return ( + `"${file_path}": (${params.join(', ')}) => ` + + `{ return \`${file_path.replaceAll('[', '${').replaceAll(']', '}')}\` }` + ) + }) + .join(',\n ')} +} + const appendSp = (sp?: Record) => { if (sp === undefined) return '' return \`?\${new URLSearchParams(sp || {}).toString()}\` @@ -118,7 +133,7 @@ export function kit_routes(params?: Options): Plugin[] { { name: 'kit-routes-watch', logs: [], - watch: ['**/+page.svelte', '**/+page.server.ts'], + watch: ['**/+page.svelte', '**/+page.server.ts', '**/+server.ts'], run: () => run(params), }, ]), diff --git a/packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+server.ts b/packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+server.ts new file mode 100644 index 000000000..3b4312885 --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+server.ts @@ -0,0 +1,5 @@ +import type { RequestHandler } from './$types' + +export const GET: RequestHandler = async () => { + return new Response() +} From 58570dbbb89585e0beadb7f056cde8597ecbd7a4 Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:40:47 +0200 Subject: [PATCH 07/10] :construction: UPDATE: tune generated_file_path location --- .../vite-plugin-kit-routes/src/lib/ROUTES2.ts | 20 +++++++++++++++++++ .../vite-plugin-kit-routes/src/lib/index.ts | 17 ++++++++++++---- .../vite-plugin-kit-routes/vite.config.ts | 6 +++++- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts new file mode 100644 index 000000000..bb43d655f --- /dev/null +++ b/packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts @@ -0,0 +1,20 @@ +export const PAGES = { + "/": (sp?: Record) => { return `/${appendSp(sp)}` }, + "/site/[id]": (id: string, sp?: Record) => { return `/site/${id}${appendSp(sp)}` }, + "/site/[param]/[yop]": (param: string, yop: string, sp?: Record) => { return `/site/${param}/${yop}${appendSp(sp)}` } +} + +// TODO: SERVERS methods? +export const SERVERS = { + "/site/[id]/two/[hello]": (id: string, hello: string, sp?: Record) => { return `/site/${id}/two/${hello}${appendSp(sp)}` } +} + +// TODO: name actions +export const ACTIONS = { + "/site/[id]/two/[hello]": (id: string, hello: string) => { return `/site/${id}/two/${hello}` } +} + +const appendSp = (sp?: Record) => { + if (sp === undefined) return '' + return `?${new URLSearchParams(sp || {}).toString()}` +} diff --git a/packages/vite-plugin-kit-routes/src/lib/index.ts b/packages/vite-plugin-kit-routes/src/lib/index.ts index d9b5277a5..bebc71c00 100644 --- a/packages/vite-plugin-kit-routes/src/lib/index.ts +++ b/packages/vite-plugin-kit-routes/src/lib/index.ts @@ -15,9 +15,18 @@ export type Options = { * ``` */ post_update_run?: string + + /** + * @default 'src/lib/ROUTES.ts' + */ + generated_file_path?: string +} + +function generated_file_path(params?: Options) { + return params?.generated_file_path ?? 'src/lib/ROUTES.ts' } -const routes_path = 'src/lib/ROUTES.ts' +// const routes_path = 'src/lib/ROUTES.ts' const log = new Log('Kit Routes') const getFiles = (dirPath: string, lookFor: '+page.svelte' | '+page.server.ts' | '+server.ts') => { @@ -46,7 +55,7 @@ const run = (params?: Options) => { const files_server_pages = getFiles(`${process.cwd()}/src/routes`, '+page.server.ts') const files_server = getFiles(`${process.cwd()}/src/routes`, '+server.ts') - const result = write(routes_path, [ + const result = write(generated_file_path(params), [ `export const PAGES = { ${files_pages .map(file_path => { @@ -108,12 +117,12 @@ const appendSp = (sp?: Record) => { }) child.on('close', code => { if (result) { - log.success(`${yellow(routes_path)} updated`) + log.success(`${yellow(generated_file_path(params))} updated`) } }) } else { if (result) { - log.success(`${yellow(routes_path)} updated`) + log.success(`${yellow(generated_file_path(params))} updated`) } } } diff --git a/packages/vite-plugin-kit-routes/vite.config.ts b/packages/vite-plugin-kit-routes/vite.config.ts index 33dc7a80a..47bc79694 100644 --- a/packages/vite-plugin-kit-routes/vite.config.ts +++ b/packages/vite-plugin-kit-routes/vite.config.ts @@ -6,7 +6,11 @@ export default defineConfig({ plugins: [ sveltekit(), // demo - kit_routes({ post_update_run: 'npm exec prettier ./src/lib/ROUTES.ts -- -w' }), + kit_routes({ + // for testing + // generated_file_path: 'src/lib/ROUTES2.ts', + post_update_run: 'npm exec prettier ./src/lib/ROUTES.ts -- -w', + }), ], test: { include: ['src/**/*.{test,spec}.{js,ts}'], From 1df430bca22b24f48642f2f57091919041f54dcc Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:43:54 +0200 Subject: [PATCH 08/10] :boom: REMOVE: ROUTE2 --- .../vite-plugin-kit-routes/src/lib/ROUTES2.ts | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts deleted file mode 100644 index bb43d655f..000000000 --- a/packages/vite-plugin-kit-routes/src/lib/ROUTES2.ts +++ /dev/null @@ -1,20 +0,0 @@ -export const PAGES = { - "/": (sp?: Record) => { return `/${appendSp(sp)}` }, - "/site/[id]": (id: string, sp?: Record) => { return `/site/${id}${appendSp(sp)}` }, - "/site/[param]/[yop]": (param: string, yop: string, sp?: Record) => { return `/site/${param}/${yop}${appendSp(sp)}` } -} - -// TODO: SERVERS methods? -export const SERVERS = { - "/site/[id]/two/[hello]": (id: string, hello: string, sp?: Record) => { return `/site/${id}/two/${hello}${appendSp(sp)}` } -} - -// TODO: name actions -export const ACTIONS = { - "/site/[id]/two/[hello]": (id: string, hello: string) => { return `/site/${id}/two/${hello}` } -} - -const appendSp = (sp?: Record) => { - if (sp === undefined) return '' - return `?${new URLSearchParams(sp || {}).toString()}` -} From a5ea58328c94956f3b053feb30a8f51d245d7b38 Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:48:41 +0200 Subject: [PATCH 09/10] :construction: RENAME: vite plugin to kitRoutes --- packages/vite-plugin-kit-routes/src/lib/index.ts | 2 +- packages/vite-plugin-kit-routes/vite.config.ts | 4 ++-- website/src/pages/docs/tools/06_vite-plugin-kit-routes.mdx | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vite-plugin-kit-routes/src/lib/index.ts b/packages/vite-plugin-kit-routes/src/lib/index.ts index bebc71c00..2754bb93a 100644 --- a/packages/vite-plugin-kit-routes/src/lib/index.ts +++ b/packages/vite-plugin-kit-routes/src/lib/index.ts @@ -127,7 +127,7 @@ const appendSp = (sp?: Record) => { } } -export function kit_routes(params?: Options): Plugin[] { +export function kitRoutes(params?: Options): Plugin[] { return [ // Run the thing at startup { diff --git a/packages/vite-plugin-kit-routes/vite.config.ts b/packages/vite-plugin-kit-routes/vite.config.ts index 47bc79694..b54503140 100644 --- a/packages/vite-plugin-kit-routes/vite.config.ts +++ b/packages/vite-plugin-kit-routes/vite.config.ts @@ -1,12 +1,12 @@ import { sveltekit } from '@sveltejs/kit/vite' import { defineConfig } from 'vite' -import { kit_routes } from './src/lib/index.js' +import { kitRoutes } from './src/lib/index.js' export default defineConfig({ plugins: [ sveltekit(), // demo - kit_routes({ + kitRoutes({ // for testing // generated_file_path: 'src/lib/ROUTES2.ts', post_update_run: 'npm exec prettier ./src/lib/ROUTES.ts -- -w', diff --git a/website/src/pages/docs/tools/06_vite-plugin-kit-routes.mdx b/website/src/pages/docs/tools/06_vite-plugin-kit-routes.mdx index 61a5f9c3d..bf7214ef9 100644 --- a/website/src/pages/docs/tools/06_vite-plugin-kit-routes.mdx +++ b/website/src/pages/docs/tools/06_vite-plugin-kit-routes.mdx @@ -12,16 +12,16 @@ npm i -D vite-plugin-kit-routes ## Configuration -Add `kit-routes` plugin with the following configuration: +Add the plugin like this: ```js filename="vite.config.js" -import { kit_routes } from 'vite-plugin-kit-routes' +import { kitRoutes } from 'vite-plugin-kit-routes' /** @type {import('vite').UserConfig} */ const config = { plugins: [ // This is the plugin to add - kit_routes() + kitRoutes() ] } From fd3946adf7478a6f2ff02dbf93732b37f2da7dc3 Mon Sep 17 00:00:00 2001 From: jycouet Date: Wed, 1 Nov 2023 10:51:31 +0200 Subject: [PATCH 10/10] :recycle: UPDATE: locations --- packages/vite-plugin-kit-routes/src/lib/ROUTES.ts | 4 ++-- .../src/routes/site/[id]/{two/[hello] => one}/+server.ts | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename packages/vite-plugin-kit-routes/src/routes/site/[id]/{two/[hello] => one}/+server.ts (100%) diff --git a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts index ae57c0e26..8e330af1f 100644 --- a/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts +++ b/packages/vite-plugin-kit-routes/src/lib/ROUTES.ts @@ -12,8 +12,8 @@ export const PAGES = { // TODO: SERVERS methods? export const SERVERS = { - '/site/[id]/two/[hello]': (id: string, hello: string, sp?: Record) => { - return `/site/${id}/two/${hello}${appendSp(sp)}` + '/site/[id]/one': (id: string, sp?: Record) => { + return `/site/${id}/one${appendSp(sp)}` }, } diff --git a/packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+server.ts b/packages/vite-plugin-kit-routes/src/routes/site/[id]/one/+server.ts similarity index 100% rename from packages/vite-plugin-kit-routes/src/routes/site/[id]/two/[hello]/+server.ts rename to packages/vite-plugin-kit-routes/src/routes/site/[id]/one/+server.ts