-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: place import command line tool
- Loading branch information
1 parent
3b55bdd
commit e698d43
Showing
62 changed files
with
985 additions
and
247 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
SZEditorExtension.xcodeproj/xcshareddata/xcschemes/SZPlaceImports.xcscheme
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,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1600" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "245E06A72C26700600F41C75" | ||
BuildableName = "SZPlaceImports" | ||
BlueprintName = "SZPlaceImports" | ||
ReferencedContainer = "container:SZEditorExtension.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</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" | ||
viewDebuggingEnabled = "No"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "245E06A72C26700600F41C75" | ||
BuildableName = "SZPlaceImports" | ||
BlueprintName = "SZPlaceImports" | ||
ReferencedContainer = "container:SZEditorExtension.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "245E06A72C26700600F41C75" | ||
BuildableName = "SZPlaceImports" | ||
BlueprintName = "SZPlaceImports" | ||
ReferencedContainer = "container:SZEditorExtension.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
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
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
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
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
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
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
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
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,96 @@ | ||
// | ||
// main.m | ||
// SZPlaceImports | ||
// | ||
// Created by csz on 2024.06.22. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "NSArray+SZAddition.h" | ||
#import "NSString+SZAddition.h" | ||
#import "SZPlaceImportHelper.h" | ||
|
||
NSArray<NSString *> *splitedLines(NSString *contents) { | ||
NSUInteger start = 0; | ||
NSUInteger count = contents.length; | ||
NSMutableArray *tempArray = [NSMutableArray array]; | ||
for (NSUInteger idx = 0; idx < count; idx++) { | ||
unichar c = [contents characterAtIndex:idx]; | ||
if (c == '\n') { | ||
NSRange range = NSMakeRange(start, idx + 1 - start); | ||
NSString *line = [contents substringWithRange:range]; | ||
[tempArray addObject:line]; | ||
start = idx + 1; | ||
} | ||
} | ||
if (start < count) { | ||
NSRange range = NSMakeRange(start, count - start); | ||
NSString *line = [contents substringWithRange:range]; | ||
[tempArray addObject:line]; | ||
} | ||
return [tempArray copy]; | ||
} | ||
|
||
BOOL isSupportedFile(NSString *filePath) { | ||
if (![filePath sz_isFileExist]) { | ||
return NO; | ||
} | ||
NSString *extension = filePath.pathExtension.lowercaseString; | ||
if (![extension isEqualToString:@"h"] && ![extension isEqualToString:@"m"]) { | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
|
||
void processFile(NSString *filePath) { | ||
@autoreleasepool { | ||
if (!isSupportedFile(filePath)) { | ||
return; | ||
} | ||
NSStringEncoding encoding = NSUTF8StringEncoding; | ||
NSString *contents = [NSString stringWithContentsOfFile:filePath usedEncoding:&encoding error:nil]; | ||
if (!contents.length) { | ||
return; | ||
} | ||
NSArray<NSString *> *lines = splitedLines(contents); | ||
lines = [SZPlaceImportHelper processLines:lines | ||
selections:@[] | ||
commandIdentifier:nil]; | ||
contents = [lines componentsJoinedByString:@""]; | ||
[contents writeToFile:filePath atomically:YES encoding:encoding error:nil]; | ||
} | ||
} | ||
|
||
NSArray<NSString *> *findSupportedFiles(NSString *directory) { | ||
NSURL *directoryURL = [NSURL fileURLWithPath:directory]; | ||
NSDirectoryEnumerator *enumerator = [NSFileManager.defaultManager enumeratorAtURL:directoryURL | ||
includingPropertiesForKeys:nil | ||
options:NSDirectoryEnumerationSkipsHiddenFiles | ||
errorHandler:nil]; | ||
NSMutableArray *tempArray = [NSMutableArray array]; | ||
for (NSURL *url in enumerator) { | ||
if (!isSupportedFile(url.path)) { | ||
continue; | ||
} | ||
[tempArray addObject:url.path]; | ||
} | ||
return [tempArray copy]; | ||
} | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
for (int i = 1; i < argc; i++) { | ||
NSString *path = [[NSString alloc] initWithCString:argv[i] encoding:NSUTF8StringEncoding]; | ||
path = [path stringByResolvingSymlinksInPath]; | ||
if ([path sz_isDirectory]) { | ||
NSArray *files = findSupportedFiles(path); | ||
for (NSString *file in files) { | ||
processFile(file); | ||
} | ||
} else { | ||
processFile(path); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
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
Oops, something went wrong.