|
2 | 2 |
|
3 | 3 | import chalk from 'chalk';
|
4 | 4 | import { exec } from 'child_process';
|
5 |
| -import fs from 'fs'; |
| 5 | +import fs from 'fs-extra'; |
6 | 6 | import path from 'path';
|
7 | 7 | import readline from 'readline';
|
8 | 8 | import util from 'util';
|
@@ -39,10 +39,9 @@ async function installDependencies(dirName) {
|
39 | 39 |
|
40 | 40 | async function initGit(dirName) {
|
41 | 41 | console.log(`Setting up Git ...`);
|
42 |
| - await run(`rm -rf ${dirName}/.git`); |
| 42 | + fs.removeSync(`${dirName}/.git`); |
43 | 43 | await run(`cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"`);
|
44 | 44 | }
|
45 |
| - |
46 | 45 | /**
|
47 | 46 | * Given a version string, compare it to a control version. Returns:
|
48 | 47 | *
|
@@ -148,18 +147,18 @@ async function cloneExample() {
|
148 | 147 | await run(`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`);
|
149 | 148 | // Checkout just the example dir.
|
150 | 149 | await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`);
|
151 |
| - // Copy out into a new directory within current working directory. |
152 |
| - await run(`cp -R ${tmpDir}/${args.example} ${dirName}`); |
| 150 | + // move out into a new directory. |
| 151 | + fs.moveSync(`${tmpDir}/${args.example}`, dirName); |
153 | 152 | // Delete the clone.
|
154 |
| - await run(`rm -rf ${tmpDir}`); |
| 153 | + fs.removeSync(tmpDir); |
155 | 154 |
|
156 | 155 | // Project Setup
|
157 | 156 | await installDependencies(dirName);
|
158 | 157 | await initGit(dirName);
|
159 | 158 | } catch (err) {
|
160 | 159 | console.error(err);
|
161 |
| - if (fs.existsSync(dirName)) await run(`rm -rf ${dirName}`); |
162 |
| - if (fs.existsSync(tmpDir)) await run(`rm -rf ${tmpDir}`); |
| 160 | + if (fs.existsSync(dirName)) fs.removeSync(dirName); |
| 161 | + if (fs.existsSync(tmpDir)) fs.removeSync(tmpDir); |
163 | 162 | process.exit(1);
|
164 | 163 | }
|
165 | 164 |
|
|
0 commit comments