Merge remote-tracking branch 'upstream/main' into aeisenberg/fix-config-files

This commit is contained in:
Andrew Eisenberg
2022-08-11 09:57:45 -07:00
73 changed files with 4750 additions and 246 deletions

View File

@@ -780,3 +780,34 @@ export async function useCodeScanningConfigInCli(
(await codeQlVersionAbove(codeql, CODEQL_VERSION_CONFIG_FILES))
);
}
/*
* Returns whether the path in the argument represents an existing directory.
*/
export function doesDirectoryExist(dirPath: string): boolean {
try {
const stats = fs.lstatSync(dirPath);
return stats.isDirectory();
} catch (e) {
return false;
}
}
/**
* Returns a recursive list of files in a given directory.
*/
export function listFolder(dir: string): string[] {
if (!doesDirectoryExist(dir)) {
return [];
}
const entries = fs.readdirSync(dir, { withFileTypes: true });
let files: string[] = [];
for (const entry of entries) {
if (entry.isFile()) {
files.push(path.resolve(dir, entry.name));
} else if (entry.isDirectory()) {
files = files.concat(listFolder(path.resolve(dir, entry.name)));
}
}
return files;
}