Skip to content

Commit

Permalink
v0.2.0 Support for remix v2
Browse files Browse the repository at this point in the history
  • Loading branch information
GuptaSiddhant committed Oct 26, 2023
1 parent 6552be5 commit 6019129
Show file tree
Hide file tree
Showing 3 changed files with 902 additions and 2,060 deletions.
26 changes: 14 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import fg from "fast-glob";
import fs from "node:fs";
import path from "node:path";

import { flatRoutesUniversal } from "@remix-run/dev/dist/config/flat-routes";
import {
flatRoutesUniversal,
routeModuleExts,
} from "@remix-run/dev/dist/config/flat-routes";
import type {
ConfigRoute,
RouteManifest,
} from "@remix-run/dev/dist/config/routes";
import { routeModuleExts } from "@remix-run/dev/dist/config/routesConvention";

export interface AddRoutesFolderOptions {
/** URL path to mount the directory to. If left undefined, the directory name will be used. */
Expand All @@ -20,7 +22,7 @@ export interface AddRoutesFolderOptions {

export function addRoutesFolder(
routesFolder: string,
options: AddRoutesFolderOptions = {},
options: AddRoutesFolderOptions = {}
): RouteManifest {
const {
urlPath = routesFolder,
Expand All @@ -32,23 +34,23 @@ export function addRoutesFolder(
const rootFilePath = generateRootFilePath(
appDirectory,
routesFolder,
routePaths,
routePaths
);

return generateFlatRoutes(
routesFolder,
rootFilePath,
urlPath,
routePaths,
appDirectory,
appDirectory
);
}

const ROOT_LAYOUT_FILE = "__root";

function generateRoutesDirPath(
routesFolder: string,
appDirectory: string = "app",
appDirectory: string = "app"
) {
const currentDir = process.cwd();
const appDirPth = path.resolve(currentDir, appDirectory);
Expand All @@ -62,15 +64,15 @@ function generateRoutesDirPath(
function generateRootFilePath(
appDirectory: string,
routesFolder: string,
routePaths: string[],
routePaths: string[]
) {
const rootFile = routePaths.find((routePath) =>
routePath.includes(path.join(routesFolder, ROOT_LAYOUT_FILE)),
routePath.includes(path.join(routesFolder, ROOT_LAYOUT_FILE))
);

if (!rootFile) {
throw new Error(
`Directory "${routesFolder}" does not contain a "${ROOT_LAYOUT_FILE}" file. The root file should contain <Outlet/>.`,
`Directory "${routesFolder}" does not contain a "${ROOT_LAYOUT_FILE}" file. The root file should contain <Outlet/>.`
);
}

Expand All @@ -79,7 +81,7 @@ function generateRootFilePath(

function generateRoutePaths(
routesDirPath: string,
ignoredRouteFiles: string[] = ["**/.*"],
ignoredRouteFiles: string[] = ["**/.*"]
) {
const extensions = routeModuleExts.join(",");
const routePaths = fg
Expand All @@ -93,7 +95,7 @@ function generateRoutePaths(

// Remove the current working directory from the route paths
return routePaths.map((routePath) =>
routePath.slice(process.cwd().length + 1),
routePath.slice(process.cwd().length + 1)
);
}

Expand All @@ -102,7 +104,7 @@ function generateFlatRoutes(
rootFilePath: string,
urlPath: string,
routePaths: string[],
appDirectory: string,
appDirectory: string
) {
const flatRoutes = flatRoutesUniversal(appDirectory, routePaths, routesDir);

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remix-routes-folder",
"version": "0.1.2",
"version": "0.2.0",
"description": "A Remix plugin that allows you to organize your routes in multiple route-folders.",
"keywords": [
"remix",
Expand Down Expand Up @@ -37,12 +37,12 @@
},
"devDependencies": {
"@jsdevtools/npm-publish": "^1.4.3",
"@remix-run/dev": "^1.14.0",
"@remix-run/dev": "^2.0.0",
"@types/node": "^18.0.0",
"fast-glob": "^3",
"typescript": "^4.9.5"
"typescript": "^5.0.0"
},
"peerDependencies": {
"@remix-run/dev": "^1.14.0"
"@remix-run/dev": "^2.0.0"
}
}
Loading

0 comments on commit 6019129

Please sign in to comment.