diff --git a/.gitignore b/.gitignore index 0a5f925..0e44f7d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ Thumbs.db *.ncrunchsolution nCrunchTemp* _ReSharper* +launchSettings.json diff --git a/VersionHistory.md b/VersionHistory.md index 3207e93..46d5a7d 100644 --- a/VersionHistory.md +++ b/VersionHistory.md @@ -9,6 +9,11 @@ Prefix the description of the change with `[major]`, `[minor]` or `[patch]` in a ## Released +### 1.1.0 + +* Find and replace `.js`, `.py`, and `.ts` files. +* Support snake case and kebab case, i.e. when replacing `SourceText` with `TargetText`, replace `source_text` with `target_text` and `source-text` with `target-text`. + ### 1.0.0 * Initial release. diff --git a/src/FindReplaceCode/FindReplaceCode.csproj b/src/FindReplaceCode/FindReplaceCode.csproj index 7f8186a..f824656 100644 --- a/src/FindReplaceCode/FindReplaceCode.csproj +++ b/src/FindReplaceCode/FindReplaceCode.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.1 - 1.0.0 + 1.1.0 true findreplacecode Faithlife.FindReplaceCode.Tool diff --git a/src/FindReplaceCode/Program.cs b/src/FindReplaceCode/Program.cs index 65e5ea3..68c00c7 100644 --- a/src/FindReplaceCode/Program.cs +++ b/src/FindReplaceCode/Program.cs @@ -144,6 +144,14 @@ private IEnumerable> GetEnhancedFindReplacePairs(Ke enhancedKeyValuePair = TryGetEnhancedFindReplacePairs(searchReplacePair, x => x.ToUpperInvariant()); if (enhancedKeyValuePair != null) yield return enhancedKeyValuePair.Value; + + enhancedKeyValuePair = TryGetEnhancedFindReplacePairs(searchReplacePair, x => ToSnakeCase(x, '_')); + if (enhancedKeyValuePair != null) + yield return enhancedKeyValuePair.Value; + + enhancedKeyValuePair = TryGetEnhancedFindReplacePairs(searchReplacePair, x => ToSnakeCase(x, '-')); + if (enhancedKeyValuePair != null) + yield return enhancedKeyValuePair.Value; } private static KeyValuePair? TryGetEnhancedFindReplacePairs(KeyValuePair searchReplacePair, Func transform) @@ -286,6 +294,17 @@ private static string RenderMatchingGuid(Match match, Guid value) return oldText != oldText.ToUpperInvariant() ? newText : newText.ToUpperInvariant(); } + private static string ToSnakeCase(string value, char separator) + { + if (value == null) + return null; + + var words = GetWords(value); + return string.Join(separator.ToString(), words.Select(x => x.ToLowerInvariant())); + } + + private static string[] GetWords(string value) => s_word.Matches(value).Select(x => x.ToString()).ToArray(); + private const string c_guidPattern = @"\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\}"; private static readonly string s_fullUsageMessage = string.Join(Environment.NewLine, new[] @@ -294,6 +313,7 @@ private static string RenderMatchingGuid(Match match, Guid value) }); private static readonly Regex s_hiddenDirectoryRegex = new Regex(@"[\\/]\..*[\\/]", RegexOptions.CultureInvariant); + private static readonly Regex s_word = new Regex("[A-Z]([A-Z]*(?![a-z])|[a-z]*)|[a-z]+|[0-9]+", RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture); private readonly string m_folderPath; private readonly ReadOnlyCollection> m_searchReplaceArgs; diff --git a/src/FindReplaceCode/ProgramSettings.cs b/src/FindReplaceCode/ProgramSettings.cs index 91b2309..741a74c 100644 --- a/src/FindReplaceCode/ProgramSettings.cs +++ b/src/FindReplaceCode/ProgramSettings.cs @@ -13,14 +13,17 @@ public static class ProgramSettings ".csproj", ".fsd", ".html", + ".js", ".json", ".md", ".nuspec", ".props", ".proto", ".ps1", + ".py", ".settings", ".sln", + ".ts", ".xaml", ".yml", };