0.7.0 • Published 3 years ago

route-codegen v0.7.0

Weekly downloads
92
License
MIT
Repository
github
Last release
3 years ago

route-codegen

This generates route objects which can be used to manage inner and inter app routing. Given a route pattern, typescript interfaces are also generated automatically to make routing safe and easy to use.

Install

$ yarn add route-codegen

Or

$ npm i route-codegen

Create config

Add route-codegen.yml to project root. Example:

apps:
  client:
    routes:
      login: /app/login
      signup: /app/signup
      logout: /app/logout
      me: /app/me
    routingType: ReactRouter
    generateReactRouterFunctions: false # Use this boolean if you don't want to create typed convenient functions/hooks such as `useParams` or `useRedirect`
    destinationDir: client/src/routes

  client-seo:
    routes:
      home: /
    routingType: NextJS
    destinationDir: client-seo/src/routes
    # Use on of these `reactRouterLinkOptions`, `nextJSLinkOptions`, `defaultLinkOptions` options below if you want to custom how Link is created
    reactRouterLinkOptions:
      path: src/common/components/Link
      propsInterfaceName: LinkProps
      hrefProp: href
    nextJSLinkOptions:
      path: src/common/components/NextJSLink
      propsInterfaceName: LinkProps
      hrefProp: href
    defaultLinkOptions:
      path: src/common/ui/Anchor
      propsInterfaceName: AnchorProps
      hrefProp: href

  express-server:
    generateLink: false
    destinationDir: server/src/routes # an app without `routes` is still valid. In this case, this app can still generate url to other apps

  legacy:
    routes:
      legacyApp: /legacy/app # leave out `destinationDir` if no route needs to be generated. Other apps still generate routes to this app

Generate

$ yarn route-codegen

Or

$ npx route-codegen

Running it manually

// routegen.ts
import generate, { Config, RoutingType } from 'route-codegen/dist/generate';

const config: Config = {
  apps: {
    app: {
      routes: {
        user: '/app/users/:id',
        account: '/app/account',
      },
      routingType: RoutingType.ReactRouter,
      destinationDir: 'tests/output/app/routes',
    },
    seo: {
      routes: {
        home: '/',
        about: '/about',
        terms: '/terms-and-conditions',
      },
      routingType: RoutingType.NextJS,
      destinationDir: 'tests/output/seo/routes',
    },
  },
};

generate(config);

Then run the following in the terminal

$ yarn tsc routegen.ts
$ node routegen.js

Developing

Build it!

We need to build from TS -> JS to be able to run the generator. For the changes to reflect, after making changes in src, run the following:

$ yarn run build

Build and run real config

$ yarn run test:cli

How it works

  • Reads in the config
  • Go through each "app"
  • Look at the routes it needs to generate and destination folder
  • Generate each route into its own file in the destination folder ( this helps codesplitting )
  • The files are generated into tests/output folder for now

TODO

  • Bring over createRoute function which uses the generated types to generate the route objects
  • Break index.ts into smaller files
  • Handle inter app routing
  • Handle NextJS routing
  • Add yaml file for config
  • Make this CLI
  • Publish
  • Generate route / link creators
  • Generate url function needs to take URL query. Maybe pass this into each createLink as a function so route & link always have the same function.
  • Tests
  • Set up CI
  • Clean up
0.0.0-alpha.48

3 years ago

0.0.0-alpha.46

4 years ago

0.0.0-alpha.45

4 years ago

0.0.0-alpha.44

4 years ago

0.0.0-alpha.43

4 years ago

0.7.0

4 years ago

0.0.0-alpha.47

4 years ago

0.6.1

4 years ago

0.0.0-alpha.42

4 years ago

0.6.0

4 years ago

0.0.0-alpha.41

4 years ago

0.0.0-alpha.40

4 years ago

0.5.2

4 years ago

0.0.0-alpha.39

4 years ago

0.5.1

4 years ago

0.0.0-alpha.38

4 years ago

0.5.0

4 years ago

0.0.0-alpha.37

4 years ago

0.0.0-alpha.36

4 years ago

0.0.0-alpha.35

4 years ago

0.0.0-alpha.34

4 years ago

0.4.4

4 years ago

0.0.0-alpha.33

4 years ago

0.0.0-alpha.32

4 years ago

0.0.0-alpha.31

4 years ago

0.0.0-alpha.30

4 years ago

0.0.0-alpha.29

4 years ago

0.0.0-alpha.28

4 years ago

0.0.0-alpha.27

4 years ago

0.0.0-alpha.26

4 years ago

0.4.3

4 years ago

0.0.0-alpha.24

4 years ago

0.0.0-alpha.25

4 years ago

0.0.0-alpha.23

4 years ago

0.0.0-alpha.22

4 years ago

0.0.0-alpha.21

4 years ago

0.0.0-alpha.20

4 years ago

0.4.2

4 years ago

0.0.0-alpha.19

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.0.0-alpha.18

4 years ago

0.0.0-alpha.17

4 years ago

0.0.0-alpha.16

4 years ago

0.3.0

4 years ago

0.0.0-alpha.15

4 years ago

0.0.0-alpha.14

4 years ago

0.0.0-alpha.13

4 years ago

0.0.0-alpha.12

4 years ago

0.2.2

4 years ago

0.0.0-alpha.11

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.0.0-alpha.10

4 years ago

0.0.0-alpha.9

4 years ago

0.0.0-alpha.8

4 years ago

0.0.0-alpha.7

4 years ago

0.0.0-alpha.6

4 years ago

0.0.0-alpha.5

4 years ago

0.1.5

4 years ago

0.0.0-alpha.4

4 years ago

0.0.0-alpha.3

4 years ago

0.1.4-alpha.16

4 years ago

0.0.0-alpha.0

4 years ago

0.0.0-alpha.1

4 years ago

0.0.0-alpha.2

4 years ago

0.1.4-alpha.15

4 years ago

0.1.4-alpha.14

4 years ago

0.1.4-alpha.13

4 years ago

0.1.4-alpha.12

4 years ago

0.1.4-alpha.10

4 years ago

0.1.4-alpha.11

4 years ago

0.1.4-alpha.8

4 years ago

0.1.4-alpha.9

4 years ago

0.1.4-alpha.7

4 years ago

0.1.4-alpha.4

4 years ago

0.1.4-alpha.5

4 years ago

0.1.4-alpha.6

4 years ago

0.1.4-alpha.3

4 years ago

0.1.4-alpha.2

4 years ago

0.1.4-alpha.0

4 years ago

0.1.4-alpha.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago