Skip to content

Commit

Permalink
fix(cpa): use proper branch tag (#9141)
Browse files Browse the repository at this point in the history
The pinned git tag was not being threaded all the way through to where
the download was occurring.
  • Loading branch information
denolfe authored Nov 12, 2024
1 parent 48d0fae commit 7cd805a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 44 deletions.
9 changes: 4 additions & 5 deletions packages/create-payload-app/src/lib/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ export async function createProject(args: {
)
await fse.copy(localTemplate, projectDir)
} else if ('url' in template) {
let templateUrl = template.url
if (cliArgs['--template-branch']) {
templateUrl = `${template.url}#${cliArgs['--template-branch']}`
debug(`Using template url: ${templateUrl}`)
template.url = `${template.url.split('#')?.[0]}#${cliArgs['--template-branch']}`
}

await downloadTemplate({
name: template.name,
branch: 'beta',
debug: cliArgs['--debug'],
projectDir,
template,
})
}

Expand Down
30 changes: 19 additions & 11 deletions packages/create-payload-app/src/lib/download-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@ import { Readable } from 'node:stream'
import { pipeline } from 'node:stream/promises'
import { x } from 'tar'

import type { ProjectTemplate } from '../types.js'

import { debug as debugLog } from '../utils/log.js'

export async function downloadTemplate({
name,
branch,
debug,
projectDir,
template,
}: {
branch: string
/**
* The name of the template to download
* Must be dir /templates/<name>
*/
name: string
debug?: boolean
projectDir: string
template: ProjectTemplate
}) {
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branch}`
const filter = `payload-${branch}/templates/${name}/`
const branchOrTag = template.url.split('#')?.[1] || 'beta'
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branchOrTag}`
const filter = `payload-${branchOrTag.replace(/^v/, '')}/templates/${template.name}/`

if (debug) {
debugLog(`Using template url: ${template.url}`)
debugLog(`Codeload url: ${url}`)
debugLog(`Filter: ${filter}`)
}

await pipeline(
await downloadTarStream(url),
x({
cwd: projectDir,
filter: (p) => p.includes(filter),
strip: 2 + name.split('/').length,
strip: 2 + template.name.split('/').length,
}),
)
}
Expand Down
29 changes: 2 additions & 27 deletions packages/create-payload-app/src/lib/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function validateTemplate(templateName: string): boolean {
}

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

// Remove these until they have been updated for 3.0

// {
// name: 'blank',
// type: 'starter',
// description: 'Blank Template',
// url: 'https://github.com/payloadcms/payload/templates/blank',
// },
// {
// name: 'ecommerce',
// type: 'starter',
// description: 'E-commerce Template',
// url: 'https://github.com/payloadcms/payload/templates/ecommerce',
// },
// {
// name: 'plugin',
// type: 'plugin',
// description: 'Template for creating a Payload plugin',
// url: 'https://github.com/payloadcms/payload-plugin-template#beta',
// },
// {
// name: 'payload-demo',
// type: 'starter',
// description: 'Payload demo site at https://demo.payloadcms.com',
// url: 'https://github.com/payloadcms/public-demo',
// },
// {
// name: 'payload-website',
// type: 'starter',
// description: 'Payload website CMS at https://payloadcms.com',
// url: 'https://github.com/payloadcms/website-cms',
// url: 'https://github.com/payloadcms/plugin-template#beta',
// },
]
}
2 changes: 1 addition & 1 deletion packages/create-payload-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class Main {
}

if (debugFlag) {
debug(`Using templates from git tag: ${PACKAGE_VERSION}`)
debug(`Using templates from git tag: v${PACKAGE_VERSION}`)
}

const validTemplates = getValidTemplates()
Expand Down

0 comments on commit 7cd805a

Please sign in to comment.