-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract include and exclude logic to utils
The logic for determining the include and exclude files for the package has been extracted into separate utility functions. This makes the code in bin.ts cleaner and more maintainable. The utility functions are getInclude and getExclude, both of which take the package JSON as an argument.
- Loading branch information
Showing
2 changed files
with
32 additions
and
19 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,29 @@ | ||
import typia from 'typia'; | ||
import type { PackageJson } from 'pkg-types'; | ||
import { parse } from 'pathe'; | ||
|
||
const isStartWithExclamation = typia.createIs<`!${string}`>(); | ||
|
||
export function getInclude(pkgJSON: PackageJson): string[] | undefined { | ||
const { files } = pkgJSON; | ||
const include = files == null ? ['dist'] : files.filter(file => isStartWithExclamation(file)); | ||
return include; | ||
} | ||
|
||
export function getExclude(pkgJSON: PackageJson): string[] | undefined { | ||
const { files } = pkgJSON; | ||
const exclude = files == null | ||
? undefined | ||
: files | ||
.filter(file => !isStartWithExclamation(file)) | ||
.map((file) => { | ||
if (file.startsWith('!**/')) { | ||
return file.slice(4); | ||
} | ||
if (file.startsWith('!')) { | ||
return file.slice(1); | ||
} | ||
return file; | ||
}); | ||
return exclude; | ||
} |