Skip to content

Commit a7986f6

Browse files
authored
Merge pull request #29 from thiagosf/fix/is-file-function
fix: change way to check isFile
2 parents b424656 + 008049b commit a7986f6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

app/__tests__/helpers/bash_utils.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ describe('bash_utils', () => {
3737
expect(isSafeStructure(['dir/other'])).toEqual(true)
3838
expect(isSafeStructure(['dir', '.git'])).toEqual(true)
3939
expect(isSafeStructure(['.git'])).toEqual(true)
40+
expect(isSafeStructure(['auth', '[...nextauth].ts'])).toEqual(true)
41+
expect(isSafeStructure(['auth', '[...nextauth.ts]'])).toEqual(true)
4042
})
4143
})
4244
})

app/helpers/bash_utils.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path'
2+
13
export function createStructureCommands(mainDirectory: string, structure: Array<string>): string {
24
const commands = structure.map(name => {
35
if (isFile(name)) return fileCommand(mainDirectory, name)
@@ -9,7 +11,7 @@ export function createStructureCommands(mainDirectory: string, structure: Array<
911

1012
export function isSafeStructure(structure: Array<string>): boolean {
1113
return structure.every((directoryOrFile: string): boolean => {
12-
return !(/\.{2,}/.test(directoryOrFile))
14+
return !(/\.{2,}/.test(directoryOrFile)) || isFile(directoryOrFile)
1315
})
1416
}
1517

@@ -18,11 +20,8 @@ export function wrapCommand(commands: string): string {
1820
}
1921

2022
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)
2625
if (!extension) return SPECIAL_FILES.includes(filename)
2726
if (filename && extension) return true
2827
return false
@@ -38,10 +37,10 @@ function fileCommand(mainDirectory: string, filepath: string): string {
3837
}
3938

4039
const SPECIAL_DOT_FILES: Array<string> = [
41-
'gitignore',
42-
'env',
43-
'eslint',
44-
'babelrc',
40+
'.gitignore',
41+
'.env',
42+
'.eslint',
43+
'.babelrc',
4544
]
4645

4746
const SPECIAL_FILES: Array<string> = [

0 commit comments

Comments
 (0)