Skip to content

Commit ba63694

Browse files
committed
Add a cleanup step
1 parent b06f938 commit ba63694

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

index.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,27 @@ async function cloneExample() {
9595
const tmpDir = `examples-sparse-${timestamp}`;
9696
console.log(`\nCreating new project in ${dirName} ...`);
9797

98-
// Sparse clone the monorepo.
99-
await run(
100-
`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`
101-
);
102-
// Checkout just the example dir.
103-
await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`);
104-
// Copy out into a new directory within current working directory.
105-
await run(`cp -R ${tmpDir}/${args.example} ${dirName}`);
106-
// Delete the clone.
107-
await run(`rm -rf ${tmpDir}`);
108-
109-
// Project Setup
110-
await installDependencies();
111-
await initGit();
98+
try {
99+
// Sparse clone the monorepo.
100+
await run(
101+
`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`
102+
);
103+
// Checkout just the example dir.
104+
await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`);
105+
// Copy out into a new directory within current working directory.
106+
await run(`cp -R ${tmpDir}/${args.example} ${dirName}`);
107+
// Delete the clone.
108+
await run(`rm -rf ${tmpDir}`);
109+
110+
// Project Setup
111+
await installDependencies();
112+
await initGit();
113+
} catch (err) {
114+
console.error(err);
115+
if (fs.existsSync(dirName)) await run(`rm -rf ${dirName}`);
116+
if (fs.existsSync(tmpDir)) await run(`rm -rf ${tmpDir}`);
117+
process.exit(1);
118+
}
112119

113120
// Output next steps:
114121
console.log(`

0 commit comments

Comments
 (0)