This repository was archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 543
修复打开工程文件失败 #73
Open
Ray0218
wants to merge
2
commits into
klaus01:master
Choose a base branch
from
Ray0218:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
修复打开工程文件失败 #73
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
KLGenerateSpamCode.xcodeproj/xcshareddata/xcschemes/KLGenerateSpamCode.xcscheme
This file contains hidden or 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,108 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Scheme | ||
| LastUpgradeVersion = "1120" | ||
| version = "1.3"> | ||
| <BuildAction | ||
| parallelizeBuildables = "YES" | ||
| buildImplicitDependencies = "YES"> | ||
| <BuildActionEntries> | ||
| <BuildActionEntry | ||
| buildForTesting = "YES" | ||
| buildForRunning = "YES" | ||
| buildForProfiling = "YES" | ||
| buildForArchiving = "YES" | ||
| buildForAnalyzing = "YES"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "24934DDE1F0CD64800958090" | ||
| BuildableName = "KLGenerateSpamCode" | ||
| BlueprintName = "KLGenerateSpamCode" | ||
| ReferencedContainer = "container:KLGenerateSpamCode.xcodeproj"> | ||
| </BuildableReference> | ||
| </BuildActionEntry> | ||
| </BuildActionEntries> | ||
| </BuildAction> | ||
| <TestAction | ||
| buildConfiguration = "Debug" | ||
| selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
| selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
| shouldUseLaunchSchemeArgsEnv = "YES"> | ||
| <Testables> | ||
| </Testables> | ||
| </TestAction> | ||
| <LaunchAction | ||
| buildConfiguration = "Debug" | ||
| selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
| selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
| launchStyle = "0" | ||
| useCustomWorkingDirectory = "NO" | ||
| ignoresPersistentStateOnLaunch = "NO" | ||
| debugDocumentVersioning = "YES" | ||
| debugServiceExtension = "internal" | ||
| allowLocationSimulation = "YES"> | ||
| <BuildableProductRunnable | ||
| runnableDebuggingMode = "0"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "24934DDE1F0CD64800958090" | ||
| BuildableName = "KLGenerateSpamCode" | ||
| BlueprintName = "KLGenerateSpamCode" | ||
| ReferencedContainer = "container:KLGenerateSpamCode.xcodeproj"> | ||
| </BuildableReference> | ||
| </BuildableProductRunnable> | ||
| <CommandLineArguments> | ||
| <CommandLineArgument | ||
| argument = "/Users/zl/Desktop/testRname/VietnamObject/VietnamObject " | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| <CommandLineArgument | ||
| argument = "-ignoreDirNames Network,Categry,Configure,MGBaseKit,MGLiveDetection,Pods,ThirdSdk" | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| <CommandLineArgument | ||
| argument = "-modifyClassNamePrefix /Users/zl/Desktop/testRname/VietnamObject/VietnamObject.xcodeproj PS>RR" | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| <CommandLineArgument | ||
| argument = "-modifyProjectName VietnamObject>NewNameDemo" | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| <CommandLineArgument | ||
| argument = "-handleXcassets " | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| <CommandLineArgument | ||
| argument = "-deleteComments" | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| <CommandLineArgument | ||
| argument = "-spamCodeOut //Users/zl/Desktop/垃圾代码 dash" | ||
| isEnabled = "YES"> | ||
| </CommandLineArgument> | ||
| </CommandLineArguments> | ||
| </LaunchAction> | ||
| <ProfileAction | ||
| buildConfiguration = "Release" | ||
| shouldUseLaunchSchemeArgsEnv = "YES" | ||
| savedToolIdentifier = "" | ||
| useCustomWorkingDirectory = "NO" | ||
| debugDocumentVersioning = "YES"> | ||
| <BuildableProductRunnable | ||
| runnableDebuggingMode = "0"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "24934DDE1F0CD64800958090" | ||
| BuildableName = "KLGenerateSpamCode" | ||
| BlueprintName = "KLGenerateSpamCode" | ||
| ReferencedContainer = "container:KLGenerateSpamCode.xcodeproj"> | ||
| </BuildableReference> | ||
| </BuildableProductRunnable> | ||
| </ProfileAction> | ||
| <AnalyzeAction | ||
| buildConfiguration = "Debug"> | ||
| </AnalyzeAction> | ||
| <ArchiveAction | ||
| buildConfiguration = "Release" | ||
| revealArchiveInOrganizer = "YES"> | ||
| </ArchiveAction> | ||
| </Scheme> | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -279,13 +279,7 @@ int main(int argc, const char * argv[]) { | |
| } | ||
| printf("删除注释和空行完成\n"); | ||
| } | ||
| if (oldProjectName && newProjectName) { | ||
| @autoreleasepool { | ||
| NSString *dir = gSourceCodeDir.stringByDeletingLastPathComponent; | ||
| modifyProjectName(dir, oldProjectName, newProjectName); | ||
| } | ||
| printf("修改工程名完成\n"); | ||
| } | ||
|
|
||
| if (oldClassNamePrefix && newClassNamePrefix) { | ||
| printf("开始修改类名前缀...\n"); | ||
| @autoreleasepool { | ||
|
|
@@ -303,6 +297,14 @@ int main(int argc, const char * argv[]) { | |
| } | ||
| printf("修改类名前缀完成\n"); | ||
| } | ||
|
|
||
| if (oldProjectName && newProjectName) { | ||
| @autoreleasepool { | ||
| NSString *dir = gSourceCodeDir.stringByDeletingLastPathComponent; | ||
| modifyProjectName(dir, oldProjectName, newProjectName); | ||
| } | ||
| printf("修改工程名完成\n"); | ||
| } | ||
| if (outDirString) { | ||
| NSMutableString *categoryCallImportString = [NSMutableString string]; | ||
| NSMutableString *categoryCallFuncString = [NSMutableString string]; | ||
|
|
@@ -442,7 +444,7 @@ void generateSpamCodeFile(NSString *outDirectory, NSString *mFilePath, GSCSource | |
| return; | ||
| } | ||
| } | ||
|
|
||
| // 查找方法 | ||
| NSString *implementation = [mFileContent substringWithRange:impResult.range]; | ||
| NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"^ *([-+])[^)]+\\)([^;{]+)" options:NSRegularExpressionAnchorsMatchLines|NSRegularExpressionUseUnicodeWordBoundaries error:nil]; | ||
|
|
@@ -561,9 +563,9 @@ void generateSpamCodeFile(NSString *outDirectory, NSString *mFilePath, GSCSource | |
| extension %@ {\n%@\ | ||
| }\n"; | ||
| static NSString *const kSwiftMethodTemplate = @"\ | ||
| func %@%@(_ %@: String%@) {\n\ | ||
| print(%@)\n\ | ||
| }\n"; | ||
| func %@%@(_ %@: String%@) {\n\ | ||
| print(%@)\n\ | ||
| }\n"; | ||
| void generateSwiftSpamCodeFile(NSString *outDirectory, NSString *swiftFilePath) { | ||
| NSString *swiftFileContent = [NSString stringWithContentsOfFile:swiftFilePath encoding:NSUTF8StringEncoding error:nil]; | ||
|
|
||
|
|
@@ -697,7 +699,7 @@ void deleteComments(NSString *directory, NSArray<NSString *> *ignoreDirNames) { | |
| deleteComments(filePath, ignoreDirNames); | ||
| continue; | ||
| } | ||
| if (![fileName hasSuffix:@".h"] && ![fileName hasSuffix:@".m"] && ![fileName hasSuffix:@".mm"] && ![fileName hasSuffix:@".swift"]) continue; | ||
| if (![fileName hasSuffix:@".h"] && ![fileName hasSuffix:@".m"] && ![fileName hasSuffix:@".mm"] && ![fileName hasSuffix:@".mm"] && ![fileName hasSuffix:@".swift"]) continue; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里重复添加 [fileName hasSuffix:@".mm"],得去掉。 |
||
| NSMutableString *fileContent = [NSMutableString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; | ||
| regularReplacement(fileContent, @"([^:/])//.*", @"\\1"); | ||
| regularReplacement(fileContent, @"^//.*", @""); | ||
|
|
@@ -857,7 +859,7 @@ void modifyFilesClassName(NSString *sourceCodeDir, NSString *oldClassName, NSStr | |
| } | ||
|
|
||
| NSString *fileName = filePath.lastPathComponent; | ||
| if ([fileName hasSuffix:@".h"] || [fileName hasSuffix:@".m"] || [fileName hasSuffix:@".pch"] || [fileName hasSuffix:@".swift"] || [fileName hasSuffix:@".xib"] || [fileName hasSuffix:@".storyboard"]) { | ||
| if ([fileName hasSuffix:@".h"] || [fileName hasSuffix:@".m"] || [fileName hasSuffix:@".mm"] || [fileName hasSuffix:@".pch"] || [fileName hasSuffix:@".swift"] || [fileName hasSuffix:@".xib"] || [fileName hasSuffix:@".storyboard"]) { | ||
|
|
||
| NSError *error = nil; | ||
| NSMutableString *fileContent = [NSMutableString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; | ||
|
|
@@ -886,6 +888,8 @@ void modifyClassNamePrefix(NSMutableString *projectContent, NSString *sourceCode | |
| NSArray<NSString *> *files = [fm contentsOfDirectoryAtPath:sourceCodeDir error:nil]; | ||
| BOOL isDirectory; | ||
| for (NSString *filePath in files) { | ||
|
|
||
|
|
||
| NSString *path = [sourceCodeDir stringByAppendingPathComponent:filePath]; | ||
| if ([fm fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory) { | ||
| if (![ignoreDirNames containsObject:filePath]) { | ||
|
|
@@ -899,27 +903,42 @@ void modifyClassNamePrefix(NSMutableString *projectContent, NSString *sourceCode | |
| NSString *newClassName; | ||
| if ([fileName hasPrefix:oldName]) { | ||
| newClassName = [newName stringByAppendingString:[fileName substringFromIndex:oldName.length]]; | ||
| } else { | ||
| //处理是category的情况。当是category时,修改+号后面的类名前缀 | ||
| }else if([fileName containsString:@"+"]){ | ||
| // category类型 | ||
| NSString *oldNamePlus = [NSString stringWithFormat:@"+%@",oldName]; | ||
| if ([fileName containsString:oldNamePlus]) { | ||
| NSMutableString *fileNameStr = [[NSMutableString alloc] initWithString:fileName]; | ||
| [fileNameStr replaceCharactersInRange:[fileName rangeOfString:oldNamePlus] withString:[NSString stringWithFormat:@"+%@",newName]]; | ||
| newClassName = fileNameStr; | ||
| }else{ | ||
| newClassName = [newName stringByAppendingString:fileName]; | ||
|
|
||
| newClassName = fileName; | ||
|
|
||
| } | ||
|
|
||
| }else { | ||
| newClassName = fileName; | ||
|
|
||
| } | ||
|
|
||
| // 文件名 Const.ext > DDConst.ext | ||
| if ([fileExtension isEqualToString:@"h"]) { | ||
| NSString *mFileName = [fileName stringByAppendingPathExtension:@"m"]; | ||
| if ([files containsObject:mFileName]) { | ||
| NSString *mmFileName = [fileName stringByAppendingPathExtension:@"mm"]; | ||
|
|
||
| if ([files containsObject:mFileName] || [files containsObject:mmFileName]) { | ||
| NSString *oldFilePath = [[sourceCodeDir stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:@"h"]; | ||
| NSString *newFilePath = [[sourceCodeDir stringByAppendingPathComponent:newClassName] stringByAppendingPathExtension:@"h"]; | ||
| renameFile(oldFilePath, newFilePath); | ||
| oldFilePath = [[sourceCodeDir stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:@"m"]; | ||
| newFilePath = [[sourceCodeDir stringByAppendingPathComponent:newClassName] stringByAppendingPathExtension:@"m"]; | ||
| if ([files containsObject:mFileName]) { | ||
| oldFilePath = [[sourceCodeDir stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:@"m"]; | ||
| newFilePath = [[sourceCodeDir stringByAppendingPathComponent:newClassName] stringByAppendingPathExtension:@"m"]; | ||
| }else{ | ||
| oldFilePath = [[sourceCodeDir stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:@"mm"]; | ||
| newFilePath = [[sourceCodeDir stringByAppendingPathComponent:newClassName] stringByAppendingPathExtension:@"mm"]; | ||
|
|
||
| } | ||
|
|
||
| renameFile(oldFilePath, newFilePath); | ||
| oldFilePath = [[sourceCodeDir stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:@"xib"]; | ||
| if ([fm fileExistsAtPath:oldFilePath]) { | ||
|
|
@@ -930,7 +949,7 @@ void modifyClassNamePrefix(NSMutableString *projectContent, NSString *sourceCode | |
| @autoreleasepool { | ||
| modifyFilesClassName(gSourceCodeDir, fileName, newClassName); | ||
| } | ||
| } else { | ||
| } else { | ||
| continue; | ||
| } | ||
| } else if ([fileExtension isEqualToString:@"swift"]) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用提交 .xcscheme 文件,更别把自己的参数提交上来。