All Projects → sandulat → routes-gen

sandulat / routes-gen

Licence: MIT license
Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 💿🤟

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to routes-gen

type-arango
🥑 TypeArango manages ArangoDB collections, documents, relations and routes by taking advantage of TypeScript typings.
Stars: ✭ 55 (-55.65%)
Mutual labels:  routes
laroute
Generate Laravel route URLs from JavaScript.
Stars: ✭ 33 (-73.39%)
Mutual labels:  routes
awesome-remix
No description or website provided.
Stars: ✭ 263 (+112.1%)
Mutual labels:  remix
zuul-route-jdbc-spring-cloud-starter
No description or website provided.
Stars: ✭ 23 (-81.45%)
Mutual labels:  routes
feathers-versionate
Create and work with nested services.
Stars: ✭ 29 (-76.61%)
Mutual labels:  routes
vue-laroute
Wrapper for injecting laravel routes into your vue application
Stars: ✭ 23 (-81.45%)
Mutual labels:  routes
radlkarte
Hand-crafted routing information for cyclists
Stars: ✭ 14 (-88.71%)
Mutual labels:  routes
modular routes
Dedicated controllers for each of your Rails route actions.
Stars: ✭ 45 (-63.71%)
Mutual labels:  routes
Xposer
A Kubernetes controller to manage (create/update/delete) Kubernetes Ingresses based on the Service - [✩Star] if you are using it!
Stars: ✭ 30 (-75.81%)
Mutual labels:  routes
django-js-routes
Expose and perform reverse lookups of Django URLs in the frontend world.
Stars: ✭ 20 (-83.87%)
Mutual labels:  routes
railways
A plugin for RubyMine and IntelliJ IDEA Ultimate that adds a panel with routes of Ruby on Rails application.
Stars: ✭ 44 (-64.52%)
Mutual labels:  routes
fastify-register-routes
Plugin to automatically load routes from a specified path and optionally limit loaded file names by a regular expression.
Stars: ✭ 15 (-87.9%)
Mutual labels:  routes
remix-auth
Simple Authentication for Remix
Stars: ✭ 929 (+649.19%)
Mutual labels:  remix
ertuo
Ertuo: quick routing for PHP
Stars: ✭ 29 (-76.61%)
Mutual labels:  routes
routes
Google Maps Api test using marker rotation and routes.
Stars: ✭ 38 (-69.35%)
Mutual labels:  routes
remix-guide
A platform for sharing everything about Remix
Stars: ✭ 197 (+58.87%)
Mutual labels:  remix
RemixIcon-Slides
Remix Icon for PowerPoint and Keynote
Stars: ✭ 50 (-59.68%)
Mutual labels:  remix
Localizater
Laravel localization package for wrapping routes in multiple locale prefixes
Stars: ✭ 48 (-61.29%)
Mutual labels:  routes
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (-69.35%)
Mutual labels:  routes
douyu-monitor
网页端跨平台斗鱼弹幕助手
Stars: ✭ 41 (-66.94%)
Mutual labels:  remix

routes-gen @routes-gen/remix License Twitter

About

routes-gen is a framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. Think of it as Prisma, but for routes.

Installation

First, you have to install the routes generator itself:

yarn add routes-gen

Official Drivers

The generator works with "drivers", which are route parsers for different frameworks.

Driver Installation
Remix yarn add @routes-gen/remix

Usage Example

You can simply run:

yarn routes-gen -d @routes-gen/remix

It will parse and export the routes, based on the driver that you've provided.

For example, the @routes-gen/remix driver will export the routes by default to /app/routes.d.ts.

Note that you can change the output path via the --output or -o flag.

Now you can import the generated route helper anywhere and enjoy the typings:

import { route } from "routes-gen";

// Compiles to /products
route("/products");

// Compiles to /products/1337
route("/products/:productId", {
    productId: "1337",
});

Params Types Usage

You can use the RouteParams type to add typings to your dynamic route parameters/segments. Example:

import { RouteParams } from "routes-gen";

const { productId } = params as RouteParams["/products/:productId"];

Remix example:

import { LoaderFunction, useParams } from "remix";
import { RouteParams } from "routes-gen";

export const loader: LoaderFunction = async ({ params }) => {
  const { productId } = params as RouteParams["/products/:productId"];
};

export default function Product() {
  const { productId } = useParams<RouteParams["/products/:productId"]>();

  return <div />;
}

CLI Options

Option Alias Description
--help Print the help message and exit
--version -v Print the CLI version and exit
--output -o The path for routes export
--driver -d The driver of handling routes parsing
--watch -w Watch for changes
--post-export Execute a command after routes export

Writing Your Driver

If there is no driver for your preferred framework, you can write your own. For example, create a simple driver.js file in your project, with the following content:

module.exports = {
    // Where to export the typings if the "output" flag was not provided.
    defaultOutputPath: "src/routes.d.ts",
    
    // The routes parser. Must export and array of routes matching the { path: string } interface.
    routes: async () => {
        return [
            {
                path: "/products",
            },
            {
                path: "/products/:productId", // Note that the dynamic segments must match the :myVar pattern.
            },
        ];
    },

    // The paths to be watched for changes. Must return and array of relative paths.
    watchPaths: async () => {
        return ["/my-routes/**/*.{ts,tsx,js,jsx}"];
    },
}

Now you can easily use it:

routes-gen -d driver.js

You can also publish it to npm, install it, and use it as a package:

routes-gen -d my-driver-package

Please consider submitting your drivers to this repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].