Skip to content

Commit 0b21688

Browse files
authored
Merge pull request #20 from stackbit/hotfix-use-node-fs
Hotfix: use node fs-extra to handle copying and removing files #3hk00xt
2 parents a5be22c + d4e4b1b commit 0b21688

File tree

3 files changed

+78
-11
lines changed

3 files changed

+78
-11
lines changed

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import chalk from 'chalk';
44
import { exec } from 'child_process';
5-
import fs from 'fs';
5+
import fs from 'fs-extra';
66
import path from 'path';
77
import readline from 'readline';
88
import util from 'util';
@@ -39,10 +39,9 @@ async function installDependencies(dirName) {
3939

4040
async function initGit(dirName) {
4141
console.log(`Setting up Git ...`);
42-
await run(`rm -rf ${dirName}/.git`);
42+
fs.removeSync(`${dirName}/.git`);
4343
await run(`cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"`);
4444
}
45-
4645
/**
4746
* Given a version string, compare it to a control version. Returns:
4847
*
@@ -148,18 +147,18 @@ async function cloneExample() {
148147
await run(`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`);
149148
// Checkout just the example dir.
150149
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);
153152
// Delete the clone.
154-
await run(`rm -rf ${tmpDir}`);
153+
fs.removeSync(tmpDir);
155154

156155
// Project Setup
157156
await installDependencies(dirName);
158157
await initGit(dirName);
159158
} catch (err) {
160159
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);
163162
process.exit(1);
164163
}
165164

package-lock.json

Lines changed: 69 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-stackbit-app",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "Create a new Stackbit site, or add Stackbit to an existing site.",
55
"main": "index.js",
66
"scripts": {
@@ -15,6 +15,7 @@
1515
"type": "module",
1616
"dependencies": {
1717
"chalk": "^5.0.0",
18+
"fs-extra": "^10.1.0",
1819
"yargs": "^17.3.1"
1920
}
2021
}

0 commit comments

Comments
 (0)