remix-flat-routes
Advanced tools
Comparing version 0.0.4 to 0.1.0
{ | ||
"name": "remix-flat-routes", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Package for generating routes using flat convention", | ||
@@ -15,2 +15,3 @@ "main": "dist/index.js", | ||
"build": "npm run clean && tsc --project tsconfig.json --module CommonJS --outDir ./dist", | ||
"test": "jest", | ||
"contributors:add": "all-contributors add", | ||
@@ -21,3 +22,4 @@ "contributors:generate": "all-contributors generate", | ||
"keywords": [ | ||
"remix" | ||
"remix", | ||
"routing-convention" | ||
], | ||
@@ -35,12 +37,24 @@ "author": { | ||
"devDependencies": { | ||
"@babel/core": "^7.16.0", | ||
"@babel/preset-env": "^7.16.4", | ||
"@babel/preset-typescript": "^7.16.0", | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^17.0.21", | ||
"all-contributors-cli": "^6.20.0", | ||
"babel-jest": "^27.4.2", | ||
"esbuild-register": "^3.3.2", | ||
"esbuild": "^0.14.36", | ||
"esbuild-register": "^3.3.2", | ||
"formdata-polyfill": "^4.0.10", | ||
"jest": "^27.4.3", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.0.7", | ||
"ts-node": "^10.7.0", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.6.2" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest/presets/default-esm", | ||
"testEnvironment": "jsdom" | ||
} | ||
} |
@@ -122,2 +122,3 @@ # Remix Flat Routes | ||
| `_layout.jsx` | explict layout file | optional, same as parent folder | | ||
| `_route.jsx` | explict route file | optional, same as parent folder | | ||
| `investors/[index].jsx` | brackets | escapes conventional characters | | ||
@@ -154,7 +155,7 @@ | ||
_auth/ | ||
login/ | ||
index.tsx <- route file (same as _auth.login.tsx) | ||
signup/ | ||
index.tsx <- route file (same as _auth.index.tsx) | ||
_layout.tsx <- explicit layout file (same as _auth.tsx) | ||
_auth.forgot-password/ | ||
_route.tsx <- explicit route file (same as _auth.forgot-password.tsx) | ||
_auth.login/ | ||
index.tsx <- route files (same as _auth.login.tsx) | ||
_landing.about/ | ||
@@ -172,8 +173,2 @@ index.tsx <- route file (same as _landing.about.tsx) | ||
footer.tsx | ||
app.projects/ | ||
$id/ | ||
index.tsx <- route file (same as app.projects.$id.tsx) | ||
project-card.tsx | ||
get-projects.server.tsx | ||
project-buttons.tsx | ||
app/ | ||
@@ -187,2 +182,10 @@ index.tsx <- route file (same as app.tsx) | ||
update-timeline.server.tsx | ||
app.projects/ | ||
_layout.tsx <- explicit layout file (sames as app.projects.tsx) | ||
project-card.tsx | ||
get-projects.server.tsx | ||
project-buttons.tsx | ||
app.projects.$id/ | ||
_route.tsx <- explicit route file (sames as app.projects.$id.tsx) | ||
``` | ||
@@ -189,0 +192,0 @@ |
@@ -70,3 +70,14 @@ import * as fs from 'fs' | ||
function parseRouteFile(baseDir: string, routeFile: string) { | ||
export type RouteInfo = { | ||
path: string | ||
file: string | ||
name: string | ||
parent: string | ||
isIndex: boolean | ||
} | ||
export function parseRouteFile( | ||
baseDir: string, | ||
routeFile: string, | ||
): RouteInfo | null { | ||
let state = 'START' | ||
@@ -88,3 +99,7 @@ let subState = 'NORMAL' | ||
if (routeFile.includes('/')) { | ||
if (!name.endsWith('/index') && !name.endsWith('/_layout')) { | ||
if ( | ||
!name.endsWith('/index') && | ||
!name.endsWith('/_layout') && | ||
!name.endsWith('/_route') | ||
) { | ||
return null | ||
@@ -96,3 +111,4 @@ } | ||
let index = 0 | ||
let segment = '' | ||
let pathSegment = '' | ||
let routeSegment = '' | ||
while (index < name.length) { | ||
@@ -104,5 +120,5 @@ let char = name[index] | ||
// process existing segment | ||
url = appendSegment(url, segment) | ||
url = appendPathSegment(url, pathSegment) | ||
if (segment.endsWith('_')) { | ||
if (routeSegment.endsWith('_')) { | ||
parentState = 'IGNORE' | ||
@@ -114,6 +130,7 @@ } | ||
} | ||
parent += segment | ||
parent += routeSegment | ||
} | ||
if (segment === 'index') isIndex = true | ||
segment = '' // reset segment | ||
if (routeSegment === 'index') isIndex = true | ||
pathSegment = '' // reset segment | ||
routeSegment = '' | ||
state = 'PATH' | ||
@@ -124,4 +141,5 @@ continue // restart without advancing index | ||
state = 'START' | ||
break | ||
} else if (char === '$') { | ||
segment += ':' | ||
pathSegment += ':' | ||
} else if (char === '[') { | ||
@@ -132,15 +150,12 @@ subState = 'ESCAPE' | ||
} else { | ||
segment += char | ||
pathSegment += char | ||
} | ||
routeSegment += char | ||
break | ||
case 'PATHLESS': | ||
if (isPathSeparator(char)) { | ||
state = 'START' | ||
} | ||
break | ||
} | ||
index++ // advance to next character | ||
} | ||
if (segment === 'index') isIndex = true | ||
url = appendSegment(url, segment) | ||
if (routeSegment === 'index') isIndex = true | ||
url = appendPathSegment(url, pathSegment) | ||
return { | ||
@@ -155,3 +170,3 @@ path: url, | ||
function appendSegment(url: string, segment: string) { | ||
function appendPathSegment(url: string, segment: string) { | ||
if (segment) { | ||
@@ -165,3 +180,3 @@ if (segment.startsWith('_')) { | ||
} | ||
} else if (segment === ':') { | ||
} else if (segment === ':' || segment === ':_') { | ||
url += '/*' | ||
@@ -168,0 +183,0 @@ } else if (segment !== 'route') { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31589
8
637
211
17
1