Skip to content

Commit

Permalink
Kebab actions (#861)
Browse files Browse the repository at this point in the history
* 🚧 NEW: kebab action management

* tmp

* tmp2

* tmp3

* tmp4

* tmp5

* tmp6

* BREAKING: kit-routes plugin is not running in test mode (vitest)

* cleanup tests

* format

* add changeset (fix #858)
  • Loading branch information
jycouet authored Jan 29, 2025
1 parent 9e33766 commit 71557b5
Show file tree
Hide file tree
Showing 27 changed files with 1,078 additions and 826 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-news-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-kit-routes': minor
---

BREAKING: kit-routes plugin is not running in test mode (vitest)
5 changes: 5 additions & 0 deletions .changeset/silly-tigers-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-kit-routes': patch
---

support kebab cased actions
4 changes: 4 additions & 0 deletions packages/vite-plugin-kit-routes/src/lib/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ const ACTIONS = {
}) => {
return `${params?.['lang'] ? `/${params?.['lang']}` : ''}/site?/create${appendSp({ redirectTo: params?.['redirectTo'] }, '&')}`
},
'u-p-d-a-t-e /site': (params?: { lang?: 'fr' | 'en' | 'hu' | 'at' | string }) => {
return `${params?.['lang'] ? `/${params?.['lang']}` : ''}/site?/u-p-d-a-t-e`
},
'update /site/[id]': (params: {
id: string | number
lang?: 'fr' | 'en' | 'hu' | 'at' | string
Expand Down Expand Up @@ -327,6 +330,7 @@ export type KIT_ROUTES = {
ACTIONS: {
'default /contract/[id]': 'id' | 'lang'
'create /site': 'lang'
'u-p-d-a-t-e /site': 'lang'
'update /site/[id]': 'id' | 'lang'
'delete /site/[id]': 'id' | 'lang'
'noSatisfies /site_contract': 'lang'
Expand Down
6 changes: 5 additions & 1 deletion packages/vite-plugin-kit-routes/src/lib/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export const getActionsOfServerPages = (pathFile: string) => {

if (properties) {
properties.forEach((property: any) => {
actions.push(property.key.name)
if (property.key.name) {
actions.push(property.key.name)
} else if (property.key.value) {
actions.push(property.key.value)
}
})
}
}
Expand Down
14 changes: 11 additions & 3 deletions packages/vite-plugin-kit-routes/src/lib/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,15 +954,21 @@ export const run = async (atStart: boolean, o?: Options) => {
return `/**\n * ${c.type}\n */
${c.files
.map((key) => {
let valiableName = `${c.type.slice(0, -1)}_${key.keyToUse}`
const invalidInVariable = ['-', ' ']
for (const invalid of invalidInVariable) {
valiableName = valiableName.replaceAll(invalid, '_')
}
if (key.strParams) {
return (
`export const ${c.type.slice(0, -1)}_${key.keyToUse} = (${key.strParams}) => {` +
`export const ${valiableName} = (${key.strParams}) => {` +
`${format({ bottom: 0, top: 1, left: 2 }, key.strDefault)}
return ${key.strReturn}
}`
)
} else {
return `export const ${c.type.slice(0, -1)}_${key.keyToUse} = ${key.strReturn}`
return `export const ${valiableName} = ${key.strReturn}`
}
})
.join('\n')}`
Expand Down Expand Up @@ -1194,7 +1200,9 @@ export function kitRoutes<T extends RouteMappings = RouteMappings>(
{
name: 'kit-routes',
async buildStart() {
await run(true, options)
if (this.environment.config.env.MODE !== 'test') {
await run(true, options)
}
},
},

Expand Down
Loading

0 comments on commit 71557b5

Please sign in to comment.