-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: perform sanity check in watch mode
- Loading branch information
Showing
3 changed files
with
41 additions
and
14 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,33 @@ | ||
import glob from "glob"; | ||
|
||
import { alerts } from "./alerts"; | ||
import { ConfigOptions } from "./types"; | ||
|
||
/** | ||
* Return the files matching the given pattern and alert the user if only 0 or 1 | ||
* files matched. | ||
* | ||
* @param pattern the file pattern to generate type definitions for | ||
* @param options the CLI options | ||
*/ | ||
export function listFilesAndPerformSanityChecks( | ||
pattern: string, | ||
options: ConfigOptions | ||
): string[] { | ||
// Find all the files that match the provided pattern. | ||
const files = glob.sync(pattern, { ignore: options.ignore }); | ||
|
||
if (!files || !files.length) { | ||
alerts.error("No files found."); | ||
} | ||
|
||
// This case still works as expected but it's easy to do on accident so | ||
// provide a (hopefully) helpful warning. | ||
if (files.length === 1) { | ||
alerts.warn( | ||
`Only 1 file found for ${pattern}. If using a glob pattern (eg: dir/**/*.scss) make sure to wrap in quotes (eg: "dir/**/*.scss").` | ||
); | ||
} | ||
|
||
return files; | ||
} |
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