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.
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
@@ -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',
|
||||
// },
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user