Skip to content

Commit 5b3079a

Browse files
authored
chore(scripts): fix generate template variations script (#9671)
1 parent 0dbfc23 commit 5b3079a

File tree

16 files changed

+358
-343
lines changed

16 files changed

+358
-343
lines changed

.github/workflows/post-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
avatar_url: 'https://l4wlsi8vxy8hre4v.public.blob.vercel-storage.com/discord-bot-logo.png'
5353

5454
update_templates:
55-
if: false # Still needs some troubleshooting
5655
runs-on: ubuntu-latest
5756
permissions:
5857
contents: write

scripts/generate-template-variations.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type TemplateVariations = {
3636
envNames?: {
3737
dbUri: string
3838
}
39+
/**
40+
* @default false
41+
*/
42+
skipReadme?: boolean
3943
configureConfig?: boolean
4044
generateLockfile?: boolean
4145
}
@@ -92,6 +96,7 @@ async function main() {
9296
// This will replace the process.env.DATABASE_URI to process.env.POSTGRES_URL
9397
dbUri: 'POSTGRES_URL',
9498
},
99+
skipReadme: true,
95100
},
96101
{
97102
name: 'payload-postgres-template',
@@ -151,6 +156,7 @@ async function main() {
151156
envNames,
152157
sharp,
153158
configureConfig,
159+
skipReadme = false,
154160
} of variations) {
155161
header(`Generating ${name}...`)
156162
const destDir = path.join(templatesDir, dirname)
@@ -160,6 +166,7 @@ async function main() {
160166
'.next',
161167
'.env$',
162168
'pnpm-lock.yaml',
169+
...(skipReadme ? ['README.md'] : ['']),
163170
])
164171

165172
log(`Copied to ${destDir}`)
@@ -183,15 +190,26 @@ async function main() {
183190
})
184191
}
185192

186-
await generateReadme({
187-
destDir,
188-
data: {
189-
name,
190-
description: name, // TODO: Add descriptions
191-
attributes: { db, storage },
192-
...(vercelDeployButtonLink && { vercelDeployButtonLink }),
193-
},
194-
})
193+
if (!skipReadme) {
194+
await generateReadme({
195+
destDir,
196+
data: {
197+
name,
198+
description: name, // TODO: Add descriptions
199+
attributes: { db, storage },
200+
...(vercelDeployButtonLink && { vercelDeployButtonLink }),
201+
},
202+
})
203+
}
204+
205+
if (generateLockfile) {
206+
log('Generating pnpm-lock.yaml')
207+
execSyncSafe(`pnpm install --ignore-workspace`, { cwd: destDir })
208+
} else {
209+
log('Installing dependencies without generating lockfile')
210+
execSyncSafe(`pnpm install --ignore-workspace`, { cwd: destDir })
211+
await fs.rm(`${destDir}/pnpm-lock.yaml`, { force: true })
212+
}
195213

196214
// Copy in initial migration if db is postgres. This contains user and media.
197215
if (db === 'postgres' || db === 'vercel-postgres') {
@@ -214,17 +232,13 @@ async function main() {
214232
cwd: destDir,
215233
env: {
216234
...process.env,
235+
PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit',
217236
BLOB_READ_WRITE_TOKEN: 'vercel_blob_rw_TEST_asdf',
218237
DATABASE_URI: 'postgres://localhost:5432/payloadtests',
219238
},
220239
})
221240
}
222241

223-
if (generateLockfile) {
224-
log('Generating pnpm-lock.yaml')
225-
execSyncSafe(`pnpm install --ignore-workspace`, { cwd: destDir })
226-
}
227-
228242
// TODO: Email?
229243

230244
// TODO: Sharp?
@@ -302,7 +316,7 @@ function log(message: string) {
302316
function execSyncSafe(command: string, options?: Parameters<typeof execSync>[1]) {
303317
try {
304318
console.log(`Executing: ${command}`)
305-
execSync(command, options)
319+
execSync(command, { stdio: 'inherit', ...options })
306320
} catch (error) {
307321
if (error instanceof Error) {
308322
const stderr = (error as any).stderr?.toString()

templates/website/pnpm-lock.yaml

Lines changed: 262 additions & 256 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/website/src/app/(frontend)/[slug]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function generateStaticParams() {
2121
draft: false,
2222
limit: 1000,
2323
overrideAccess: false,
24+
pagination: false,
2425
select: {
2526
slug: true,
2627
},

templates/website/src/app/(frontend)/posts/[slug]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function generateStaticParams() {
2121
draft: false,
2222
limit: 1000,
2323
overrideAccess: false,
24+
pagination: false,
2425
select: {
2526
slug: true,
2627
},

templates/website/src/collections/Pages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const Pages: CollectionConfig<'pages'> = {
3232
},
3333
// This config controls what's populated by default when a page is referenced
3434
// https://payloadcms.com/docs/queries/select#defaultpopulate-collection-config-property
35-
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pagess'>
35+
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pages'>
3636
defaultPopulate: {
3737
title: true,
3838
slug: true,

templates/website/src/payload-types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,9 @@ export interface PagesSelect<T extends boolean = true> {
874874
meta?:
875875
| T
876876
| {
877-
overview?: T;
878877
title?: T;
879878
image?: T;
880879
description?: T;
881-
preview?: T;
882880
};
883881
publishedAt?: T;
884882
slug?: T;
@@ -899,11 +897,9 @@ export interface PostsSelect<T extends boolean = true> {
899897
meta?:
900898
| T
901899
| {
902-
overview?: T;
903900
title?: T;
904901
image?: T;
905902
description?: T;
906-
preview?: T;
907903
};
908904
publishedAt?: T;
909905
authors?: T;
@@ -1208,7 +1204,6 @@ export interface SearchSelect<T extends boolean = true> {
12081204
title?: T;
12091205
priority?: T;
12101206
doc?: T;
1211-
docUrl?: T;
12121207
slug?: T;
12131208
meta?:
12141209
| T

templates/with-vercel-website/src/app/(frontend)/[slug]/page.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default async function Page({ params: paramsPromise }: Args) {
4848
const { slug = 'home' } = await paramsPromise
4949
const url = '/' + slug
5050

51-
let page: Pick<PageType, 'slug' | 'layout' | 'hero'> | null
51+
let page: PageType | null
5252

5353
page = await queryPageBySlug({
5454
slug,
@@ -97,11 +97,6 @@ const queryPageBySlug = cache(async ({ slug }: { slug: string }) => {
9797
limit: 1,
9898
pagination: false,
9999
overrideAccess: draft,
100-
select: {
101-
slug: true,
102-
hero: true,
103-
layout: true,
104-
},
105100
where: {
106101
slug: {
107102
equals: slug,

templates/with-vercel-website/src/app/(frontend)/next/preview/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export async function GET(
7070
collection,
7171
draft: true,
7272
limit: 1,
73+
// pagination: false reduces overhead if you don't need totalDocs
7374
pagination: false,
7475
depth: 0,
7576
select: {},

templates/with-vercel-website/src/app/(frontend)/posts/[slug]/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export async function generateStaticParams() {
2020
collection: 'posts',
2121
draft: false,
2222
limit: 1000,
23-
pagination: false,
2423
overrideAccess: false,
2524
select: {
2625
slug: true,

templates/with-vercel-website/src/app/(payload)/admin/importMap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { SlugComponent as SlugComponent_92cc057d0a2abb4f6cf0307edf59f986 } from
1717
import { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
1818
import { BlocksFeatureClient as BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
1919
import { LinkToDoc as LinkToDoc_aead06e4cbf6b2620c5c51c9ab283634 } from '@payloadcms/plugin-search/client'
20+
import { ReindexButton as ReindexButton_aead06e4cbf6b2620c5c51c9ab283634 } from '@payloadcms/plugin-search/client'
2021
import { default as default_1a7510af427896d367a49dbf838d2de6 } from '@/components/BeforeDashboard'
2122
import { default as default_8a7ab0eb7ab5c511aba12e68480bfe5e } from '@/components/BeforeLogin'
2223

@@ -57,6 +58,7 @@ export const importMap = {
5758
'@payloadcms/richtext-lexical/client#BlocksFeatureClient':
5859
BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
5960
'@payloadcms/plugin-search/client#LinkToDoc': LinkToDoc_aead06e4cbf6b2620c5c51c9ab283634,
61+
'@payloadcms/plugin-search/client#ReindexButton': ReindexButton_aead06e4cbf6b2620c5c51c9ab283634,
6062
'@/components/BeforeDashboard#default': default_1a7510af427896d367a49dbf838d2de6,
6163
'@/components/BeforeLogin#default': default_8a7ab0eb7ab5c511aba12e68480bfe5e,
6264
}

templates/with-vercel-website/src/collections/Pages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const Pages: CollectionConfig<'pages'> = {
3232
},
3333
// This config controls what's populated by default when a page is referenced
3434
// https://payloadcms.com/docs/queries/select#defaultpopulate-collection-config-property
35-
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pages'>
35+
// Type safe if the collection slug generic is passed to `CollectionConfig` - `CollectionConfig<'pagess'>
3636
defaultPopulate: {
3737
title: true,
3838
slug: true,

templates/with-vercel-website/src/heros/MediumImpact/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export const MediumImpactHero: React.FC<Page['hero']> = ({ links, media, richTex
3030
<Media
3131
className="-mx-4 md:-mx-8 2xl:-mx-16"
3232
imgClassName=""
33-
priority
33+
priority={false}
34+
loading="lazy"
3435
resource={media}
3536
/>
3637
{media?.caption && (

templates/with-vercel-website/src/heros/PostHero/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ export const PostHero: React.FC<{
7979
</div>
8080
<div className="min-h-[80vh] select-none">
8181
{metaImage && typeof metaImage !== 'string' && (
82-
<Media fill imgClassName="-z-10 object-cover" resource={metaImage} />
82+
<Media
83+
fill
84+
priority={false}
85+
loading="lazy"
86+
imgClassName="-z-10 object-cover"
87+
resource={metaImage}
88+
/>
8389
)}
8490
<div className="absolute pointer-events-none left-0 bottom-0 w-full h-1/2 bg-gradient-to-t from-black to-transparent" />
8591
</div>

0 commit comments

Comments
 (0)