chore(scripts): fix generate template variations script (#9671)

This commit is contained in:
Paul
2024-12-02 17:30:52 -06:00
committed by GitHub
parent 0dbfc237d3
commit 5b3079a88e
16 changed files with 358 additions and 343 deletions

View File

@@ -52,7 +52,6 @@ jobs:
avatar_url: 'https://l4wlsi8vxy8hre4v.public.blob.vercel-storage.com/discord-bot-logo.png'
update_templates:
if: false # Still needs some troubleshooting
runs-on: ubuntu-latest
permissions:
contents: write

View File

@@ -36,6 +36,10 @@ type TemplateVariations = {
envNames?: {
dbUri: string
}
/**
* @default false
*/
skipReadme?: boolean
configureConfig?: boolean
generateLockfile?: boolean
}
@@ -92,6 +96,7 @@ async function main() {
// This will replace the process.env.DATABASE_URI to process.env.POSTGRES_URL
dbUri: 'POSTGRES_URL',
},
skipReadme: true,
},
{
name: 'payload-postgres-template',
@@ -151,6 +156,7 @@ async function main() {
envNames,
sharp,
configureConfig,
skipReadme = false,
} of variations) {
header(`Generating ${name}...`)
const destDir = path.join(templatesDir, dirname)
@@ -160,6 +166,7 @@ async function main() {
'.next',
'.env$',
'pnpm-lock.yaml',
...(skipReadme ? ['README.md'] : ['']),
])
log(`Copied to ${destDir}`)
@@ -183,6 +190,7 @@ async function main() {
})
}
if (!skipReadme) {
await generateReadme({
destDir,
data: {
@@ -192,6 +200,16 @@ async function main() {
...(vercelDeployButtonLink && { vercelDeployButtonLink }),
},
})
}
if (generateLockfile) {
log('Generating pnpm-lock.yaml')
execSyncSafe(`pnpm install --ignore-workspace`, { cwd: destDir })
} else {
log('Installing dependencies without generating lockfile')
execSyncSafe(`pnpm install --ignore-workspace`, { cwd: destDir })
await fs.rm(`${destDir}/pnpm-lock.yaml`, { force: true })
}
// Copy in initial migration if db is postgres. This contains user and media.
if (db === 'postgres' || db === 'vercel-postgres') {
@@ -214,17 +232,13 @@ async function main() {
cwd: destDir,
env: {
...process.env,
PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit',
BLOB_READ_WRITE_TOKEN: 'vercel_blob_rw_TEST_asdf',
DATABASE_URI: 'postgres://localhost:5432/payloadtests',
},
})
}
if (generateLockfile) {
log('Generating pnpm-lock.yaml')
execSyncSafe(`pnpm install --ignore-workspace`, { cwd: destDir })
}
// TODO: Email?
// TODO: Sharp?
@@ -302,7 +316,7 @@ function log(message: string) {
function execSyncSafe(command: string, options?: Parameters<typeof execSync>[1]) {
try {
console.log(`Executing: ${command}`)
execSync(command, options)
execSync(command, { stdio: 'inherit', ...options })
} catch (error) {
if (error instanceof Error) {
const stderr = (error as any).stderr?.toString()

File diff suppressed because it is too large Load Diff

View File

@@ -21,6 +21,7 @@ export async function generateStaticParams() {
draft: false,
limit: 1000,
overrideAccess: false,
pagination: false,
select: {
slug: true,
},

View File

@@ -21,6 +21,7 @@ export async function generateStaticParams() {
draft: false,
limit: 1000,
overrideAccess: false,
pagination: false,
select: {
slug: true,
},

View File

@@ -32,7 +32,7 @@ export const Pages: CollectionConfig<'pages'> = {
},
// This config controls what's populated by default when a page is referenced
// https://payloadcms.com/docs/queries/select#defaultpopulate-collection-config-property
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pagess'>
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pages'>
defaultPopulate: {
title: true,
slug: true,

View File

@@ -874,11 +874,9 @@ export interface PagesSelect<T extends boolean = true> {
meta?:
| T
| {
overview?: T;
title?: T;
image?: T;
description?: T;
preview?: T;
};
publishedAt?: T;
slug?: T;
@@ -899,11 +897,9 @@ export interface PostsSelect<T extends boolean = true> {
meta?:
| T
| {
overview?: T;
title?: T;
image?: T;
description?: T;
preview?: T;
};
publishedAt?: T;
authors?: T;
@@ -1208,7 +1204,6 @@ export interface SearchSelect<T extends boolean = true> {
title?: T;
priority?: T;
doc?: T;
docUrl?: T;
slug?: T;
meta?:
| T

View File

@@ -48,7 +48,7 @@ export default async function Page({ params: paramsPromise }: Args) {
const { slug = 'home' } = await paramsPromise
const url = '/' + slug
let page: Pick<PageType, 'slug' | 'layout' | 'hero'> | null
let page: PageType | null
page = await queryPageBySlug({
slug,
@@ -97,11 +97,6 @@ const queryPageBySlug = cache(async ({ slug }: { slug: string }) => {
limit: 1,
pagination: false,
overrideAccess: draft,
select: {
slug: true,
hero: true,
layout: true,
},
where: {
slug: {
equals: slug,

View File

@@ -70,6 +70,7 @@ export async function GET(
collection,
draft: true,
limit: 1,
// pagination: false reduces overhead if you don't need totalDocs
pagination: false,
depth: 0,
select: {},

View File

@@ -20,7 +20,6 @@ export async function generateStaticParams() {
collection: 'posts',
draft: false,
limit: 1000,
pagination: false,
overrideAccess: false,
select: {
slug: true,

View File

@@ -17,6 +17,7 @@ import { SlugComponent as SlugComponent_92cc057d0a2abb4f6cf0307edf59f986 } from
import { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
import { BlocksFeatureClient as BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
import { LinkToDoc as LinkToDoc_aead06e4cbf6b2620c5c51c9ab283634 } from '@payloadcms/plugin-search/client'
import { ReindexButton as ReindexButton_aead06e4cbf6b2620c5c51c9ab283634 } from '@payloadcms/plugin-search/client'
import { default as default_1a7510af427896d367a49dbf838d2de6 } from '@/components/BeforeDashboard'
import { default as default_8a7ab0eb7ab5c511aba12e68480bfe5e } from '@/components/BeforeLogin'
@@ -57,6 +58,7 @@ export const importMap = {
'@payloadcms/richtext-lexical/client#BlocksFeatureClient':
BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
'@payloadcms/plugin-search/client#LinkToDoc': LinkToDoc_aead06e4cbf6b2620c5c51c9ab283634,
'@payloadcms/plugin-search/client#ReindexButton': ReindexButton_aead06e4cbf6b2620c5c51c9ab283634,
'@/components/BeforeDashboard#default': default_1a7510af427896d367a49dbf838d2de6,
'@/components/BeforeLogin#default': default_8a7ab0eb7ab5c511aba12e68480bfe5e,
}

View File

@@ -32,7 +32,7 @@ export const Pages: CollectionConfig<'pages'> = {
},
// This config controls what's populated by default when a page is referenced
// https://payloadcms.com/docs/queries/select#defaultpopulate-collection-config-property
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pages'>
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pagess'>
defaultPopulate: {
title: true,
slug: true,

View File

@@ -30,7 +30,8 @@ export const MediumImpactHero: React.FC<Page['hero']> = ({ links, media, richTex
<Media
className="-mx-4 md:-mx-8 2xl:-mx-16"
imgClassName=""
priority
priority={false}
loading="lazy"
resource={media}
/>
{media?.caption && (

View File

@@ -79,7 +79,13 @@ export const PostHero: React.FC<{
</div>
<div className="min-h-[80vh] select-none">
{metaImage && typeof metaImage !== 'string' && (
<Media fill imgClassName="-z-10 object-cover" resource={metaImage} />
<Media
fill
priority={false}
loading="lazy"
imgClassName="-z-10 object-cover"
resource={metaImage}
/>
)}
<div className="absolute pointer-events-none left-0 bottom-0 w-full h-1/2 bg-gradient-to-t from-black to-transparent" />
</div>

View File

@@ -40,7 +40,7 @@ export interface Config {
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
};
db: {
defaultIDType: string;
defaultIDType: number;
};
globals: {
header: Header;
@@ -82,7 +82,7 @@ export interface UserAuthOperations {
* via the `definition` "pages".
*/
export interface Page {
id: string;
id: number;
title: string;
hero: {
type: 'none' | 'highImpact' | 'mediumImpact' | 'lowImpact';
@@ -108,7 +108,7 @@ export interface Page {
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null;
url?: string | null;
label: string;
@@ -117,12 +117,12 @@ export interface Page {
id?: string | null;
}[]
| null;
media?: (string | null) | Media;
media?: (number | null) | Media;
};
layout: (CallToActionBlock | ContentBlock | MediaBlock | ArchiveBlock | FormBlock)[];
meta?: {
title?: string | null;
image?: (string | null) | Media;
image?: (number | null) | Media;
description?: string | null;
};
publishedAt?: string | null;
@@ -137,7 +137,7 @@ export interface Page {
* via the `definition` "media".
*/
export interface Media {
id: string;
id: number;
alt?: string | null;
caption?: {
root: {
@@ -243,7 +243,7 @@ export interface CallToActionBlock {
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null;
url?: string | null;
label: string;
@@ -285,7 +285,7 @@ export interface ContentBlock {
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null;
url?: string | null;
label: string;
@@ -303,7 +303,7 @@ export interface ContentBlock {
* via the `definition` "MediaBlock".
*/
export interface MediaBlock {
media: string | Media;
media: number | Media;
id?: string | null;
blockName?: string | null;
blockType: 'mediaBlock';
@@ -330,12 +330,12 @@ export interface ArchiveBlock {
} | null;
populateBy?: ('collection' | 'selection') | null;
relationTo?: 'posts' | null;
categories?: (string | Category)[] | null;
categories?: (number | Category)[] | null;
limit?: number | null;
selectedDocs?:
| {
relationTo: 'posts';
value: string | Post;
value: number | Post;
}[]
| null;
id?: string | null;
@@ -347,12 +347,12 @@ export interface ArchiveBlock {
* via the `definition` "categories".
*/
export interface Category {
id: string;
id: number;
title: string;
parent?: (string | null) | Category;
parent?: (number | null) | Category;
breadcrumbs?:
| {
doc?: (string | null) | Category;
doc?: (number | null) | Category;
url?: string | null;
label?: string | null;
id?: string | null;
@@ -366,7 +366,7 @@ export interface Category {
* via the `definition` "posts".
*/
export interface Post {
id: string;
id: number;
title: string;
content: {
root: {
@@ -383,15 +383,15 @@ export interface Post {
};
[k: string]: unknown;
};
relatedPosts?: (string | Post)[] | null;
categories?: (string | Category)[] | null;
relatedPosts?: (number | Post)[] | null;
categories?: (number | Category)[] | null;
meta?: {
title?: string | null;
image?: (string | null) | Media;
image?: (number | null) | Media;
description?: string | null;
};
publishedAt?: string | null;
authors?: (string | User)[] | null;
authors?: (number | User)[] | null;
populatedAuthors?:
| {
id?: string | null;
@@ -409,7 +409,7 @@ export interface Post {
* via the `definition` "users".
*/
export interface User {
id: string;
id: number;
name?: string | null;
updatedAt: string;
createdAt: string;
@@ -427,7 +427,7 @@ export interface User {
* via the `definition` "FormBlock".
*/
export interface FormBlock {
form: string | Form;
form: number | Form;
enableIntro?: boolean | null;
introContent?: {
root: {
@@ -453,7 +453,7 @@ export interface FormBlock {
* via the `definition` "forms".
*/
export interface Form {
id: string;
id: number;
title: string;
fields?:
| (
@@ -617,18 +617,18 @@ export interface Form {
* via the `definition` "redirects".
*/
export interface Redirect {
id: string;
id: number;
from: string;
to?: {
type?: ('reference' | 'custom') | null;
reference?:
| ({
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
value: number | Post;
} | null);
url?: string | null;
};
@@ -640,8 +640,8 @@ export interface Redirect {
* via the `definition` "form-submissions".
*/
export interface FormSubmission {
id: string;
form: string | Form;
id: number;
form: number | Form;
submissionData?:
| {
field: string;
@@ -657,18 +657,18 @@ export interface FormSubmission {
* via the `definition` "search".
*/
export interface Search {
id: string;
id: number;
title?: string | null;
priority?: number | null;
doc: {
relationTo: 'posts';
value: string | Post;
value: number | Post;
};
slug?: string | null;
meta?: {
title?: string | null;
description?: string | null;
image?: (string | null) | Media;
image?: (number | null) | Media;
};
categories?:
| {
@@ -685,48 +685,48 @@ export interface Search {
* via the `definition` "payload-locked-documents".
*/
export interface PayloadLockedDocument {
id: string;
id: number;
document?:
| ({
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null)
| ({
relationTo: 'posts';
value: string | Post;
value: number | Post;
} | null)
| ({
relationTo: 'media';
value: string | Media;
value: number | Media;
} | null)
| ({
relationTo: 'categories';
value: string | Category;
value: number | Category;
} | null)
| ({
relationTo: 'users';
value: string | User;
value: number | User;
} | null)
| ({
relationTo: 'redirects';
value: string | Redirect;
value: number | Redirect;
} | null)
| ({
relationTo: 'forms';
value: string | Form;
value: number | Form;
} | null)
| ({
relationTo: 'form-submissions';
value: string | FormSubmission;
value: number | FormSubmission;
} | null)
| ({
relationTo: 'search';
value: string | Search;
value: number | Search;
} | null);
globalSlug?: string | null;
user: {
relationTo: 'users';
value: string | User;
value: number | User;
};
updatedAt: string;
createdAt: string;
@@ -736,10 +736,10 @@ export interface PayloadLockedDocument {
* via the `definition` "payload-preferences".
*/
export interface PayloadPreference {
id: string;
id: number;
user: {
relationTo: 'users';
value: string | User;
value: number | User;
};
key?: string | null;
value?:
@@ -759,7 +759,7 @@ export interface PayloadPreference {
* via the `definition` "payload-migrations".
*/
export interface PayloadMigration {
id: string;
id: number;
name?: string | null;
batch?: number | null;
updatedAt: string;
@@ -874,11 +874,9 @@ export interface PagesSelect<T extends boolean = true> {
meta?:
| T
| {
overview?: T;
title?: T;
image?: T;
description?: T;
preview?: T;
};
publishedAt?: T;
slug?: T;
@@ -899,11 +897,9 @@ export interface PostsSelect<T extends boolean = true> {
meta?:
| T
| {
overview?: T;
title?: T;
image?: T;
description?: T;
preview?: T;
};
publishedAt?: T;
authors?: T;
@@ -1208,7 +1204,6 @@ export interface SearchSelect<T extends boolean = true> {
title?: T;
priority?: T;
doc?: T;
docUrl?: T;
slug?: T;
meta?:
| T
@@ -1264,7 +1259,7 @@ export interface PayloadMigrationsSelect<T extends boolean = true> {
* via the `definition` "header".
*/
export interface Header {
id: string;
id: number;
navItems?:
| {
link: {
@@ -1272,7 +1267,7 @@ export interface Header {
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null;
url?: string | null;
label: string;
@@ -1288,7 +1283,7 @@ export interface Header {
* via the `definition` "footer".
*/
export interface Footer {
id: string;
id: number;
navItems?:
| {
link: {
@@ -1296,7 +1291,7 @@ export interface Footer {
newTab?: boolean | null;
reference?: {
relationTo: 'pages';
value: string | Page;
value: number | Page;
} | null;
url?: string | null;
label: string;

View File

@@ -58,7 +58,7 @@ export default {
foreground: 'hsl(var(--accent-foreground))',
},
background: 'hsl(var(--background))',
border: 'hsl(var(--border))',
border: 'hsla(var(--border))',
card: {
DEFAULT: 'hsl(var(--card))',
foreground: 'hsl(var(--card-foreground))',
@@ -110,7 +110,7 @@ export default {
'--tw-prose-body': 'var(--text)',
'--tw-prose-headings': 'var(--text)',
h1: {
fontSize: '4rem',
fontSize: '3.5rem',
fontWeight: 'normal',
marginBottom: '0.25em',
},