MCPcopy
hub / github.com/tldraw/tldraw / downloadTemplate

Function downloadTemplate

packages/create-tldraw/src/main.ts:168–199  ·  view source on GitHub ↗
(template: Template, targetDir: string)

Source from the content-addressed store, hash-verified

166}
167
168async function downloadTemplate(template: Template, targetDir: string) {
169 const s = spinner()
170 s.start(`Downloading github.com/${template.repo}...`)
171 try {
172 const url = `https://github.com/${template.repo}/archive/refs/heads/main.tar.gz`
173 const tarResponse = await fetch(url)
174 if (!tarResponse.ok) {
175 throw new Error(`${url}: ${tarResponse.status} ${tarResponse.statusText}`)
176 }
177
178 if (!tarResponse.body) {
179 throw new Error(`${url}: no body`)
180 }
181
182 const extractor = tar.extract({
183 cwd: targetDir,
184 strip: 1,
185 })
186
187 await new Promise<void>((resolve, reject) => {
188 Readable.fromWeb(tarResponse.body as any)
189 .pipe(extractor)
190 .on('end', resolve)
191 .on('error', reject)
192 })
193
194 s.stop(`Downloaded github.com/${template.repo}`)
195 } catch (err) {
196 s.stop(`Failed to download github.com/${template.repo}`)
197 throw err
198 }
199}
200
201async function renameTemplate(name: string, targetDir: string) {
202 const packageJson = JSON.parse(readFileSync(resolve(targetDir, 'package.json'), 'utf-8'))

Callers 1

mainFunction · 0.85

Calls 4

onMethod · 0.80
startMethod · 0.65
stopMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…