Skip to content

Commit 7cd805a

Browse files
authored
fix(cpa): use proper branch tag (#9141)
The pinned git tag was not being threaded all the way through to where the download was occurring.
1 parent 48d0fae commit 7cd805a

File tree

4 files changed

+26
-44
lines changed

4 files changed

+26
-44
lines changed

packages/create-payload-app/src/lib/create-project.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,14 @@ export async function createProject(args: {
7878
)
7979
await fse.copy(localTemplate, projectDir)
8080
} else if ('url' in template) {
81-
let templateUrl = template.url
8281
if (cliArgs['--template-branch']) {
83-
templateUrl = `${template.url}#${cliArgs['--template-branch']}`
84-
debug(`Using template url: ${templateUrl}`)
82+
template.url = `${template.url.split('#')?.[0]}#${cliArgs['--template-branch']}`
8583
}
84+
8685
await downloadTemplate({
87-
name: template.name,
88-
branch: 'beta',
86+
debug: cliArgs['--debug'],
8987
projectDir,
88+
template,
9089
})
9190
}
9291

packages/create-payload-app/src/lib/download-template.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@ import { Readable } from 'node:stream'
22
import { pipeline } from 'node:stream/promises'
33
import { x } from 'tar'
44

5+
import type { ProjectTemplate } from '../types.js'
6+
7+
import { debug as debugLog } from '../utils/log.js'
8+
59
export async function downloadTemplate({
6-
name,
7-
branch,
10+
debug,
811
projectDir,
12+
template,
913
}: {
10-
branch: string
11-
/**
12-
* The name of the template to download
13-
* Must be dir /templates/<name>
14-
*/
15-
name: string
14+
debug?: boolean
1615
projectDir: string
16+
template: ProjectTemplate
1717
}) {
18-
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branch}`
19-
const filter = `payload-${branch}/templates/${name}/`
18+
const branchOrTag = template.url.split('#')?.[1] || 'beta'
19+
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branchOrTag}`
20+
const filter = `payload-${branchOrTag.replace(/^v/, '')}/templates/${template.name}/`
21+
22+
if (debug) {
23+
debugLog(`Using template url: ${template.url}`)
24+
debugLog(`Codeload url: ${url}`)
25+
debugLog(`Filter: ${filter}`)
26+
}
27+
2028
await pipeline(
2129
await downloadTarStream(url),
2230
x({
2331
cwd: projectDir,
2432
filter: (p) => p.includes(filter),
25-
strip: 2 + name.split('/').length,
33+
strip: 2 + template.name.split('/').length,
2634
}),
2735
)
2836
}

packages/create-payload-app/src/lib/templates.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function validateTemplate(templateName: string): boolean {
1414
}
1515

1616
export function getValidTemplates(): ProjectTemplate[] {
17+
// Starters _must_ be a valid template name from the templates/ directory
1718
return [
1819
{
1920
name: 'blank',
@@ -28,37 +29,11 @@ export function getValidTemplates(): ProjectTemplate[] {
2829
url: `https://github.com/payloadcms/payload/templates/website#v${PACKAGE_VERSION}`,
2930
},
3031

31-
// Remove these until they have been updated for 3.0
32-
33-
// {
34-
// name: 'blank',
35-
// type: 'starter',
36-
// description: 'Blank Template',
37-
// url: 'https://github.com/payloadcms/payload/templates/blank',
38-
// },
39-
// {
40-
// name: 'ecommerce',
41-
// type: 'starter',
42-
// description: 'E-commerce Template',
43-
// url: 'https://github.com/payloadcms/payload/templates/ecommerce',
44-
// },
4532
// {
4633
// name: 'plugin',
4734
// type: 'plugin',
4835
// description: 'Template for creating a Payload plugin',
49-
// url: 'https://github.com/payloadcms/payload-plugin-template#beta',
50-
// },
51-
// {
52-
// name: 'payload-demo',
53-
// type: 'starter',
54-
// description: 'Payload demo site at https://demo.payloadcms.com',
55-
// url: 'https://github.com/payloadcms/public-demo',
56-
// },
57-
// {
58-
// name: 'payload-website',
59-
// type: 'starter',
60-
// description: 'Payload website CMS at https://payloadcms.com',
61-
// url: 'https://github.com/payloadcms/website-cms',
36+
// url: 'https://github.com/payloadcms/plugin-template#beta',
6237
// },
6338
]
6439
}

packages/create-payload-app/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class Main {
205205
}
206206

207207
if (debugFlag) {
208-
debug(`Using templates from git tag: ${PACKAGE_VERSION}`)
208+
debug(`Using templates from git tag: v${PACKAGE_VERSION}`)
209209
}
210210

211211
const validTemplates = getValidTemplates()

0 commit comments

Comments
 (0)