Skip to content

Commit 840163a

Browse files
committed
fix repo deletion bug
1 parent 39e50bd commit 840163a

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

bin/setup.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require("path");
55
const fs = require("fs");
66
const readline = require("readline");
77
const compareVersions = require("compare-versions");
8-
// const shell = require("shelljs");
8+
const shell = require("shelljs");
99
// const chalk = require("chalk");
1010

1111
const npmConfig = require("./helpers/get_npm_config.js");
@@ -23,16 +23,32 @@ function deleteFileInCurrentDir(file) {
2323
});
2424
}
2525

26-
function removeGitRepository() {
26+
function hasGitRepository() {
2727
return new Promise((resolve, reject) => {
28-
exec("rm -rf .git/", (error) => {
29-
if (error) reject(new Error(error));
28+
exec("git status", (err, stdout) => {
29+
if (err) {
30+
reject(new Error(err));
31+
}
3032

31-
resolve();
33+
const regex = new RegExp(/fatal:\s+Not\s+a\s+git\s+repository/, "i");
34+
35+
/* eslint-disable-next-line no-unused-expressions */
36+
regex.test(stdout) ? resolve(false) : resolve(true);
3237
});
3338
});
3439
}
3540

41+
function removeGitRepository() {
42+
return new Promise((resolve, reject) => {
43+
try {
44+
shell.rm("-rf", ".git/");
45+
resolve();
46+
} catch (err) {
47+
reject(err);
48+
}
49+
});
50+
}
51+
3652
function askUserIfWeShouldRemoveRepo() {
3753
return new Promise((resolve) => {
3854
process.stdout.write(
@@ -177,7 +193,8 @@ function reportError(error) {
177193

178194
if (error) {
179195
process.stdout.write("\n\n");
180-
addXMark(() => process.stderr.write(chalk.red(` ${error}\n`)));
196+
process.stderr.write(` ${error}\n`);
197+
// addXMark(() => process.stderr.write(chalk.red(` ${error}\n`)));
181198
process.exit(1);
182199
}
183200
}

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "1.0.0",
44
"description": "React + Webpack 5 + SCSS + Jest/RTL",
55
"main": "index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/ilyasudakov/basic-react-boilerplate.git"
9+
},
610
"scripts": {
711
"start": "webpack serve",
812
"build": "webpack",
@@ -36,11 +40,16 @@
3640
"webpack-cli": "^4.5.0",
3741
"webpack-dev-server": "^3.11.2"
3842
},
43+
"engines": {
44+
"npm": ">=5",
45+
"node": ">=8.15.1"
46+
},
3947
"dependencies": {
4048
"compare-versions": "^3.6.0",
4149
"dotenv": "^8.2.0",
4250
"prop-types": "^15.7.2",
4351
"react": "^17.0.1",
44-
"react-dom": "^17.0.1"
52+
"react-dom": "^17.0.1",
53+
"shelljs": "^0.8.4"
4554
}
4655
}

0 commit comments

Comments
 (0)