1
+ import path from 'path'
2
+
1
3
export function createStructureCommands ( mainDirectory : string , structure : Array < string > ) : string {
2
4
const commands = structure . map ( name => {
3
5
if ( isFile ( name ) ) return fileCommand ( mainDirectory , name )
@@ -9,7 +11,7 @@ export function createStructureCommands(mainDirectory: string, structure: Array<
9
11
10
12
export function isSafeStructure ( structure : Array < string > ) : boolean {
11
13
return structure . every ( ( directoryOrFile : string ) : boolean => {
12
- return ! ( / \. { 2 , } / . test ( directoryOrFile ) )
14
+ return ! ( / \. { 2 , } / . test ( directoryOrFile ) ) || isFile ( directoryOrFile )
13
15
} )
14
16
}
15
17
@@ -18,11 +20,8 @@ export function wrapCommand(commands: string): string {
18
20
}
19
21
20
22
export function isFile ( name : string ) : boolean {
21
- const parts = name . split ( '.' )
22
- const filename = parts . shift ( )
23
- const extension = parts . pop ( )
24
-
25
- if ( ! filename ) return SPECIAL_DOT_FILES . includes ( extension )
23
+ const { name : filename , ext : extension } = path . parse ( name )
24
+ if ( ! extension && filename . startsWith ( '.' ) ) return SPECIAL_DOT_FILES . includes ( filename )
26
25
if ( ! extension ) return SPECIAL_FILES . includes ( filename )
27
26
if ( filename && extension ) return true
28
27
return false
@@ -38,10 +37,10 @@ function fileCommand(mainDirectory: string, filepath: string): string {
38
37
}
39
38
40
39
const SPECIAL_DOT_FILES : Array < string > = [
41
- 'gitignore' ,
42
- 'env' ,
43
- 'eslint' ,
44
- 'babelrc' ,
40
+ '. gitignore' ,
41
+ '. env' ,
42
+ '. eslint' ,
43
+ '. babelrc' ,
45
44
]
46
45
47
46
const SPECIAL_FILES : Array < string > = [
0 commit comments