From 1ef4ab9671e38386d2910df646f0aeffe5e77664 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 24 Dec 2023 21:32:20 +0100 Subject: [PATCH] fix: create dst dir only after source successfully downloaded (resolves #119) --- src/giget.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/giget.ts b/src/giget.ts index e507372..79b6e5e 100644 --- a/src/giget.ts +++ b/src/giget.ts @@ -85,20 +85,7 @@ export async function downloadTemplate( "-", ); - const cwd = resolve(options.cwd || "."); - const extractPath = resolve(cwd, options.dir || template.defaultDir); - if (options.forceClean) { - await rm(extractPath, { recursive: true, force: true }); - } - if ( - !options.force && - existsSync(extractPath) && - readdirSync(extractPath).length > 0 - ) { - throw new Error(`Destination ${extractPath} already exists.`); - } - await mkdir(extractPath, { recursive: true }); - + // Download template source const temporaryDirectory = resolve( cacheDirectory(), providerName, @@ -137,6 +124,21 @@ export async function downloadTemplate( ); } + // Extract template + const cwd = resolve(options.cwd || "."); + const extractPath = resolve(cwd, options.dir || template.defaultDir); + if (options.forceClean) { + await rm(extractPath, { recursive: true, force: true }); + } + if ( + !options.force && + existsSync(extractPath) && + readdirSync(extractPath).length > 0 + ) { + throw new Error(`Destination ${extractPath} already exists.`); + } + await mkdir(extractPath, { recursive: true }); + const s = Date.now(); const subdir = template.subdir?.replace(/^\//, "") || ""; await extract({