gistajs 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.cjs +30 -2
- package/dist/index.js +31 -2
- package/package.json +1 -1
package/dist/bin.cjs
CHANGED
|
@@ -204,7 +204,7 @@ async function createProject(starter, options) {
|
|
|
204
204
|
await extractStarter(archivePath, extractRoot);
|
|
205
205
|
let extracted = await findExtractedRoot(extractRoot);
|
|
206
206
|
await assertSafeProjectRoot(root);
|
|
207
|
-
await (
|
|
207
|
+
await copyProject(extracted, root);
|
|
208
208
|
await rewritePackageName(root, (0, import_node_path.basename)(root));
|
|
209
209
|
if (options.git !== false) {
|
|
210
210
|
await initGit(root, starter);
|
|
@@ -214,7 +214,7 @@ async function createProject(starter, options) {
|
|
|
214
214
|
}
|
|
215
215
|
return root;
|
|
216
216
|
} finally {
|
|
217
|
-
await (
|
|
217
|
+
await cleanupStaging(staging);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
function getStarterTarballUrl(starter) {
|
|
@@ -266,6 +266,34 @@ async function rewritePackageName(root, projectName) {
|
|
|
266
266
|
`);
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
+
async function copyProject(source, destination) {
|
|
270
|
+
try {
|
|
271
|
+
await (0, import_promises2.rename)(source, destination);
|
|
272
|
+
return;
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (!shouldFallbackToCopy(error)) throw error;
|
|
275
|
+
}
|
|
276
|
+
await (0, import_promises2.cp)(source, destination, {
|
|
277
|
+
recursive: true,
|
|
278
|
+
force: false,
|
|
279
|
+
errorOnExist: true
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function shouldFallbackToCopy(error) {
|
|
283
|
+
let code = error?.code;
|
|
284
|
+
return code === "EXDEV" || code === "EPERM" || code === "ENOTEMPTY";
|
|
285
|
+
}
|
|
286
|
+
async function cleanupStaging(root) {
|
|
287
|
+
try {
|
|
288
|
+
await (0, import_promises2.rm)(root, {
|
|
289
|
+
recursive: true,
|
|
290
|
+
force: true,
|
|
291
|
+
maxRetries: 5,
|
|
292
|
+
retryDelay: 100
|
|
293
|
+
});
|
|
294
|
+
} catch {
|
|
295
|
+
}
|
|
296
|
+
}
|
|
269
297
|
async function assertEmptyTarget(root) {
|
|
270
298
|
try {
|
|
271
299
|
await (0, import_promises2.stat)(root);
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ function parseStarter(data) {
|
|
|
33
33
|
|
|
34
34
|
// src/create.ts
|
|
35
35
|
import {
|
|
36
|
+
cp,
|
|
36
37
|
mkdtemp,
|
|
37
38
|
mkdir,
|
|
38
39
|
readdir,
|
|
@@ -188,7 +189,7 @@ async function createProject(starter, options) {
|
|
|
188
189
|
await extractStarter(archivePath, extractRoot);
|
|
189
190
|
let extracted = await findExtractedRoot(extractRoot);
|
|
190
191
|
await assertSafeProjectRoot(root);
|
|
191
|
-
await
|
|
192
|
+
await copyProject(extracted, root);
|
|
192
193
|
await rewritePackageName(root, basename(root));
|
|
193
194
|
if (options.git !== false) {
|
|
194
195
|
await initGit(root, starter);
|
|
@@ -198,7 +199,7 @@ async function createProject(starter, options) {
|
|
|
198
199
|
}
|
|
199
200
|
return root;
|
|
200
201
|
} finally {
|
|
201
|
-
await
|
|
202
|
+
await cleanupStaging(staging);
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
function getStarterTarballUrl(starter) {
|
|
@@ -250,6 +251,34 @@ async function rewritePackageName(root, projectName) {
|
|
|
250
251
|
`);
|
|
251
252
|
}
|
|
252
253
|
}
|
|
254
|
+
async function copyProject(source, destination) {
|
|
255
|
+
try {
|
|
256
|
+
await rename(source, destination);
|
|
257
|
+
return;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (!shouldFallbackToCopy(error)) throw error;
|
|
260
|
+
}
|
|
261
|
+
await cp(source, destination, {
|
|
262
|
+
recursive: true,
|
|
263
|
+
force: false,
|
|
264
|
+
errorOnExist: true
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function shouldFallbackToCopy(error) {
|
|
268
|
+
let code = error?.code;
|
|
269
|
+
return code === "EXDEV" || code === "EPERM" || code === "ENOTEMPTY";
|
|
270
|
+
}
|
|
271
|
+
async function cleanupStaging(root) {
|
|
272
|
+
try {
|
|
273
|
+
await rm(root, {
|
|
274
|
+
recursive: true,
|
|
275
|
+
force: true,
|
|
276
|
+
maxRetries: 5,
|
|
277
|
+
retryDelay: 100
|
|
278
|
+
});
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
281
|
+
}
|
|
253
282
|
async function assertEmptyTarget(root) {
|
|
254
283
|
try {
|
|
255
284
|
await stat(root);
|