private static IEnumerable <string> EnumerateAllFiles(string source, string filters, ProjectLanguage language) { var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var patterns = filters.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToArray(); var directories = new List <string>() { source }; try { directories.AddRange( Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories) .Where(dirName => ShouldIncludeDirectory(CommonUtils.TrimEndSeparator(CommonUtils.GetRelativeDirectoryPath(source, dirName)))) ); } catch (Exception exc) when(exc is UnauthorizedAccessException || exc is IOException) { } foreach (var dir in directories) { if (NodejsConstants.ContainsNodeModulesOrBowerComponentsFolder(dir)) { continue; } try { foreach (var filter in patterns) { files.UnionWith(Directory.EnumerateFiles(dir, filter, SearchOption.TopDirectoryOnly)); } } catch (Exception exc) when(exc is UnauthorizedAccessException || exc is IOException) { } } var res = files .Where(path => path.StartsWith(source, StringComparison.OrdinalIgnoreCase)) .Select(path => path.Substring(source.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); // We only want to include the language specific config file by default, since the user can always add other files later switch (language) { case ProjectLanguage.TypeScript: return(res.Where(f => !f.EndsWith("jsconfig.json"))); case ProjectLanguage.JavaScript: default: return(res.Where(f => !f.EndsWith("tsconfig.json"))); } }
private static IEnumerable <string> EnumerateAllFiles(string source, string filters, bool excludeNodeModules) { var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var patterns = filters.Split(';').Concat(new[] { "*.js" }).Select(p => p.Trim()).ToArray(); var directories = new List <string>() { source }; try { directories.AddRange( Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories) .Where(dirName => ShouldIncludeDirectory(CommonUtils.TrimEndSeparator(CommonUtils.GetRelativeDirectoryPath(source, dirName)))) ); } catch (UnauthorizedAccessException) { } foreach (var dir in directories) { if (excludeNodeModules && NodejsConstants.ContainsNodeModulesOrBowerComponentsFolder(dir)) { continue; } try { foreach (var filter in patterns) { files.UnionWith(Directory.EnumerateFiles(dir, filter, SearchOption.TopDirectoryOnly)); } } catch (UnauthorizedAccessException) { } } var res = files .Where(path => path.StartsWith(source, StringComparison.Ordinal)) .Select(path => path.Substring(source.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)) .Distinct(StringComparer.OrdinalIgnoreCase); return(res); }
private static bool IsProjectTypeScriptSourceFile(string path) { return(TypeScriptHelpers.IsTypeScriptFile(path) && !StringComparer.OrdinalIgnoreCase.Equals(Path.GetExtension(path), NodejsConstants.TypeScriptDeclarationExtension) && !NodejsConstants.ContainsNodeModulesOrBowerComponentsFolder(path)); }
private static bool IsProjectTypeScriptSourceFile(string path) { return string.Equals(Path.GetExtension(path), NodejsConstants.TypeScriptExtension, StringComparison.OrdinalIgnoreCase) && !string.Equals(Path.GetExtension(path), NodejsConstants.TypeScriptDeclarationExtension, StringComparison.OrdinalIgnoreCase) && !NodejsConstants.ContainsNodeModulesOrBowerComponentsFolder(path); }