generated from florian-lefebvre/astro-integration-template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5de4221
commit 62ecc58
Showing
13 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"astro-integration-kit": minor | ||
--- | ||
|
||
Adds a new utility, `injectDevRoute` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: injectDevRoute | ||
description: Allows to inject a route in development only. | ||
--- | ||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
|
||
`injectDevRoute` allows to inject a route in development only. For example: | ||
|
||
<Tabs> | ||
<TabItem label="Extended hooks"> | ||
```ts title="my-integration/index.ts" /injectDevRoute\\b/ {2,6} | ||
import { createResolver, defineIntegration } from "astro-integration-kit"; | ||
import { injectDevRoutePlugin } from "astro-integration-kit/plugins"; | ||
|
||
export default defineIntegration({ | ||
name: "my-integration", | ||
plugins: [injectDevRoutePlugin], | ||
setup() { | ||
const { resolve } = createResolver(import.meta.url); | ||
|
||
return { | ||
"astro:config:setup": ({ injectDevRoute }) => { | ||
injectDevRoute({ | ||
pattern: "/foo", | ||
entrypoint: resolve("./pages/foo.astro") | ||
}) | ||
} | ||
} | ||
} | ||
}) | ||
``` | ||
</TabItem> | ||
<TabItem label="Standalone utilities"> | ||
```ts title="integration/index.ts" "watchIntegration" | ||
import type { AstroIntegration } from "astro"; | ||
import { createResolver } from "astro-integration-kit"; | ||
import { injectDevRoute } from "astro-integration-kit/utilities"; | ||
|
||
export default function myIntegration(): AstroIntegration { | ||
const { resolve } = createResolver(import.meta.url); | ||
|
||
return { | ||
name: "my-integration", | ||
hooks: { | ||
"astro:config:setup": ({ command, injectRoute }) => { | ||
injectDevRoute({ | ||
command, | ||
injectRoute, | ||
injectedRoute: { | ||
pattern: "/foo", | ||
entrypoint: resolve("./pages/foo.astro") | ||
}, | ||
}) | ||
}, | ||
} | ||
} | ||
} | ||
``` | ||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { definePlugin } from "../core/define-plugin.js"; | ||
import { injectDevRoute } from "../utilities/inject-dev-route.js"; | ||
|
||
export const injectDevRoutePlugin = definePlugin({ | ||
name: "injectDevRoute", | ||
hook: "astro:config:setup", | ||
implementation: | ||
({ command, injectRoute }) => | ||
(injectedRoute: Parameters<typeof injectDevRoute>[0]["injectedRoute"]) => | ||
injectDevRoute({ command, injectRoute, injectedRoute }), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { HookParameters, InjectedRoute } from "astro"; | ||
|
||
/** | ||
* Allows to inject a route in development only | ||
* | ||
* @param {object} params | ||
* @param {import("astro").HookParameters<"astro:config:setup">["command"]} params.command | ||
* @param {import("astro").HookParameters<"astro:config:setup">["injectRoute"]} params.injectRoute | ||
* @param {import("astro").InjectedRoute} params.injectedRoute | ||
* | ||
* @example | ||
* ```ts | ||
* injectDevRoute({ | ||
* command, | ||
* injectRoute, | ||
* injectedRoute: { | ||
* pattern: "/foo", | ||
* entrypoint: resolve("./pages/foo.astro") | ||
* }, | ||
* }) | ||
* ``` | ||
* | ||
* @see https://astro-integration-kit.netlify.app/utilities/inject-dev-route/ | ||
*/ | ||
export const injectDevRoute = ({ | ||
command, | ||
injectRoute, | ||
injectedRoute, | ||
}: Pick<HookParameters<"astro:config:setup">, "command" | "injectRoute"> & { | ||
injectedRoute: InjectedRoute; | ||
}) => { | ||
if (command === "dev") { | ||
injectRoute(injectedRoute); | ||
} | ||
}; |