chore(cpa): get templates using tar (#8006)
Remove `degit` in favor of tar files from codeload. Degit is rather dated and has unfixed bugs such as #5402 and #7463 .
This commit is contained in:
@@ -56,16 +56,15 @@
|
||||
"arg": "^5.0.0",
|
||||
"chalk": "^4.1.0",
|
||||
"comment-json": "^4.2.3",
|
||||
"degit": "^2.8.4",
|
||||
"esprima-next": "^6.0.3",
|
||||
"execa": "^5.0.0",
|
||||
"figures": "^6.1.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"globby": "11.1.0",
|
||||
"tar": "^7.4.3",
|
||||
"terminal-link": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/degit": "^2.8.3",
|
||||
"@types/esprima": "^4.0.6",
|
||||
"@types/fs-extra": "^9.0.12",
|
||||
"@types/jest": "29.5.12",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import * as p from '@clack/prompts'
|
||||
import chalk from 'chalk'
|
||||
import degit from 'degit'
|
||||
import execa from 'execa'
|
||||
import fse from 'fs-extra'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
@@ -11,6 +10,7 @@ import type { CliArgs, DbDetails, PackageManager, ProjectTemplate } from '../typ
|
||||
import { tryInitRepoAndCommit } from '../utils/git.js'
|
||||
import { debug, error, info, warning } from '../utils/log.js'
|
||||
import { configurePayloadConfig } from './configure-payload-config.js'
|
||||
import { downloadTemplate } from './download-template.js'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
@@ -81,8 +81,11 @@ export async function createProject(args: {
|
||||
templateUrl = `${template.url}#${cliArgs['--template-branch']}`
|
||||
debug(`Using template url: ${templateUrl}`)
|
||||
}
|
||||
const emitter = degit(templateUrl)
|
||||
await emitter.clone(projectDir)
|
||||
await downloadTemplate({
|
||||
name: template.name,
|
||||
branch: 'beta',
|
||||
projectDir,
|
||||
})
|
||||
}
|
||||
|
||||
const spinner = p.spinner()
|
||||
|
||||
38
packages/create-payload-app/src/lib/download-template.ts
Normal file
38
packages/create-payload-app/src/lib/download-template.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Readable } from 'node:stream'
|
||||
import { pipeline } from 'node:stream/promises'
|
||||
import { x } from 'tar'
|
||||
|
||||
export async function downloadTemplate({
|
||||
name,
|
||||
branch,
|
||||
projectDir,
|
||||
}: {
|
||||
branch: string
|
||||
/**
|
||||
* The name of the template to download
|
||||
* Must be dir /templates/<name>
|
||||
*/
|
||||
name: string
|
||||
projectDir: string
|
||||
}) {
|
||||
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branch}`
|
||||
const filter = `payload-${branch}/templates/${name}/`
|
||||
await pipeline(
|
||||
await downloadTarStream(url),
|
||||
x({
|
||||
cwd: projectDir,
|
||||
filter: (p) => p.includes(filter),
|
||||
strip: 2 + name.split('/').length,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async function downloadTarStream(url: string) {
|
||||
const res = await fetch(url)
|
||||
|
||||
if (!res.body) {
|
||||
throw new Error(`Failed to download: ${url}`)
|
||||
}
|
||||
|
||||
return Readable.from(res.body as unknown as NodeJS.ReadableStream)
|
||||
}
|
||||
9208
pnpm-lock.yaml
generated
9208
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user