chore(plugin-redirects): lints and builds (#4551)
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
max_line_length = null
|
||||
@@ -1,3 +1,37 @@
|
||||
/** @type {import('prettier').Config} */
|
||||
module.exports = {
|
||||
extends: ['@payloadcms'],
|
||||
overrides: [
|
||||
{
|
||||
extends: ['plugin:@typescript-eslint/disable-type-checked'],
|
||||
files: ['*.js', '*.cjs', '*.json', '*.md', '*.yml', '*.yaml'],
|
||||
},
|
||||
{
|
||||
files: ['package.json', 'tsconfig.json'],
|
||||
rules: {
|
||||
'perfectionist/sort-array-includes': 'off',
|
||||
'perfectionist/sort-astro-attributes': 'off',
|
||||
'perfectionist/sort-classes': 'off',
|
||||
'perfectionist/sort-enums': 'off',
|
||||
'perfectionist/sort-exports': 'off',
|
||||
'perfectionist/sort-imports': 'off',
|
||||
'perfectionist/sort-interfaces': 'off',
|
||||
'perfectionist/sort-jsx-props': 'off',
|
||||
'perfectionist/sort-keys': 'off',
|
||||
'perfectionist/sort-maps': 'off',
|
||||
'perfectionist/sort-named-exports': 'off',
|
||||
'perfectionist/sort-named-imports': 'off',
|
||||
'perfectionist/sort-object-types': 'off',
|
||||
'perfectionist/sort-objects': 'off',
|
||||
'perfectionist/sort-svelte-attributes': 'off',
|
||||
'perfectionist/sort-union-types': 'off',
|
||||
'perfectionist/sort-vue-attributes': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.json'],
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
root: true,
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
module.exports = {
|
||||
printWidth: 100,
|
||||
parser: "typescript",
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
trailingComma: "all",
|
||||
arrowParens: "avoid",
|
||||
};
|
||||
15
packages/plugin-redirects/.swcrc
Normal file
15
packages/plugin-redirects/.swcrc
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/swcrc",
|
||||
"sourceMaps": "inline",
|
||||
"jsc": {
|
||||
"target": "esnext",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": true,
|
||||
"dts": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
||||
@@ -1,92 +1,7 @@
|
||||
# Payload Redirects Plugin
|
||||
|
||||
[](https://www.npmjs.com/package/@payloadcms/plugin-redirects)
|
||||
A plugin for [Payload](https://github.com/payloadcms/payload) to easily manage your redirects from within your admin panel.
|
||||
|
||||
A plugin for [Payload](https://github.com/payloadcms/payload) to easily manage your redirects.
|
||||
|
||||
Core features:
|
||||
|
||||
- Adds a `redirects` collection to your config that:
|
||||
- includes a `from` and `to` fields
|
||||
- allows `to` to be a document reference
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
yarn add @payloadcms/plugin-redirects
|
||||
# OR
|
||||
npm i @payloadcms/plugin-redirects
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
In the `plugins` array of your [Payload config](https://payloadcms.com/docs/configuration/overview), call the plugin with [options](#options):
|
||||
|
||||
```js
|
||||
import { buildConfig } from "payload/config";
|
||||
import redirects from "@payloadcms/plugin-redirects";
|
||||
|
||||
const config = buildConfig({
|
||||
collections: [
|
||||
{
|
||||
slug: "pages",
|
||||
fields: [],
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
redirects({
|
||||
collections: ["pages"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
- `collections` : string[] | optional
|
||||
|
||||
An array of collections slugs to populate in the `to` field of each redirect.
|
||||
|
||||
- `overrides` : object | optional
|
||||
|
||||
A partial collection config that allows you to override anything on the `redirects` collection.
|
||||
|
||||
## TypeScript
|
||||
|
||||
All types can be directly imported:
|
||||
|
||||
```js
|
||||
import { PluginConfig } from "@payloadcms/plugin-redirects/types";
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
To actively develop or debug this plugin you can either work directly within the demo directory of this repo, or link your own project.
|
||||
|
||||
1. #### Internal Demo
|
||||
|
||||
This repo includes a fully working, self-seeding instance of Payload that installs the plugin directly from the source code. This is the easiest way to get started. To spin up this demo, follow these steps:
|
||||
|
||||
1. First clone the repo
|
||||
1. Then, `cd YOUR_PLUGIN_REPO && yarn && cd demo && yarn && yarn dev`
|
||||
1. Now open `http://localhost:3000/admin` in your browser
|
||||
1. Enter username `dev@payloadcms.com` and password `test`
|
||||
|
||||
That's it! Changes made in `./src` will be reflected in your demo. Keep in mind that the demo database is automatically seeded on every startup, any changes you make to the data get destroyed each time you reboot the app.
|
||||
|
||||
1. #### Linked Project
|
||||
|
||||
You can alternatively link your own project to the source code:
|
||||
|
||||
1. First clone the repo
|
||||
1. Then, `cd YOUR_PLUGIN_REPO && yarn && cd demo && cp env.example .env && yarn && yarn dev`
|
||||
1. Now `cd` back into your own project and run, `yarn link @payloadcms/plugin-redirects`
|
||||
1. If this plugin using React in any way, continue to the next step. Otherwise skip to step 7.
|
||||
1. From your own project, `cd node_modules/react && yarn link && cd ../react-dom && yarn link && cd ../../`
|
||||
1. Then, `cd YOUR_PLUGIN_REPO && yarn link react react-dom`
|
||||
|
||||
All set! You can now boot up your own project as normal, and your local copy of the plugin source code will be used. Keep in mind that changes to the source code require a rebuild, `yarn build`.
|
||||
|
||||
## Screenshots
|
||||
- [Source code](https://github.com/payloadcms/payload/tree/main/packages/plugin-redirects)
|
||||
- [Documentation](https://payloadcms.com/docs/plugins/redirects)
|
||||
- [Documentation source](https://github.com/payloadcms/payload/tree/main/docs/plugins/redirects.mdx)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,12 +7,12 @@
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"lint": "eslint src",
|
||||
"lint:fix": "eslint --fix --ext .ts,.tsx src",
|
||||
"clean": "rimraf dist",
|
||||
"prepublishOnly": "yarn clean && yarn build"
|
||||
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
|
||||
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
||||
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
||||
"clean": "rimraf {dist,*.tsbuildinfo}",
|
||||
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
||||
"prepublishOnly": "pnpm clean && pnpm build"
|
||||
},
|
||||
"keywords": [
|
||||
"payload",
|
||||
@@ -29,29 +29,23 @@
|
||||
"payload": "^0.18.5 || ^1.0.0 || ^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@payloadcms/eslint-config": "^0.0.1",
|
||||
"@types/escape-html": "^1.0.1",
|
||||
"@payloadcms/eslint-config": "workspace:*",
|
||||
"@types/express": "^4.17.9",
|
||||
"@types/node": "18.11.3",
|
||||
"@types/react": "18.0.21",
|
||||
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"copyfiles": "^2.4.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.19.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-filenames": "^1.3.2",
|
||||
"eslint-plugin-import": "2.25.4",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"nodemon": "^2.0.6",
|
||||
"payload": "^1.8.2",
|
||||
"prettier": "^2.7.1",
|
||||
"react": "^18.0.0",
|
||||
"rimraf": "^5.0.5",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.8.4"
|
||||
"payload": "workspace:*",
|
||||
"react": "^18.0.0"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"default": "./src/index.ts",
|
||||
"types": "./src/index.ts"
|
||||
}
|
||||
},
|
||||
"publishConfig": {
|
||||
"exports": null,
|
||||
"main": "./dist/index.js",
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
|
||||
@@ -17,7 +17,7 @@ export function isObject(item: unknown): boolean {
|
||||
export default function deepMerge<T, R>(target: T, source: R): T {
|
||||
const output = { ...target }
|
||||
if (isObject(target) && isObject(source)) {
|
||||
Object.keys(source).forEach(key => {
|
||||
Object.keys(source).forEach((key) => {
|
||||
if (isObject(source[key])) {
|
||||
if (!(key in target)) {
|
||||
Object.assign(output, { [key]: source[key] })
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Config } from 'payload/config'
|
||||
|
||||
import deepMerge from './deepMerge'
|
||||
import type { PluginConfig } from './types'
|
||||
|
||||
import deepMerge from './deepMerge'
|
||||
|
||||
const redirects =
|
||||
(pluginConfig: PluginConfig) =>
|
||||
(incomingConfig: Config): Config => ({
|
||||
@@ -11,30 +12,30 @@ const redirects =
|
||||
...(incomingConfig?.collections || []),
|
||||
deepMerge(
|
||||
{
|
||||
slug: 'redirects',
|
||||
admin: {
|
||||
defaultColumns: ['from', 'to.type', 'createdAt'],
|
||||
},
|
||||
access: {
|
||||
read: (): boolean => true,
|
||||
},
|
||||
admin: {
|
||||
defaultColumns: ['from', 'to.type', 'createdAt'],
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'from',
|
||||
label: 'From URL',
|
||||
index: true,
|
||||
label: 'From URL',
|
||||
required: true,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'to',
|
||||
label: false,
|
||||
type: 'group',
|
||||
fields: [
|
||||
{
|
||||
name: 'type',
|
||||
admin: {
|
||||
layout: 'horizontal',
|
||||
},
|
||||
defaultValue: 'reference',
|
||||
label: 'To URL Type',
|
||||
type: 'radio',
|
||||
options: [
|
||||
{
|
||||
label: 'Internal link',
|
||||
@@ -45,33 +46,33 @@ const redirects =
|
||||
value: 'custom',
|
||||
},
|
||||
],
|
||||
defaultValue: 'reference',
|
||||
admin: {
|
||||
layout: 'horizontal',
|
||||
},
|
||||
type: 'radio',
|
||||
},
|
||||
{
|
||||
name: 'reference',
|
||||
label: 'Document to redirect to',
|
||||
type: 'relationship',
|
||||
relationTo: pluginConfig?.collections || [],
|
||||
required: true,
|
||||
admin: {
|
||||
condition: (_, siblingData) => siblingData?.type === 'reference',
|
||||
},
|
||||
label: 'Document to redirect to',
|
||||
relationTo: pluginConfig?.collections || [],
|
||||
required: true,
|
||||
type: 'relationship',
|
||||
},
|
||||
{
|
||||
name: 'url',
|
||||
label: 'Custom URL',
|
||||
type: 'text',
|
||||
required: true,
|
||||
admin: {
|
||||
condition: (_, siblingData) => siblingData?.type === 'custom',
|
||||
},
|
||||
label: 'Custom URL',
|
||||
required: true,
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
label: false,
|
||||
type: 'group',
|
||||
},
|
||||
],
|
||||
slug: 'redirects',
|
||||
},
|
||||
pluginConfig?.overrides || {},
|
||||
),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CollectionConfig } from 'payload/types'
|
||||
|
||||
export interface PluginConfig {
|
||||
overrides?: Partial<CollectionConfig>
|
||||
collections?: string[]
|
||||
overrides?: Partial<CollectionConfig>
|
||||
}
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"outDir": "./dist",
|
||||
"allowJs": true,
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
"jsx": "react",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"declarationDir": "./dist",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"composite": true, // Make sure typescript knows that this module depends on their references
|
||||
"noEmit": false /* Do not emit outputs. */,
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
||||
"rootDir": "./src" /* Specify the root folder within your source files. */
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
"exclude": [
|
||||
"dist",
|
||||
"build",
|
||||
"tests",
|
||||
"test",
|
||||
"node_modules",
|
||||
".eslintrc.js",
|
||||
"src/**/*.spec.js",
|
||||
"src/**/*.spec.jsx",
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.spec.tsx"
|
||||
],
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
|
||||
"references": [{ "path": "../payload" }]
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
max_line_length = null
|
||||
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@@ -1187,6 +1187,24 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../payload
|
||||
|
||||
packages/plugin-redirects:
|
||||
devDependencies:
|
||||
'@payloadcms/eslint-config':
|
||||
specifier: workspace:*
|
||||
version: link:../eslint-config-payload
|
||||
'@types/express':
|
||||
specifier: ^4.17.9
|
||||
version: 4.17.21
|
||||
'@types/react':
|
||||
specifier: 18.0.21
|
||||
version: 18.0.21
|
||||
payload:
|
||||
specifier: workspace:*
|
||||
version: link:../payload
|
||||
react:
|
||||
specifier: ^18.0.0
|
||||
version: 18.2.0
|
||||
|
||||
packages/plugin-search:
|
||||
dependencies:
|
||||
ts-deepmerge:
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
{ "path": "./packages/plugin-cloud" },
|
||||
{ "path": "./packages/plugin-form-builder" },
|
||||
{ "path": "./packages/plugin-nested-docs" },
|
||||
{ "path": "./packages/plugin-redirects" },
|
||||
{ "path": "./packages/plugin-search" },
|
||||
{ "path": "./packages/plugin-seo" },
|
||||
{ "path": "./packages/plugin-stripe" },
|
||||
|
||||
Reference in New Issue
Block a user