-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from JasonPaff/cli-filename-update
Updated the CLI to allow for a filename option to override the default 'routeType.ts' filename
- Loading branch information
Showing
27 changed files
with
518 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"next-typesafe-url": minor | ||
--- | ||
|
||
updates the cli to allow for a custom filename to be set under the --filename flag to replace the default of 'routeType.ts' - Thank you @JasonPaff ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This file is generated by next-typesafe-url | ||
// Do not edit this file directly. | ||
|
||
// @generated | ||
// prettier-ignore | ||
/* eslint-disable */ | ||
|
||
declare module "@@@next-typesafe-url" { | ||
import type { InferRoute, StaticRoute } from "next-typesafe-url"; | ||
|
||
interface DynamicRouter { | ||
"/[slug]/[...foo]": InferRoute<import("./src/app/[slug]/[...foo]/route-type").RouteType>; | ||
} | ||
|
||
interface StaticRouter { | ||
"/": StaticRoute; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const withMDX = require('@next/mdx')() | ||
|
||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'], | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} | ||
|
||
module.exports = withMDX(nextConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "custom-filename", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "concurrently \"next-typesafe-url -w --filename route-type --pageExtensions js,jsx,mdx,ts,tsx\" \"next dev\"", | ||
"build": "next-typesafe-url --filename route-type --pageExtensions js,jsx,mdx,ts,tsx && next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"@mdx-js/loader": "^3.0.1", | ||
"@mdx-js/react": "^3.0.1", | ||
"@next/mdx": "^14.2.4", | ||
"@types/mdx": "^2.0.13", | ||
"@types/node": "18.16.3", | ||
"@types/react": "18.2.5", | ||
"@types/react-dom": "18.2.3", | ||
"autoprefixer": "10.4.14", | ||
"concurrently": "^8.0.1", | ||
"eslint": "8.39.0", | ||
"eslint-config-next": "13.4.0", | ||
"next": "13.4.12", | ||
"next-typesafe-url": "workspace:*", | ||
"postcss": "8.4.23", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"tailwindcss": "3.3.2", | ||
"typescript": "5.0.4", | ||
"zod": "^3.20.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
examples/custom-filename/src/app/[slug]/[...foo]/client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use client"; | ||
|
||
import { $path } from "next-typesafe-url"; | ||
import Link from "next/link"; | ||
import { useState } from "react"; | ||
import { useRouteParams, useSearchParams } from "next-typesafe-url/app"; | ||
import { Route } from "./route-type"; | ||
import { useParams } from "next/navigation"; | ||
|
||
export const Client = () => { | ||
const [input, setInput] = useState(""); | ||
const nextParams = useParams(); | ||
console.log("nextParams", nextParams); | ||
|
||
const params = useSearchParams(Route.searchParams); | ||
const routeParams = useRouteParams(Route.routeParams); | ||
|
||
return ( | ||
<> | ||
<Link href={$path({ route: "/" })}>Back</Link> | ||
<br /> | ||
<input value={input} onChange={(e) => setInput(e.target.value)} /> | ||
<Link | ||
href={$path({ | ||
route: "/[slug]/[...foo]", | ||
routeParams: { | ||
slug: input === "" ? "default" : input, | ||
foo: [123, 424, 343], | ||
}, | ||
searchParams: { | ||
location: "us", | ||
userInfo: { name: "harry", age: 123 }, | ||
}, | ||
})} | ||
> | ||
hooks | ||
</Link> | ||
<br /> | ||
<h1>searchParams</h1> | ||
<div>{`data: ${JSON.stringify(params)}`}</div> | ||
<h1>routeParams</h1> | ||
<div>{`data: ${JSON.stringify(routeParams)}`}</div> | ||
</> | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
examples/custom-filename/src/app/[slug]/[...foo]/error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; // Error components must be Client components | ||
|
||
import { useEffect } from "react"; | ||
|
||
export default function Error({ | ||
error, | ||
reset, | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
useEffect(() => { | ||
// Log the error to an error reporting service | ||
console.error(error); | ||
}, [error]); | ||
|
||
return ( | ||
<div> | ||
<h2>Something went wrong!</h2> | ||
<button | ||
onClick={ | ||
// Attempt to recover by trying to re-render the segment | ||
() => reset() | ||
} | ||
> | ||
Try again | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { withParamValidation } from "next-typesafe-url/app/hoc"; | ||
import { InferPagePropsType } from "next-typesafe-url"; | ||
import { Route, RouteType } from "./route-type"; | ||
import { Client } from "./client"; | ||
|
||
type PageProps = InferPagePropsType<RouteType>; | ||
|
||
let count = 0; | ||
|
||
const Page = ({ routeParams, searchParams }: PageProps) => { | ||
console.log("render", count++); | ||
console.log(JSON.stringify(routeParams)); | ||
console.log(JSON.stringify(searchParams)); | ||
|
||
return ( | ||
<> | ||
<div>{`data: ${JSON.stringify(routeParams)}`}</div> | ||
<br /> | ||
<div>{`data: ${JSON.stringify(searchParams)}`}</div> | ||
<Client /> | ||
</> | ||
); | ||
}; | ||
|
||
export default withParamValidation(Page, Route); |
20 changes: 20 additions & 0 deletions
20
examples/custom-filename/src/app/[slug]/[...foo]/route-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { z } from "zod"; | ||
import { type DynamicRoute } from "next-typesafe-url"; | ||
|
||
export const Route = { | ||
routeParams: z.object({ | ||
slug: z.string(), | ||
foo: z.array(z.number()).or(z.number()), | ||
}), | ||
searchParams: z.object({ | ||
location: z.enum(["us", "eu"]).optional(), | ||
userInfo: z | ||
.object({ | ||
name: z.string(), | ||
age: z.number(), | ||
}) | ||
.optional(), | ||
}), | ||
} satisfies DynamicRoute; | ||
|
||
export type RouteType = typeof Route; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { z } from "zod"; | ||
import { withLayoutParamValidation } from "next-typesafe-url/app/hoc"; | ||
import type { DynamicLayout, InferLayoutPropsType } from "next-typesafe-url"; | ||
|
||
const LayoutRoute = { | ||
routeParams: z.object({ | ||
slug: z.string(), | ||
}), | ||
} satisfies DynamicLayout; | ||
type LayoutType = typeof LayoutRoute; | ||
|
||
type Props = InferLayoutPropsType<LayoutType>; | ||
function Layout({ children, routeParams }: Props) { | ||
return ( | ||
<div> | ||
<h1>THIS IS A LAYOUT</h1> | ||
<p>{JSON.stringify(routeParams)}</p> | ||
<div className="border border-black">{children}</div> | ||
<p>bottom</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default withLayoutParamValidation(Layout, LayoutRoute); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Inter } from "next/font/google"; | ||
import "./globals.css"; | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
export const metadata = { | ||
title: "Create Next App", | ||
description: "Generated by create next app", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body className={inter.className}>{children}</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
|
||
import { $path, type RouterOutputs } from "next-typesafe-url"; | ||
import Link from "next/link"; | ||
|
||
type _ThisIsHelpful = RouterOutputs["/[slug]/[...foo]"]["routeParams"]; | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<div>test</div> | ||
<Link | ||
href={$path({ | ||
route: "/[slug]/[...foo]", | ||
routeParams: { slug: "string", foo: [123, 424, 343] }, | ||
searchParams: { | ||
location: "us", | ||
userInfo: { name: "string", age: 123 }, | ||
}, | ||
})} | ||
> | ||
server component! | ||
</Link> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { MDXComponents } from "mdx/types"; | ||
|
||
export function useMDXComponents(components: MDXComponents): MDXComponents { | ||
return { | ||
...components, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
module.exports = { | ||
content: [ | ||
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}', | ||
'./src/components/**/*.{js,ts,jsx,tsx,mdx}', | ||
'./src/app/**/*.{js,ts,jsx,tsx,mdx}', | ||
], | ||
theme: { | ||
extend: { | ||
backgroundImage: { | ||
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', | ||
'gradient-conic': | ||
'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', | ||
}, | ||
}, | ||
}, | ||
plugins: [], | ||
} |
Oops, something went wrong.