File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ module.exports = async (argvs) => {
23
23
const timer = elapsed . start ( ) ;
24
24
const version = ( argv [ "release" ] || "latest" ) . toString ( ) ;
25
25
const targetDir = path . resolve ( argv [ "_" ] [ 0 ] || "./" ) ;
26
+ const override = await checkFolder ( targetDir , argv ) ;
27
+ if ( ! override ) {
28
+ console . log ( chalk . red ( "Aborted" ) ) ;
29
+ return ;
30
+ }
26
31
spinner = ora (
27
32
`Downloading ${ packageName } version '${ version } ' to ${ targetDir } `
28
33
) . start ( ) ;
@@ -55,6 +60,26 @@ module.exports = async (argvs) => {
55
60
}
56
61
} ;
57
62
63
+ const checkFolder = async ( targetDir , argv ) => {
64
+ const folderExists = await fs . exists ( targetDir ) ;
65
+ if ( ! folderExists ) {
66
+ return true ;
67
+ }
68
+ if ( argv [ "yes" ] === true ) {
69
+ return true ;
70
+ }
71
+ const folderFiles = await fs . readdir ( targetDir ) ;
72
+ if ( folderFiles . length !== - 1 ) {
73
+ const { override } = await prompts ( {
74
+ type : "confirm" ,
75
+ name : "override" ,
76
+ message : `${ targetDir } is not an empty folder, proceed?` ,
77
+ initial : true ,
78
+ } ) ;
79
+ return override ;
80
+ }
81
+ } ;
82
+
58
83
const onLoad = async ( targetDir , version , argv ) => {
59
84
// see https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
60
85
const npmIgnoreFiles = await glob (
You can’t perform that action at this time.
0 commit comments