From 7f4459dc50d516fe1b66c851c22c9cfe9c3bcba0 Mon Sep 17 00:00:00 2001 From: Underthestars-zhy Date: Thu, 13 Jul 2023 21:26:59 +0800 Subject: [PATCH] support more files --- SwiftGGFormatter.xcodeproj/project.pbxproj | 4 -- .../xcshareddata/swiftpm/Package.resolved | 41 +++++++++++++++++++ SwiftGGFormatter/Mapper.swift | 32 --------------- SwiftGGFormatter/SwiftGGFormatter.swift | 10 ++++- 4 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 SwiftGGFormatter.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved delete mode 100644 SwiftGGFormatter/Mapper.swift diff --git a/SwiftGGFormatter.xcodeproj/project.pbxproj b/SwiftGGFormatter.xcodeproj/project.pbxproj index 902abd9..cd55d32 100644 --- a/SwiftGGFormatter.xcodeproj/project.pbxproj +++ b/SwiftGGFormatter.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 90B11FF32A2B8CDA00188D29 /* SwiftGGFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B11FF22A2B8CDA00188D29 /* SwiftGGFormatter.swift */; }; 90B11FFB2A2B8CFA00188D29 /* SwiftGGFormater in Frameworks */ = {isa = PBXBuildFile; productRef = 90B11FFA2A2B8CFA00188D29 /* SwiftGGFormater */; }; - 90B11FFD2A2B8D0600188D29 /* Mapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B11FFC2A2B8D0600188D29 /* Mapper.swift */; }; 90B120002A2B8EB200188D29 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 90B11FFF2A2B8EB200188D29 /* ArgumentParser */; }; /* End PBXBuildFile section */ @@ -28,7 +27,6 @@ /* Begin PBXFileReference section */ 90B11FEF2A2B8CDA00188D29 /* SwiftGGFormatter */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SwiftGGFormatter; sourceTree = BUILT_PRODUCTS_DIR; }; 90B11FF22A2B8CDA00188D29 /* SwiftGGFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftGGFormatter.swift; sourceTree = ""; }; - 90B11FFC2A2B8D0600188D29 /* Mapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mapper.swift; sourceTree = ""; }; 90B120012A2B903F00188D29 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; /* End PBXFileReference section */ @@ -66,7 +64,6 @@ isa = PBXGroup; children = ( 90B11FF22A2B8CDA00188D29 /* SwiftGGFormatter.swift */, - 90B11FFC2A2B8D0600188D29 /* Mapper.swift */, ); path = SwiftGGFormatter; sourceTree = ""; @@ -137,7 +134,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 90B11FFD2A2B8D0600188D29 /* Mapper.swift in Sources */, 90B11FF32A2B8CDA00188D29 /* SwiftGGFormatter.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/SwiftGGFormatter.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/SwiftGGFormatter.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..80dd733 --- /dev/null +++ b/SwiftGGFormatter.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,41 @@ +{ + "pins" : [ + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a", + "version" : "1.2.2" + } + }, + { + "identity" : "swiftggformater", + "kind" : "remoteSourceControl", + "location" : "https://github.com/underthestars-zhy/SwiftGGFormater", + "state" : { + "revision" : "02e38eac9d441e74d8e394c910968c39ee193454", + "version" : "1.0.0" + } + }, + { + "identity" : "swiftsoup", + "kind" : "remoteSourceControl", + "location" : "https://github.com/scinfu/SwiftSoup", + "state" : { + "revision" : "0e96a20ffd37a515c5c963952d4335c89bed50a6", + "version" : "2.6.0" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "f47ba4838c30dbd59998a4e4c87ab620ff959e8a", + "version" : "5.0.5" + } + } + ], + "version" : 2 +} diff --git a/SwiftGGFormatter/Mapper.swift b/SwiftGGFormatter/Mapper.swift deleted file mode 100644 index 1672e6a..0000000 --- a/SwiftGGFormatter/Mapper.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// Mapper.swift -// SwiftGGFormatter -// -// Created by 朱浩宇 on 2023/6/3. -// - -import Foundation - -let mapper = [ - "adjusting-the-space-between-views.yml": "https://developer.apple.com/tutorials/swiftui-concepts/adjusting-the-space-between-views", - - "choosing-the-right-way-to-hide-a-view.yml": "https://developer.apple.com/tutorials/swiftui-concepts/choosing-the-right-way-to-hide-a-view", - - "creating-a-custom-input-control-that-binds-to-a-value.yml": "https://developer.apple.com/tutorials/swiftui-concepts/creating-a-custom-input-control-that-binds-to-a-value", - - "defining-the-source-of-truth-using-a-custom-binding.yml": "https://developer.apple.com/tutorials/swiftui-concepts/defining-the-source-of-truth-using-a-custom-binding", - - "driving-changes-in-your-ui-with-state-and-bindings.yml": "https://developer.apple.com/tutorials/swiftui-concepts/driving-changes-in-your-ui-with-state-and-bindings", - - "exploring-the-structure-of-a-swiftui-app.yml": "https://developer.apple.com/tutorials/swiftui-concepts/exploring-the-structure-of-a-swiftui-app", - - "layering-content.yml": "https://developer.apple.com/tutorials/swiftui-concepts/layering-content", - - "maintaining-the-adaptable-sizes-of-built-in-views.yml": "https://developer.apple.com/tutorials/swiftui-concepts/maintaining-the-adaptable-sizes-of-built-in-views", - - "organizing-and-aligning-content-with-stacks.yml": "https://developer.apple.com/tutorials/swiftui-concepts/organizing-and-aligning-content-with-stacks", - - "scaling-views-to-complement-text.yml": "https://developer.apple.com/tutorials/swiftui-concepts/scaling-views-to-complement-text", - - "specifying-the-view-hierarchy-of-an-app-using-a-scene.yml": "https://developer.apple.com/tutorials/swiftui-concepts/specifying-the-view-hierarchy-of-an-app-using-a-scene", -] diff --git a/SwiftGGFormatter/SwiftGGFormatter.swift b/SwiftGGFormatter/SwiftGGFormatter.swift index a5cdb07..68ef843 100644 --- a/SwiftGGFormatter/SwiftGGFormatter.swift +++ b/SwiftGGFormatter/SwiftGGFormatter.swift @@ -20,7 +20,15 @@ struct SwiftGGFormatterCLI: AsyncParsableCommand { mutating func run() async throws { let file = URL.init(filePath: path) - let formater = SwiftGGFormater(file: file, web: URL(string: mapper[file.lastPathComponent]!)!) + let formater = SwiftGGFormater(file: file, web: findURL(path: path)) try await formater.formate() } + + func findURL(path: String) -> URL { + let file = URL.init(filePath: path) + let components = file.pathComponents + let category = components[components.endIndex - 2] + let fileName = file.deletingPathExtension().lastPathComponent + return URL(string: "https://developer.apple.com/tutorials/\(category)/\(fileName)")! + } }