Skip to content

Commit

Permalink
fix: create dst dir only after source successfully downloaded (resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 24, 2023
1 parent ab28a9f commit 1ef4ab9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/giget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 1ef4ab9

Please sign in to comment.