Skip to content

Commit

Permalink
🔨 Update migration script to use v1-route-convention package
Browse files Browse the repository at this point in the history
Fix #46
  • Loading branch information
kiliman committed Jul 4, 2023
1 parent 5c8cf3f commit 1a6250a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@babel/preset-env": "^7.16.4",
"@babel/preset-typescript": "^7.16.0",
"@remix-run/dev": "^1.6.2",
"@remix-run/v1-route-convention": "^0.1.1",
"@types/jest": "^27.0.3",
"@types/node": "^17.0.21",
"all-contributors-cli": "^6.20.0",
Expand Down
24 changes: 21 additions & 3 deletions src/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createRoutesFromFolders } from '@remix-run/v1-route-convention'
import * as fs from 'fs'
import * as path from 'path'
import { defaultVisitFiles as visitFiles, getRouteSegments } from './index'
import { getRouteSegments } from './index'
import { defineRoutes } from './routes'

export type RoutingConvention = 'flat-files' | 'flat-folders'
export type MigrateOptions = {
Expand All @@ -11,9 +13,25 @@ export function migrate(
targetDir: string,
options: MigrateOptions = { convention: 'flat-files' },
) {
var visitor = options.convention === 'flat-files' ? flatFiles : flatFolders
// var visitor = options.convention === 'flat-files' ? flatFiles : flatFolders

visitFiles(sourceDir, visitor(sourceDir, targetDir))
// visitFiles(sourceDir, visitor(sourceDir, targetDir))

const routes = createRoutesFromFolders(defineRoutes, {
appDirectory: './app',
routesDirectory: sourceDir,
})

Object.entries(routes).forEach(([_key, route]) => {
let file = route.file
let flat = file
.replace(/[\/]/g, '.')
.replace(/\._([^_.])/g, '.[_]$1')
.replace(/\.__/g, '._')
.replace(/\.index.tsx$/, '._index.tsx')
.replace(/^routes\./, 'routes/')
console.log(flat)
})
}

export function flatFiles(sourceDir: string, targetDir: string) {
Expand Down

5 comments on commit 1a6250a

@zachrip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiliman this commit made it so the migrate doesn't actually do anything anymore

@kiliman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. You're right. I must have gotten distracted and never actually finished the implementation.

@zachrip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiliman when it does the path validation, it ends up fighting with the remix route package as well since the cli looks from root but the remix route package looks from ./app. So migrate ./app/routes ./app/flat-routes ends up with an error that ./app/app/routes cannot be found.

@kiliman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow... must have been asleep when I wrote that code. Very sorry about that. I'll try to get a working version up soon.

@zachrip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiliman no problem, I was able to bypass the issue by fixing it in my local version but I didn't have time to upstream those changes. Thanks for the package!

Please sign in to comment.