kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention
MIT License
640 stars 22 forks source link

Migrate script nested folders with flat-files convention #78

Closed elledienne closed 8 months ago

elledienne commented 8 months ago

We are in the process of migrating to the v2 routes convention but we really struggle to use the flat-files/folders conventions as we are working on a big project with tens, maybe hundreds of routes.

We believe that "nested folders with flat-files" could be the best approach for us as - any chance we can use the migrate script to migrate our routes to "nested folders with flat-files"?

Thank you!

kiliman commented 8 months ago

So, do you want the script to automatically include the + suffix on every folder in the v1 route?

existing v1 routes

app/routes-v1
├── users
│   ├── $userId.edit.tsx
│   ├── $userId.tsx
│   └── index.tsx
└── users.tsx

current migration to v2

app/routes-v2-current
├── users.$userId.tsx
├── users.$userId_.edit.tsx
├── users._index.tsx
└── users.tsx

proposed migration to hybrid?

app/routes-v2-hybrid
└── users+
    ├── $userId.tsx
    ├── $userId_.edit.tsx
    ├── _index.tsx
    └── _layout.tsx      <- routes/users.tsx v1 layout file
elledienne commented 8 months ago

yeah, that's right! Ideally we want to migrate to v2 without actually changing the folder structure as we like the way it currently is

kiliman commented 8 months ago

Ok, I'll see what I can do. Thanks for the confirmation.

kiliman commented 8 months ago

I think I've got it working

v1 routes

app/old-routes/
├── $lang.$ref
│   ├── $.tsx
│   ├── index.tsx
│   └── test.edit.tsx
├── $lang.$ref.tsx
├── accounts.tsx
├── api
│   └── v1
│       ├── README.md
│       ├── experiments.tsx
│       ├── invoice
│       │   └── $invoiceId.tsx
│       └── invoice.tsx
├── dashboard.tsx
├── expenses.tsx
├── index.tsx
├── reports.tsx
├── sales
│   ├── customers.tsx
│   ├── deposits.tsx
│   ├── index.tsx
│   ├── invoices
│   │   ├── $invoiceId.edit.tsx
│   │   ├── $invoiceId.tsx
│   │   └── index.tsx
│   ├── invoices.tsx
│   └── subscriptions.tsx
├── sales.tsx
├── users
│   ├── $id.edit.tsx
│   ├── $id.tsx
│   └── index.tsx
└── users.tsx

migrated hybrid routes

app/hybrid-routes/
├── $lang.$ref+
│   ├── $.tsx
│   ├── _index.tsx
│   ├── _layout.tsx
│   └── test_.edit.tsx
├── _index.tsx
├── accounts.tsx
├── api+
│   └── v1+
│       ├── README.md
│       ├── experiments.tsx
│       └── invoice+
│           ├── $invoiceId.tsx
│           └── _layout.tsx
├── dashboard.tsx
├── expenses.tsx
├── reports.tsx
├── sales+
│   ├── _index.tsx
│   ├── _layout.tsx
│   ├── customers.tsx
│   ├── deposits.tsx
│   ├── invoices+
│   │   ├── $invoiceId.tsx
│   │   ├── $invoiceId_.edit.tsx
│   │   ├── _index.tsx
│   │   └── _layout.tsx
│   └── subscriptions.tsx
└── users+
    ├── $id.tsx
    ├── $id_.edit.tsx
    ├── _index.tsx
    └── _layout.tsx

I like that hybrid routes move the sibling layout route into folder as _layout.tsx