{"id":13606907,"url":"https://github.com/Lindeneg/generate-next-links","last_synced_at":"2025-04-12T11:31:02.278Z","repository":{"id":37030081,"uuid":"393467027","full_name":"Lindeneg/generate-next-links","owner":"Lindeneg","description":"(Not Maintained) Generate typescript enum containing paths to nextjs pages","archived":true,"fork":false,"pushed_at":"2023-01-08T21:19:17.000Z","size":356,"stargazers_count":12,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T23:33:23.650Z","etag":null,"topics":["cli","link-generator","nextjs","react","typescript","utility"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lindeneg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-06T18:27:47.000Z","updated_at":"2023-11-13T18:14:02.000Z","dependencies_parsed_at":"2023-02-08T07:31:26.410Z","dependency_job_id":null,"html_url":"https://github.com/Lindeneg/generate-next-links","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lindeneg%2Fgenerate-next-links","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lindeneg%2Fgenerate-next-links/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lindeneg%2Fgenerate-next-links/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lindeneg%2Fgenerate-next-links/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lindeneg","download_url":"https://codeload.github.com/Lindeneg/generate-next-links/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560061,"owners_count":21124586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","link-generator","nextjs","react","typescript","utility"],"created_at":"2024-08-01T19:01:13.677Z","updated_at":"2025-04-12T11:31:01.769Z","avatar_url":"https://github.com/Lindeneg.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Lindeneg_generate-next-links\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=Lindeneg_generate-next-links) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Lindeneg_generate-next-links\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Lindeneg_generate-next-links) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=Lindeneg_generate-next-links\u0026metric=ncloc)](https://sonarcloud.io/summary/new_code?id=Lindeneg_generate-next-links)\n\n\n*I **highly** recommend checking out [this](https://github.com/tatethurston/nextjs-routes) library created by [Tate Thurston](https://github.com/tatethurston). It types the standard nextjs `Link` component by using declaration merging. If you have no need for an exported `enum` or `JSON` file, I urge you to use `nextjs-routes`, as it is superior. I will personally use it going forward.*\n\n## Generate links to nextjs pages\n\nThis program generates a file with a [TypeScript](https://www.typescriptlang.org/) `enum` containing pathnames to all pages in a [next.js](https://nextjs.org/) application.\n\n---\n\n### Getting Started\n\n##### Installing\n\n-   `npm install -g generate-next-links`\n-   `generate-next-links [...ARGS]`\n-   **or**\n-   `npx generate-next-links@latest [...ARGS]`\n\n##### Options\n\n```\nUsage: generate-next-links\n\nIf no 'path' is specified, a 'pages' folder must be located\ninside the folder where the script is running from\n\nOptions:\n -N --name [NAME]         name of generated TypeScript enum               default: links\n -P --path [PATH]         path to folder where 'pages' directory resides  default: cwd\n -O --out  [PATH]         path to folder where ts file will be written to default: cwd\n -B --base [PATH]         define a custom base path to prefix all paths   default: /\n -S --tab-size [INT]      specify tab size used in generated file         default: 4\n -A --api                 include API paths found in '/pages/api' folder\n -R --root                include a root entry with path [BASE]\n -D --dry                 perform all operations except writing to disk\n -V --verbose             show all log messages in stdout\n -T --omit-timestamp      omit timestamp from written ts file\n -J --export-json         export json instead of ts enum\n -C --convert-camel-case  convert camel case to be delimited by underscore\n -E --convert-hyphens     convert kebab case to be delimited by underscore\n -Q --single-quote        use single quotes in the generated file\n -I --version             show current version\n -H --help                show help\n```\n\n---\n\n### Description\n\nSuppose a next.js application with the following `pages` structure:\n\n```\n.\n└── pages\n    ├── 404.tsx\n    ├── 500.tsx\n    ├── admin\n    │   ├── administrate.tsx\n    │   ├── index.tsx\n    │   └── user\n    │       ├── index.tsx\n    │       └── options\n    │           └── dashboard.tsx\n    ├── _app.tsx\n    ├── content\n    │   ├── [articleId]\n    │   │   └── index.tsx\n    │   └── index.tsx\n    ├── _document.tsx\n    ├── index.tsx\n    ├── posts\n    │   └── [...slug].tsx\n    └── user\n        └── [[...slug]].tsx\n```\n\n_`[...slug]` and `[[...slug]]` are [catch-all-routes](https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes)_\n\nGiven the above structure, this program will generate a `.ts` file with the following `enum`:\n\n```ts\nexport enum links {\n    N404 = '/404',\n    N500 = '/500',\n    ADMIN = '/admin',\n    ADMIN_ADMINISTRATE = '/admin/administrate',\n    ADMIN_USER = '/admin/user',\n    ADMIN_USER_OPTIONS_DASHBOARD = '/admin/user/options/dashboard',\n    CONTENT = '/content',\n    CONTENT_ARTICLEID = '/content/[articleId]',\n    POSTS_CATCHALL_SLUG = '/posts/[...slug]',\n    USER_OPTIONAL_CATCHALL_SLUG = '/user/[[...slug]]',\n}\n```\n\nThe dynamic paths can easily be used in conjunction with [next/link](https://nextjs.org/docs/api-reference/next/link#with-url-object)\n\n```tsx\nfunction component (props) {\n  return (\n    \u003cLink\n      href={{\n        pathname: links.CONTENT_ARTICLEID,\n        query: {\n          articleId: props.id\n        },\n      }}\n    \u003e\n  )\n}\n```\n\nOr with another library such as [cl-fill-link](https://github.com/Lindeneg/cl-fill-link)\n\n```ts\n// returns: '/posts/category/music/jazz/miles-davis'\nfillLink(links.POSTS_CATCHALL_SLUG, {\n    slug: ['category', 'music', 'jazz', 'miles-davis'],\n});\n```\n\nSuppose the following `api` folder is present in the above example\n\n```\n.\n└── pages\n    ├── api\n        ├── article\n        │   └── create.ts\n        ├── auth\n        │   ├── login.ts\n        │   └── logout.ts\n        └── user\n            └── [[...userId]].ts\n```\n\nRun the program with the `--api` flag to produce the following:\n\n```ts\nexport enum links {\n    N404 = '/404',\n    N500 = '/500',\n    ADMIN = '/admin',\n    ADMIN_ADMINISTRATE = '/admin/administrate',\n    ADMIN_USER = '/admin/user',\n    ADMIN_USER_OPTIONS_DASHBOARD = '/admin/user/options/dashboard',\n    API_ARTICLE_CREATE = '/api/article/create',\n    API_AUTH_LOGIN = '/api/auth/login',\n    API_AUTH_LOGOUT = '/api/auth/logout',\n    API_USER_OPTIONAL_CATCHALL_USERID = '/api/user/[[...userId]]',\n    CONTENT = '/content',\n    CONTENT_ARTICLEID = '/content/[articleId]',\n    POSTS_CATCHALL_SLUG = '/posts/[...slug]',\n    USER_OPTIONAL_CATCHALL_SLUG = '/user/[[...slug]]',\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLindeneg%2Fgenerate-next-links","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLindeneg%2Fgenerate-next-links","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLindeneg%2Fgenerate-next-links/lists"}