Skip to content

Commit 1ef4ab9

Browse files
committed
fix: create dst dir only after source successfully downloaded (resolves #119)
1 parent ab28a9f commit 1ef4ab9

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/giget.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,7 @@ export async function downloadTemplate(
8585
"-",
8686
);
8787

88-
const cwd = resolve(options.cwd || ".");
89-
const extractPath = resolve(cwd, options.dir || template.defaultDir);
90-
if (options.forceClean) {
91-
await rm(extractPath, { recursive: true, force: true });
92-
}
93-
if (
94-
!options.force &&
95-
existsSync(extractPath) &&
96-
readdirSync(extractPath).length > 0
97-
) {
98-
throw new Error(`Destination ${extractPath} already exists.`);
99-
}
100-
await mkdir(extractPath, { recursive: true });
101-
88+
// Download template source
10289
const temporaryDirectory = resolve(
10390
cacheDirectory(),
10491
providerName,
@@ -137,6 +124,21 @@ export async function downloadTemplate(
137124
);
138125
}
139126

127+
// Extract template
128+
const cwd = resolve(options.cwd || ".");
129+
const extractPath = resolve(cwd, options.dir || template.defaultDir);
130+
if (options.forceClean) {
131+
await rm(extractPath, { recursive: true, force: true });
132+
}
133+
if (
134+
!options.force &&
135+
existsSync(extractPath) &&
136+
readdirSync(extractPath).length > 0
137+
) {
138+
throw new Error(`Destination ${extractPath} already exists.`);
139+
}
140+
await mkdir(extractPath, { recursive: true });
141+
140142
const s = Date.now();
141143
const subdir = template.subdir?.replace(/^\//, "") || "";
142144
await extract({

0 commit comments

Comments
 (0)