-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
826 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "space" | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"complexity": { | ||
"noForEach": "off" | ||
}, | ||
"correctness": { | ||
"noUnusedImports": "error", | ||
"noUnusedVariables": "error" | ||
} | ||
} | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"quoteStyle": "single" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ | |
"directory-validator": "dist/index.js" | ||
}, | ||
"scripts": { | ||
"dev": "npx tsx src/index.ts", | ||
"build": "npm run clean && tsc && cp src/resources/* dist/resources", | ||
"clean": "rm -rf dist", | ||
"prettier": "prettier -c .", | ||
"test": "npm run prettier && jest" | ||
"test": "jest" | ||
}, | ||
"author": "Erwin Gaitan O <[email protected]>", | ||
"license": "MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
type File = { | ||
type: 'file'; | ||
fullPath: string; | ||
path: string; | ||
}; | ||
|
||
type Directory = { | ||
type: 'dir'; | ||
fullPath: string; | ||
path: string; | ||
isEmpty: boolean; | ||
}; | ||
|
||
export function getFilesAndDirectories( | ||
dirPath: string, | ||
options: { | ||
recursive: boolean; | ||
_initialPath?: string; | ||
ignoreFilesAndDirectories?: string[]; | ||
} = { recursive: true }, | ||
): (File | Directory)[] { | ||
const items = fs.readdirSync(dirPath); | ||
options._initialPath = options._initialPath || dirPath; | ||
const lPath = path.relative(options._initialPath, dirPath); | ||
|
||
if (options.ignoreFilesAndDirectories?.includes(lPath)) return []; | ||
|
||
const result: (File | Directory)[] = [ | ||
{ | ||
type: 'dir', | ||
fullPath: dirPath, | ||
path: lPath, | ||
isEmpty: items.length === 0, | ||
}, | ||
]; | ||
|
||
for (const item of items) { | ||
const fullPath = path.join(dirPath, item); | ||
const itemStat = fs.statSync(fullPath); | ||
const localPath = path.relative(options._initialPath, fullPath); | ||
|
||
if (itemStat.isDirectory()) { | ||
if (!options.recursive) | ||
result.push({ type: 'dir', fullPath, path: localPath, isEmpty: false }); | ||
else result.push(...getFilesAndDirectories(fullPath, options)); | ||
} else { | ||
if (options.ignoreFilesAndDirectories?.includes(localPath)) continue; | ||
result.push({ type: 'file', fullPath, path: localPath }); | ||
} | ||
} | ||
|
||
return result; | ||
} |
Oops, something went wrong.