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

Overview

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

Note that it should not be a dev dependency, since you'll be importing the route method from here.

Official Drivers

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

Driver Installation Default export path
Remix yarn add -D @routes-gen/remix /app/routes.d.ts

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",
});

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

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 file if the "output" flag was not provided
    defaultOutputPath: "src/routes.d.ts",
    
    // The routes parser. Must export and array of routes matching the interface: { path: string }
    routes: async () => {
        return [
            {
                path: "/products",
            },
            {
                path: "/products/:productId", // Note that the dynamic segments must match the pattern :myVar
            },
        ];
    },
}

Now you can easily use it:

routes-gen -d driver.js

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

routes-gen -d my-driver-package

Please consider submitting your drivers to this repository.

Comments
  • Command failed: remix routes --json | tee in Windows Powershell

    Command failed: remix routes --json | tee in Windows Powershell

    Describe the bug

    Followed the instructions up to this line yarn routes-gen -d @routes-gen/remix and received the following error:

    image

    I believe this occurs because on Windows it defaults to use command prompt instead of Powershell, where the command would have worked.

    Your Example Website or App

    n/a

    Steps to Reproduce the Bug or Issue

    1. Open existing remix repo on VSCode Windows
    2. yarn add routes-gen @routes-gen/remix
    3. yarn routes-gen -d @routes-gen/remix

    Expected behavior

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

    Screenshots or Videos

    No response

    Platform

    • OS: Windows 10 Powershell
    • IDE: VSCode

    Additional context

    No response

    bug 
    opened by xHomu 7
  • fix: change the empty object type {} to use TS Record utility type

    fix: change the empty object type {} to use TS Record utility type

    To use the more accurate type based on typescript/eslint's recommendations, The generated type when there's no param was changed to Record<string, never>

     Don't use `{}` as a type. `{}` actually means "any non-nullish value".
    - If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.
    - If you want a type meaning "any value", you probably want `unknown` instead.
    - If you want a type meaning "empty object", you probably want `Record<string, never>` instead
    

    https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/ban-types.md

    For example, this is valid in the current main branch

    image

    But once it's changed, now it throws an error

    image

    However, this is still valid as expected

    image

    opened by aniravi24 5
  • Invalid driver package name or file path

    Invalid driver package name or file path

    Describe the bug

    I'm running routes-gen on postinstall on Github Actions, and I'm getting this error:

    [ERROR] Invalid driver package name or file path.
    

    It's running on node:16-bullseye-slim image, and it's running without any issues on my local machine. I tested it even after deleting node_modules.

    The relevant parts of my scripts:

        "postinstall": "remix setup node && npm run routes-gen",
        "routes-gen": "routes-gen -d @routes-gen/remix"
    

    and relevant devDependencies:

        "@routes-gen/remix": "^0.3.0",
        "routes-gen": "^0.4.0",
    

    Your Example Website or App

    a private repo

    Steps to Reproduce the Bug or Issue

    1. Run npm install --production=false on Github Actions under Docker node:16-bullseye-slim image

    Expected behavior

    The driver should resolve correctly

    Screenshots or Videos

    No response

    Platform

    • OS: [Linux]
    • Version: [0.4.0]

    Additional context

    No response

    opened by frontsideair 5
  • Is there a limit to the number of routes

    Is there a limit to the number of routes

    Describe the bug

    In a Remix app, we are struggling to add any additional routes. We are getting the following error:

    SyntaxError: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at /Users/my-appl/node_modules/@routes-gen/remix/dist/index.js:52:30
        at ChildProcess.exithandler (child_process.js:310:7)
        at ChildProcess.emit (events.js:376:20)
        at maybeClose (internal/child_process.js:1055:16)
        at Socket.<anonymous> (internal/child_process.js:441:11)
        at Socket.emit (events.js:376:20)
        at Pipe.<anonymous> (net.js:673:12)
    

    The only way around it, is to delete an existing route in order to create a new one.

    I have tested on a fresh remix app and limit appears to be 68 routes and issues shows up when I create any additional routes.

    Your Example Website or App

    Local app

    Steps to Reproduce the Bug or Issue

    1. Create 70 routes on a fresh remix app
    2. Try to run the command routes-gen -d @routes-gen/remix in a Remix App

    Expected behavior

    To be able to generate an updated /routes.d.ts file

    Screenshots or Videos

    No response

    Platform

    • OS: macOS

    Additional context

    No response

    bug 
    opened by brightpixels 2
  • change devDependencies to dependencies

    change devDependencies to dependencies

    I had chalk v5 installed in my project, which raised an error because routes-gen needs v4, but v4 wasn't installed. The package needs to use dependencies and not devDependencies for its required packages to be installed with it

    opened by itsMapleLeaf 2
  • [FEATURE REQUEST] Add query string support

    [FEATURE REQUEST] Add query string support

    Describe the bug

    Discussions are not enabled so I am using this.

    There is a similar library to this, Remix Routes, that supports adding query parameters to URLs with the path helper. Could this functionality be added to this package?

    Your Example Website or App

    https://github.com/yesmeck/remix-routes

    Steps to Reproduce the Bug or Issue

    N/A

    Expected behavior

    Query parameters can be added to the path with the helper.

    Screenshots or Videos

    No response

    Platform

    • OS: [e.g. macOS, Windows, Linux]
    • Browser: [e.g. Chrome, Safari, Firefox]
    • Version: [e.g. 91.1]

    Additional context

    No response

    enhancement question 
    opened by MrAwesomeRocks 2
  • add github ISSUE_TEMPLATE files

    add github ISSUE_TEMPLATE files

    What is the change?

    Add bug_report.yml & config.yml file to enable Github's form based issue template

    • https://youtu.be/qQE1BUkf2-s?t=23

    Motivation

    • encourage's bug reporter's to put more care into their bug report before submission
    • this may help maintainer's receive more detailed & higher quality bug report's
    • adds helpful tips for user's during the process of creating a bug/issue report

    Demo of Change

    this PR is similar to this one I created here for another repo recently

    • https://github.com/antvis/G6/blob/master/.github/ISSUE_TEMPLATE/bug_report.yml
    opened by cliffordfajardo 1
  • add plugin @routes-gen/solid-start

    add plugin @routes-gen/solid-start

    This PR adds a new plugin @routes-gen/solid-start. You can see it running and published under @nirtamir2/routes-gen-solid-start and play with it in https://github.com/nirtamir2/solid-start-starter/tree/routes-gen-published

    Closes #28

    opened by nirtamir2 2
Releases(v0.5.2)
  • v0.5.2(Aug 8, 2022)

  • v0.5.1(Jul 8, 2022)

    What's Changed

    • fix: change the empty object type {} to use TS Record utility type by @aniravi24 in https://github.com/sandulat/routes-gen/pull/21

    New Contributors

    • @aniravi24 made their first contribution in https://github.com/sandulat/routes-gen/pull/21

    Full Changelog: https://github.com/sandulat/routes-gen/compare/v0.5.0...v0.5.1

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Apr 30, 2022)

    What's Changed

    • feat: implemented post-export hook in routes-gen by @sandulat in https://github.com/sandulat/routes-gen/pull/18

    Full Changelog: https://github.com/sandulat/routes-gen/compare/v0.4.0...v0.5.0

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Apr 17, 2022)

  • v0.3.3(Apr 14, 2022)

    What's Changed

    • change devDependencies to dependencies by @itsMapleLeaf in https://github.com/sandulat/routes-gen/pull/17

    New Contributors

    • @itsMapleLeaf made their first contribution in https://github.com/sandulat/routes-gen/pull/17

    Full Changelog: https://github.com/sandulat/routes-gen/compare/v0.3.2...v0.3.3

    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Apr 6, 2022)

  • v0.3.1(Mar 24, 2022)

Owner
Stratulat Alexandru
Working hard on @kitwindio 🧩 — Writing about Laravel ☕️ — Married to React & Typescript 👰 — In love with Tailwind 💅 Running https://blitz-jobs.com 🤘
Stratulat Alexandru
This package enables you to define your routes using the flat-routes convention.

Remix Flat Routes This package enables you to define your routes using the flat-routes convention. This is based on the gist by Ryan Florence ?? Insta

Kiliman 180 Jan 3, 2023
Automatically document all of your Remix loaders and actions typings per each route. 📚

About remix-docs-gen parses all of your Remix loaders and actions and automatically documents all the typings per each route. Installation First, you

Stratulat Alexandru 50 Nov 9, 2022
End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register route handlers. LOL

Chino intelligence in japaneese End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register rou

sambit sahoo 2 Sep 12, 2022
SafeCycle—a tool that keeps cyclists safe. Gone are days of weaving through busy city streets, SafeCycle finds all the bike routes for you to ensure a smooth ride wherever you want to go.

Inspiration Biking—an everyday form of travel for students and professionals across the globe. On-campus, back home, and with the people that we know

Ryan Hu 2 May 2, 2022
👩‍🎤 Headless, type-safe, UI components for the next generation Web3.Storage APIs.

Headless, type-safe, UI components for the next generation Web3.Storage APIs. Documentation beta.ui.web3.storage Examples React Sign up / Sign in Sing

Web3 Storage 47 Dec 22, 2022
Um bot de suporte feito usando threads para o Discord, 100% customizável, feito em JavaScript e inspirado no Rio Helper do servidor Elixir Lab e na Loritta Helper do serivdor de suporte da Loritta.

Ticket Bot Um bot de suporte feito usando threads para o Discord, 100% customizável, feito em JavaScript e inspirado no Rio Helper do servidor Elixir

ADG 6 Dec 21, 2022
A solid create-remix app, that applies best practices into a clean, batteries included template. SQLite version. Deploys to Fly.io

Remix Barebones Stack npx create-remix --template dev-xo/barebones-stack A solid create-remix app, that follows community guidelines and applies best

Dev XO 97 Dec 30, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
Ready-to-use Remix + Tailwind CSS routes and components.

remix-blocks What is RemixBlocks? Ready-to-use Remix + Tailwind CSS routes, and UI components, all blocks: Are full-stack routes. Are independent of e

Alexandro Martínez 111 Jan 5, 2023
JavaScript library for parsing Dirtywave M8 files, complete with a CLI for interacting with M8 files.

m8-js This repository contains a JavaScript library for parsing Dirtywave M8 files, as well as a CLI for interacting with M8 files. The hopes are not

Jeremy Whitlock 20 Dec 17, 2022
A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Jean Rodríguez 7 Sep 13, 2022
AI-based CLI tool for code generation and mass refactoring

fixgpt Tool that helps you do mass changes across your codebase Create new files Mass refactoring Remove files upon certain conditions Code execution

Anton Kosykh 6 May 5, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Hadmean is an internal tool generator. It is language agnostic, schema driven, extremely customizable, featured packed, user-friendly and has just one installation step.

Hadmean Report a Bug · Request a Feature · Ask a Question Table of Contents About Quick Demo Motivation Why you should try Hadmean Getting Started Pre

Hadmean 344 Dec 29, 2022
This is a jquery ui sortable helper plugin for handy tree type structure sotable.

Tree Sortable A drag and drop list item sorting and level changing library. Motivation The jQuery-ui's sortable plugin allows us to sort items vertica

Sajeeb Ahamed 10 Dec 23, 2022
Lightweight, fast and framework-agnostic sse service for NodeJS

SSE service Lightweight, fast and framework-agnostic sse service for NodeJS Written on TS. Features Could be embedded to Express, Fastify, Nest, etc.

null 9 Dec 9, 2022
A next-gen framework for type-safe command-line applications

Zors ?? Next-gen framework for building modern, type-safe command-line applications. ?? Tiny (zero dependencies) ?? Runtime agonistic (supports both D

Sidharth Rathi 13 Dec 1, 2022