Skip to content

Commit

Permalink
chore(scripts): fix generate template variations script (#9671)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpopus authored Dec 2, 2024
1 parent 0dbfc23 commit 5b3079a
Show file tree
Hide file tree
Showing 16 changed files with 358 additions and 343 deletions.
1 change: 0 additions & 1 deletion .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 29 additions & 15 deletions scripts/generate-template-variations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type TemplateVariations = {
envNames?: {
dbUri: string
}
/**
* @default false
*/
skipReadme?: boolean
configureConfig?: boolean
generateLockfile?: boolean
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -151,6 +156,7 @@ async function main() {
envNames,
sharp,
configureConfig,
skipReadme = false,
} of variations) {
header(`Generating ${name}...`)
const destDir = path.join(templatesDir, dirname)
Expand All @@ -160,6 +166,7 @@ async function main() {
'.next',
'.env$',
'pnpm-lock.yaml',
...(skipReadme ? ['README.md'] : ['']),
])

log(`Copied to ${destDir}`)
Expand All @@ -183,15 +190,26 @@ async function main() {
})
}

await generateReadme({
destDir,
data: {
name,
description: name, // TODO: Add descriptions
attributes: { db, storage },
...(vercelDeployButtonLink && { vercelDeployButtonLink }),
},
})
if (!skipReadme) {
await generateReadme({
destDir,
data: {
name,
description: name, // TODO: Add descriptions
attributes: { db, storage },
...(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') {
Expand All @@ -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?
Expand Down Expand Up @@ -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()
Expand Down
518 changes: 262 additions & 256 deletions templates/website/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions templates/website/src/app/(frontend)/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function generateStaticParams() {
draft: false,
limit: 1000,
overrideAccess: false,
pagination: false,
select: {
slug: true,
},
Expand Down
1 change: 1 addition & 0 deletions templates/website/src/app/(frontend)/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function generateStaticParams() {
draft: false,
limit: 1000,
overrideAccess: false,
pagination: false,
select: {
slug: true,
},
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/collections/Pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions templates/website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1208,7 +1204,6 @@ export interface SearchSelect<T extends boolean = true> {
title?: T;
priority?: T;
doc?: T;
docUrl?: T;
slug?: T;
meta?:
| T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export async function generateStaticParams() {
collection: 'posts',
draft: false,
limit: 1000,
pagination: false,
overrideAccess: false,
select: {
slug: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
Expand Down
8 changes: 7 additions & 1 deletion templates/with-vercel-website/src/heros/PostHero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Loading

0 comments on commit 5b3079a

Please sign in to comment.