Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e6a9a1f
feat: implemented svelte-kit adapter
Chigala Sep 8, 2023
dca3e8c
feat: implemented the @trigger.dev/svelte package
Chigala Sep 8, 2023
721d807
scaffolded a sveltekit example project with trigger.dev
Chigala Sep 10, 2023
cc88a1d
added the convertToStandardRequest function in the sveltekit package
Chigala Sep 10, 2023
1a16dc0
example sveltekit project with the @trigger.dev/svelte package
Chigala Sep 10, 2023
0f5a9e9
Merge branch 'main' into feat/svelte-kit-support
Chigala Sep 10, 2023
9ff8639
doc: added the manual setup guide for sveltekit
Chigala Sep 11, 2023
1c6fe3c
updated the web app onboard for sveltekit
Chigala Sep 11, 2023
77c34bc
formatted the manual setup guide for sveltekit
Chigala Sep 11, 2023
55ff9de
added a link to webapp sveltekit onboarding
Chigala Sep 11, 2023
507429d
added a wait function to the sveltekit example app job
Chigala Sep 11, 2023
87f9e23
typo fix
Chigala Sep 11, 2023
1d90b2e
Merge branch 'main' into feat/svelte-kit-support
Chigala Sep 12, 2023
4834b8c
removed comments from the @trigger.dev/svelte
Chigala Sep 15, 2023
d440987
updated package.json to use internal packages
Chigala Sep 15, 2023
6834414
added a .env.example file
Chigala Sep 15, 2023
eb8c5c2
updated the example-svelte-app
Chigala Sep 15, 2023
801ecb9
updated the svelte-example
Chigala Sep 15, 2023
47e9cf8
updated the onboarding page to reflect requested changes
Chigala Sep 15, 2023
4c57559
made the manual setup guide more specific
Chigala Sep 15, 2023
dcc82d7
created a .env.example file for svelte-example
Chigala Sep 15, 2023
8019688
added import aliases
Chigala Sep 15, 2023
a08522f
updated the tsconfig and svelte.config file
Chigala Sep 15, 2023
62abe71
updated to use uint8Array
Chigala Sep 15, 2023
39a70e5
added missing paths in the tsconfig
Chigala Sep 15, 2023
e63fe22
Merge branch 'main' into feat/svelte-kit-support
Chigala Sep 15, 2023
7391ad9
Merge branch 'main' into feat/svelte-kit-support
matt-aitken Oct 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function FrameworkSelector() {
<FrameworkLink to={projectSetupNuxtPath(organization, project)}>
<NuxtLogo className="w-32" />
</FrameworkLink>
<FrameworkLink to={projectSetupSvelteKitPath(organization, project)}>
<FrameworkLink to={projectSetupSvelteKitPath(organization, project)} supported>
<SvelteKitLogo className="w-44" />
</FrameworkLink>
<FrameworkLink to={projectSetupFastifyPath(organization, project)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,113 @@
import { SvelteKitLogo } from "~/assets/logos/SveltekitLogo";
import { FrameworkComingSoon } from "~/components/frameworks/FrameworkComingSoon";
import { ChatBubbleLeftRightIcon, Squares2X2Icon } from "@heroicons/react/20/solid";
import invariant from "tiny-invariant";
import { Feedback } from "~/components/Feedback";
import { PageGradient } from "~/components/PageGradient";
import { RunDevCommand, TriggerDevStep } from "~/components/SetupCommands";
import { StepContentContainer } from "~/components/StepContentContainer";
import { InlineCode } from "~/components/code/InlineCode";
import { BreadcrumbLink } from "~/components/navigation/NavBar";
import { Button, LinkButton } from "~/components/primitives/Buttons";
import { ClipboardField } from "~/components/primitives/ClipboardField";
import { Header1 } from "~/components/primitives/Headers";
import { NamedIcon } from "~/components/primitives/NamedIcon";
import { Paragraph } from "~/components/primitives/Paragraph";
import { StepNumber } from "~/components/primitives/StepNumber";
import { useAppOrigin } from "~/hooks/useAppOrigin";
import { useProjectSetupComplete } from "~/hooks/useProjectSetupComplete";
import { useDevEnvironment } from "~/hooks/useEnvironments";
import { useOrganization } from "~/hooks/useOrganizations";
import { useProject } from "~/hooks/useProject";
import { Handle } from "~/utils/handle";
import { trimTrailingSlash } from "~/utils/pathBuilder";

import { projectSetupPath, trimTrailingSlash } from "~/utils/pathBuilder";
import { Callout } from "~/components/primitives/Callout";
import { Badge } from "~/components/primitives/Badge";
export const handle: Handle = {
breadcrumb: (match) => (
<BreadcrumbLink to={trimTrailingSlash(match.pathname)} title="SvelteKit" />
),
};

export default function Page() {
export default function SetUpSveltekit() {
const organization = useOrganization();
const project = useProject();
useProjectSetupComplete();
const devEnvironment = useDevEnvironment();
invariant(devEnvironment, "Dev environment must be defined");
return (
<FrameworkComingSoon
frameworkName="SvelteKit"
githubIssueUrl="https://github.com/triggerdotdev/trigger.dev/issues/453"
githubIssueNumber={453}
>
<SvelteKitLogo className="w-56" />
</FrameworkComingSoon>
<PageGradient>
<div className="mx-auto max-w-3xl">
<div className="flex items-center justify-between">
<Header1 spacing className="text-bright">
Get setup in 5 minutes
</Header1>
<div className="flex items-center gap-2">
<LinkButton
to={projectSetupPath(organization, project)}
variant="tertiary/small"
LeadingIcon={Squares2X2Icon}
>
Choose a different framework
</LinkButton>
<Feedback
button={
<Button variant="tertiary/small" LeadingIcon={ChatBubbleLeftRightIcon}>
I'm stuck!
</Button>
}
defaultValue="help"
/>
</div>
</div>
<div>
<Callout
variant={"info"}
to="https://github.com/triggerdotdev/trigger.dev/discussions/430"
className="mb-8"
>
Trigger.dev has full support for serverless. We will be adding support for long-running
servers soon.
</Callout>
<div>
<StepNumber
stepNumber="1"
title="Follow the steps from the Sveltekit manual installation guide"
/>
<StepContentContainer className="flex flex-col gap-2">
<Paragraph className="mt-2">Copy your server API Key to your clipboard:</Paragraph>
<div className="mb-2 flex w-full items-center justify-between">
<ClipboardField
secure
className="w-fit"
value={devEnvironment.apiKey}
variant={"secondary/medium"}
icon={<Badge variant="outline">Server</Badge>}
/>
</div>
<Paragraph>Now follow this guide:</Paragraph>
<LinkButton
to="https://trigger.dev/docs/documentation/guides/manual/sveltekit"
variant="primary/medium"
TrailingIcon="external-link"
>
Manual installation guide
</LinkButton>
<div className="flex items-start justify-start gap-2"></div>
</StepContentContainer>
<StepNumber stepNumber="2" title="Run your sveltekit app" />
<StepContentContainer>
<RunDevCommand />
</StepContentContainer>
<StepNumber stepNumber="3" title="Run the CLI 'dev' command" />
<StepContentContainer>
<TriggerDevStep />
</StepContentContainer>
<StepNumber stepNumber="6" title="Wait for Jobs" displaySpinner />
<StepContentContainer>
<Paragraph>This page will automatically refresh.</Paragraph>
</StepContentContainer>
</div>
</div>
</div>
</PageGradient>
);
}
249 changes: 248 additions & 1 deletion docs/_snippets/manual-setup-sveltekit.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,248 @@
We're in the process of building support for the SvelteKit framework. You can follow along with progress or contribute via [this GitHub issue](https://github.com/triggerdotdev/trigger.dev/issues).
## Installing Required Packages

To begin, install the necessary packages in your Sveltekit project directory. You can choose one of the following package managers:

<CodeGroup>

```bash npm

npm i @trigger.dev/sdk @trigger.dev/sveltekit

```

```bash pnpm
pnpm install @trigger.dev/sdk @trigger.dev/sveltekit

```

```bash yarn
yarn add @trigger.dev/sdk @trigger.dev/sveltekit

```

</CodeGroup>

## Obtaining the Development API Key

To locate your development API key, login to the [Trigger.dev
dashboard](https://cloud.trigger.dev) and select the Project you want to
connect to. Then click on the Environments & API Keys tab in the left menu.
You can copy your development API Key from the field at the top of this page.
(Your development key will start with `tr_dev_`).

## Adding Environment Variables

Create a `.env` file at the root of your project and include your Trigger API key and URL like this:

```bash

TRIGGER_API_KEY=ENTER_YOUR_DEVELOPMENT_API_KEY_HERE
TRIGGER_API_URL=https://cloud.trigger.dev

```

Replace `ENTER_YOUR_DEVELOPMENT_API_KEY_HERE` with the actual API key obtained from the previous step.

## Configuring the Trigger Client

To set up the Trigger Client for your project, follow these steps:

1. **Create Configuration File:**

In your project directory, create a configuration file named `trigger.ts` or `trigger.js`, depending on whether your project uses TypeScript (`.ts`) or JavaScript (`.js`).

2. **Choose Directory:**

Create the file within the `src` directory. You can also create it directly in the project root.

3. **Add Configuration Code:**

Open the configuration file you created and add the following code:

```typescript src/trigger.(ts/js)
// trigger.ts (for TypeScript) or trigger.js (for JavaScript)

import { TriggerClient } from "@trigger.dev/sdk";
import { TRIGGER_API_KEY, TRIGGER_API_URL } from "$env/static/private";

export const client = new TriggerClient({
id: "my-app",
apiKey: TRIGGER_API_KEY,
apiUrl: TRIGGER_API_URL,
});
```

Replace **"my-app"** with an appropriate identifier for your project. The **apiKey** and **apiUrl** are obtained from the environment variables you set earlier.

4. **File Location:**

Example Directory Structure:

```
project-root/
├── src/
├── trigger.ts
├── other files...
```

Example Directory Structure where the file is stored in the project root

```
project-root/
|──src/
|──other files...
├── trigger.ts
├── other files...
```

By following these steps, you'll configure the Trigger Client to work with your project, regardless of whether you're using TypeScript or JavaScript files.

## Creating the API Route

To establish an API route for interacting with Trigger.dev, follow these steps based on your project's file type and structure

1. Create a new file named `+server.(ts/js)` within the `src/routes/api/trigger` directory.
2. Add the following code to `trigger.(ts/js)`:

```typescript
import { createSvelteRoute } from "@trigger.dev/sveltekit";

import { client } from "$trigger";

// Replace this with your own jobs
import "$jobs/example";

// Create the Svelte route handler using the createSvelteRoute function
const svelteRoute = createSvelteRoute(client);

// Define your API route handler
export const POST = svelteRoute.POST;
```

## Creating the Example Job

1. Create a folder named `Jobs` alongside your `src` directory
2. Inside the `Jobs` folder, add two files named `example.(ts/js)` and `index.(ts/js)`.

<CodeGroup>

```typescript src/jobs/example.(ts/js)
import { eventTrigger } from "@trigger.dev/sdk";
import { client } from "$trigger";

// your first job
client.defineJob({
id: "example-job",
name: "Example Job",
version: "0.0.1",
trigger: eventTrigger({
name: "example.event",
}),
run: async (payload, io, ctx) => {
await io.logger.info("Hello world!", { payload });

return {
message: "Hello world!",
};
},
});
```

```typescript index.(ts/js)
// import all your job files here

export * from "./examples";
```

</CodeGroup>

## Additonal Job Definitions

You can define more job definitions by creating additional files in the `Jobs` folder and exporting them in `index` file.

For example, in `index.(ts/js)`, you can export other job files like this:

```typescript
// import all your job files here

export * from "./examples";
export * from "./other-job-file";
```

## Adding Configuration to `package.json`

Inside the `package.json` file, add the following configuration under the root object:

```json
"trigger.dev": {
"endpointId": "my-app"
}
```

Your `package.json` file might look something like this:

```json
{
"name": "my-app",
"version": "1.0.0",
"dependencies": {
// ... other dependencies
},
"trigger.dev": {
"endpointId": "my-app"
}
}
```

Replace **"my-app"** with the appropriate identifier you used during the step for creating the Trigger Client.

## Running

### Run your Sveltekit app

Run your Sveltekit app locally, like you normally would. For example:

<CodeGroup>

```bash npm
npm run dev
```

```bash pnpm
pnpm run dev
```

```bash yarn
yarn run dev
```

</CodeGroup>

### Run the CLI 'dev' command

In a **_separate terminal window or tab_** run:

<CodeGroup>

```bash npm
npx @trigger.dev/cli@latest dev
```

```bash pnpm
pnpm dlx @trigger.dev/cli@latest dev
```

```bash yarn
yarn dlx @trigger.dev/cli@latest dev
```

</CodeGroup>
<br />
<Note>
You can optionally pass the port if you're not running on 3000 by adding
`--port 5173` to the end
</Note>
<Note>
You can optionally pass the hostname if you're not running on localhost by adding
`--hostname <host>`. Example, in case your Sveltekit app is running on 0.0.0.0: `--hostname 0.0.0.0`.
</Note>
Loading