sveltekit-generator
v2.0.7
Published
Inspired by Laravel (php artisan make:)
Maintainers
Readme
SvelteKit Generator
SvelteKit Generator is a powerful CLI tool inspired by Laravel Artisan (php artisan make:). It simplifies the process of generating routes, components, server functions, API endpoints, and layouts in your SvelteKit projects. With sveltekit-generator, you can save time and focus on building your application.
Features
- Generate Routes: Automatically creates
+page.svelteand+page.server.tsfiles in thesrc/routes/directory. - Dynamic Route Parameters: Supports creating dynamic routes parameter (e.g.,
/user/[id],store/[storeId]). - Custom Dynamic Parameters: Allows you to specify custom dynamic parameters (e.g.,
--dynamic userIdor using the-dflag). - Component Generator: Easily create Svelte components inside route directories.
- API Endpoint Generator: Automatically generates
+server.tsfiles for API endpoints. - Layout Generator: Quickly create layout files (
+layout.svelteand+layout.server.ts) for consistent page structures. - Route Name Validation: Ensures route names only contain letters, numbers, and hyphens.
- Route Store Validation and Creation: Validates and creates stores automatically (e.g., src/lib/stores).
- Ready-to-Use Templates: Provides pre-built file templates for quick setup.
Installation
Install sveltekit-generator using your preferred package manager:
Using npm
npm i sveltekit-generatorUsing pnpm
pnpm i sveltekit-generatorUsing bun
bun install i sveltekit-generatorAfter installation, you can can put this command in your package.json file to use it globally:
"scripts": {
"generate": "sveltekit-generator"
}Usage
Generate a Basic Route:
pnpm generate route <route_name>Generate / Custom a Dynamic Route existing
pnpm generate route <route_name> -d <param_name>Generate a Component Inside a Route
pnpm generate component <route_name> <component_name>Generate / Custom a Component Inside a Dynamic Route existing
pnpm generate component <route_name> -d <param_name> <component_name>Generate routes in spesific directory
pnpm generate route ('(folder_name)/<route_name>')Generate dynamic routes in spesific directory
pnpm generate route ('(folder_name)/<route_name>') --dynamic <param_name>generate API endpoint
pnpm generate api <api_name>Generate a Dynamic API endpoint
pnpm generate api <api_name> -d <param_name>Generate a Layout
pnpm generate layout <layout_name>Generate a Store (type: writable, readable, derived)
pnpm generate store <store_name>Generate a Store with a different type
pnpm generate store <store_name> -t readablepnpm generate store <store_name> -t derivedpnpm generate store <store_name> -t writableGenerate a store in spesific path
pnpm generate store <store_name> -p <path>Why Use SvelteKit Generator?
- Save Time: Automates repetitive tasks like creating routes, components, API endpoints, and layouts.
- Consistency: Ensures a consistent project structure.
- Easy to Use: Simple commands for generating files.
- Customizable: Supports dynamic routes and custom parameters.
Contributing
If you'd like to contribute to this project, feel free to open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License. See the LICENSE.md file for details.
