Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mpiorowski/svelte-cli

Svelte Cli for easy scaffolding the SvelteKit project using the newest options.
https://github.com/mpiorowski/svelte-cli

Last synced: 4 days ago
JSON representation

Svelte Cli for easy scaffolding the SvelteKit project using the newest options.

Awesome Lists containing this project

README

        

# Svelte Cli

Svelte cli for fast Svelte/SvelteKit scaffolding using the newest routing. Written fully using Rust.

WIP

## Install

```
cargo install sveltecli
```

Please make sure that `~/.cargo/bin` is in your PATH.
In the future more distro related options will be added :)

## Usage

```
sv add [pages] -p [path]
```

This command will add specified routing files with the basic template.
Example:

```
sv add ps -p reports
```

This will add `+page.server.ts` to Your `reports` folder (it will create it if not existed) with the following template:

```
import { Actions, PageServerLoad } from "./$types";

export const load = (({ }) => {
return {};
}) satisfies PageServerLoad;

export const actions = {
formAction: async ({ request }) => {
const form = await request.formData();
const id = form.get('id');

return { id };
},
} satisfies Actions;
```

You can also add multiple files in one command:

```
sv add ps p e l
```

## Pages

| Command | Page (ts) | Page (js) |
| ------- | ----------------- | ----------------- |
| e | +error.svelte | +error.svelte |
| l | +layout.svelte | +layout.svelte |
| lc | +layout.ts | +layout.js |
| ls | +layout.server.ts | +layout.server.js |
| p | +page.svelte | +page.svelte |
| pc | +page.ts | +page.js |
| ps | +page.server.ts | +page.server.js |
| s | +server.ts | +server.js |

## Config

### Language

```
sv config lang [js or ts]
```

This will set up the language. `js` lang will not use types, the files will have the `.js` extension and cli will search for `.js` files inside temp folder.

### Tempaltes

```
sv config temp [path_to_your_templates_folder]
```

This will set Your default templates path. Inside this folder put the files with Your default templates. The name of the pages must much the default ones. You don't need to put all the pages, the cli will use the default one if some will be missing. Then add it:

## Default templates

### +error.svelte

```

import { page } from '$app/stores';

{$page.status}: {$page.error.message}


```

### +layout.svelte

```

import { LayoutData } from "./$types";
export let data: LayoutData;

```

### +layout.ts

```
import { LayoutLoad } from "./$types";

export const load = (({ }) => {
return {};
}) satisfies LayoutLoad;
```

### +layout.server.ts

```
import { LayoutServerLoad } from "./$types";

export const load = (({ }) => {
return {};
}) satisfies LayoutServerLoad;
```

### +page.svelte

```

import { PageData } from "./$types";
export let data: PageData;

Page


```

### +page.ts

```
import { PageLoad } from "./$types";

export const load = (({ }) => {
return {};
}) satisfies PageLoad;
```

### +page.server.ts

```
import { Actions, PageServerLoad } from "./$types";

export const load = (({ }) => {
return {};
}) satisfies PageServerLoad;

export const actions = {
formAction: async ({ request }) => {
const form = await request.formData();
const id = form.get('id');

return { id };
},
} satisfies Actions;
```

### +server.ts

```
import type { RequestHandler } from "./$types";

export const GET = ( ({ url }) => {
return new Response(String(url));
}) satisfies RequestHandler;
```