diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..461759b --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,18 @@ +name: Swift + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - name: Build + run: swift build -v + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1b8f628..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -{ - "os": "osx", - "script": [ - "swift build -c release" - ], - "language": "swift", - "osx_image": "xcode9.3" -} \ No newline at end of file diff --git a/LICENSE b/LICENSE index d98c8e1..1794b35 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2018, ShouDong Zheng +Copyright (c) 2018, Shoudong Zheng All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index cbde659..b8d6d02 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # XcodeManager -[![Travis CI](https://travis-ci.org/ZhengShouDong/XcodeManager.svg?branch=master)](https://travis-ci.org/ZhengShouDong/XcodeManager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) [![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/ZhengShouDong/XcodeManager) +![Build Status](https://github.com/0x973/XcodeManager/actions/workflows/swift.yml/badge.svg?branch=master) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-00D835.svg?style=flat)](https://github.com/Carthage/Carthage) +[![Platform](https://img.shields.io/badge/Platform-OSX-green.svg)](https://github.com/0x973/XcodeManager) The better way to manage the Xcode project file (project.pbxproj) in swift. This swift module lets you automate the modification process. @@ -14,13 +16,13 @@ This swift module lets you automate the modification process. #### Swift Package Manager ```swift -.package(url: "https://github.com/ZhengShouDong/XcodeManager.git", from: "0.2.0") +.package(url: "https://github.com/0x973/XcodeManager.git", from: "0.2.0") ``` #### Carthage You can use [Carthage](https://github.com/Carthage/Carthage) to install `XcodeManager` by adding it to your Cartfile: ``` -github "ZhengShouDong/XcodeManager" ~> 0.2.0 +github "0x973/XcodeManager" ~> 0.2.0 ``` ## Usage @@ -69,7 +71,7 @@ project.setProductName("TestProduct") 7. How to modify the Bundle Identifier? ```swift -project.setBundleId("cn.zhengshoudong.TestProduct") +project.setBundleId("cn.x0x01.TestProduct") ``` 8. How to add new value? @@ -98,4 +100,4 @@ let isSaveSuccess = try? project.save() if (isSaveSuccess) { print("Done!") } -``` \ No newline at end of file +``` diff --git a/Sources/XcodeManager/XcodeManager.swift b/Sources/XcodeManager/XcodeManager.swift index 78ddf26..797273d 100644 --- a/Sources/XcodeManager/XcodeManager.swift +++ b/Sources/XcodeManager/XcodeManager.swift @@ -1,6 +1,6 @@ // XcodeManager.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without @@ -379,7 +379,6 @@ public struct XcodeManager { for (key, value) in objects { if var obj = value.dictionaryObject { if let isa = obj["isa"] as? String { - if (isa == "PBXBuildFile") { if let fileRef = obj["fileRef"] as? String { if (fileRef == uuid) { @@ -389,9 +388,7 @@ public struct XcodeManager { } } } - } - - if (isa == "PBXFrameworksBuildPhase") { + } else if (isa == "PBXFrameworksBuildPhase") { if let fileUuids = obj["files"] as? Array { obj["files"] = fileUuids.filter{ $0 != uuid } // 移除完毕, 开始回写缓存 @@ -457,14 +454,11 @@ public struct XcodeManager { if (isa == "PBXBuildFile") { let fileRef = obj["fileRef"] as? String ?? String() if (fileRef == uuid) { - // 找到指针树,移除并回写 if let _ = objects.removeValue(forKey: key) { self._cacheProjet["objects"] = XcodeManagerJSON(objects) } } - } - - if (isa == "PBXFrameworksBuildPhase") { + } else if (isa == "PBXFrameworksBuildPhase") { let fileUuids = obj["files"] as? Array ?? Array() if (fileUuids.isEmpty) { _logger.xcodeManagerPrintLog("`files` parse error!", type: .error) @@ -472,7 +466,6 @@ public struct XcodeManager { } obj["files"] = fileUuids.filter{ $0 != uuid } - // 移除完毕, 开始回写缓存 objects[key] = XcodeManagerJSON(obj) self._cacheProjet["objects"] = XcodeManagerJSON(objects) } @@ -601,16 +594,12 @@ public struct XcodeManager { let varType = frameworkSearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = frameworkSearchPaths?.string ?? String() - if (newPath == string) { + let frameworkSearchPath = frameworkSearchPaths?.string ?? String() + if (newPath == frameworkSearchPath) { _logger.xcodeManagerPrintLog("Current object already exists.") return } - var newArray = Array() - newArray.append(string) - newArray.append(newPath) - - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON([frameworkSearchPath, newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -625,17 +614,12 @@ public struct XcodeManager { } newArray.append(XcodeManagerJSON(newPath)) - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break default: - var newArray = Array() - newArray.append("$(inherited)") - newArray.append(newPath) - - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)", newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -672,22 +656,17 @@ public struct XcodeManager { let varType = librarySearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = librarySearchPaths?.string ?? String() - if (newPath == string) { + let librarySearchPath = librarySearchPaths?.string ?? String() + if (newPath == librarySearchPath) { _logger.xcodeManagerPrintLog("Current object already exists.") return } - var newArray = Array() - newArray.append(string) - newArray.append(newPath) - - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON([librarySearchPath, newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break case .array: var newArray = librarySearchPaths?.array ?? Array() - for ele in newArray { let str = ele.string ?? String() if (str == newPath) { @@ -696,17 +675,12 @@ public struct XcodeManager { } newArray.append(XcodeManagerJSON(newPath)) - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break default: - var newArray = Array() - newArray.append("$(inherited)") - newArray.append(newPath) - - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)", newPath]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -737,29 +711,26 @@ public struct XcodeManager { continue } - let framework_search_paths = buildSettings["FRAMEWORK_SEARCH_PATHS"] - let varType = framework_search_paths?.type ?? Type.unknown + let frameworkSearchPaths = buildSettings["FRAMEWORK_SEARCH_PATHS"] + let varType = frameworkSearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = framework_search_paths?.string ?? String() - if (removePath == string) { - var newArray = Array() - newArray.append("$(inherited)") - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + let frameworkSearchPath = frameworkSearchPaths?.string ?? String() + if (removePath == frameworkSearchPath) { + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict } break case .array: - let newArray = framework_search_paths?.array ?? Array() + let newArray = frameworkSearchPaths?.array ?? Array() let array = newArray.filter { $0.stringValue != removePath } buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(array) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break default: - let newArray = ["$(inherited)"] - buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["FRAMEWORK_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -794,8 +765,8 @@ public struct XcodeManager { let varType = librarySearchPaths?.type ?? Type.unknown switch varType { case .string: - let string = librarySearchPaths?.string ?? String() - if (removePath == string) { + let librarySearchPath = librarySearchPaths?.string ?? String() + if (removePath == librarySearchPath) { buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict @@ -809,8 +780,7 @@ public struct XcodeManager { self._cacheProjet["objects"][element.key] = dict break default: - let newArray = ["$(inherited)"] - buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(newArray) + buildSettings["LIBRARY_SEARCH_PATHS"] = XcodeManagerJSON(["$(inherited)"]) dict["buildSettings"] = XcodeManagerJSON(buildSettings) self._cacheProjet["objects"][element.key] = dict break @@ -894,8 +864,8 @@ public struct XcodeManager { } let rootObj = objects[self._rootObjectUUID]?.dictionary ?? Dictionary() - var attributes = rootObj["attributes"]?.dictionary ?? Dictionary() - var targetAttributes = attributes["TargetAttributes"]?.dictionary ?? Dictionary() + let attributes = rootObj["attributes"]?.dictionary ?? Dictionary() + let targetAttributes = attributes["TargetAttributes"]?.dictionary ?? Dictionary() var newTargetAttributes = Dictionary() for attribute in targetAttributes { diff --git a/Sources/XcodeManager/XcodeManagerFile.swift b/Sources/XcodeManager/XcodeManagerFile.swift index 19dd6df..c551d11 100644 --- a/Sources/XcodeManager/XcodeManagerFile.swift +++ b/Sources/XcodeManager/XcodeManagerFile.swift @@ -1,6 +1,6 @@ // XcodeManagerFile.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without @@ -53,17 +53,16 @@ internal struct XcodeManagerFile { } let fileURL = URL(fileURLWithPath: path) - let filePathExtension = fileURL.pathExtension if (!fileURL.isFileURL || filePathExtension.isEmpty) { return defaultFileType } let type = XcodeManagerFile.fileTypeDict[filePathExtension] ?? String() - if !type.isEmpty { - return type + if type.isEmpty { + return defaultFileType } - return "unknown" + return type } } diff --git a/Sources/XcodeManager/XcodeManagerJSON.swift b/Sources/XcodeManager/XcodeManagerJSON.swift index d422700..2287906 100644 --- a/Sources/XcodeManager/XcodeManagerJSON.swift +++ b/Sources/XcodeManager/XcodeManagerJSON.swift @@ -1,6 +1,6 @@ // XcodeManagerJSON.swift // -// Copyright (c) 2019, ShouDong Zheng +// Copyright (c) 2019, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without diff --git a/Sources/XcodeManager/XcodeManagerLogger.swift b/Sources/XcodeManager/XcodeManagerLogger.swift index b8f63f8..31a25f3 100644 --- a/Sources/XcodeManager/XcodeManagerLogger.swift +++ b/Sources/XcodeManager/XcodeManagerLogger.swift @@ -1,6 +1,6 @@ // XcodeManagerLogger.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without diff --git a/Sources/XcodeManagerTests/XcodeManagerTests.swift b/Sources/XcodeManagerTests/XcodeManagerTests.swift index 4f092d6..b1b40f3 100644 --- a/Sources/XcodeManagerTests/XcodeManagerTests.swift +++ b/Sources/XcodeManagerTests/XcodeManagerTests.swift @@ -1,6 +1,6 @@ // XcodeManagerTests.swift // -// Copyright (c) 2018, ShouDong Zheng +// Copyright (c) 2018, Shoudong Zheng // All rights reserved. // Redistribution and use in source and binary forms, with or without @@ -66,10 +66,10 @@ class XcodeManagerTests: XCTestCase { // test BundleId get and set. finally, will reset func testBundleId() { let bundleId = _project!.getBundleId() - XCTAssertEqual(bundleId, "cn.zhengshoudong.iOSTestProject") + XCTAssertEqual(bundleId, "cn.x0x01.iOSTestProject") - _project!.setBundleId("cn.zhengshoudong.xxxx") - XCTAssertEqual(_project!.getBundleId(), "cn.zhengshoudong.xxxx") + _project!.setBundleId("cn.x0x01.xxxx") + XCTAssertEqual(_project!.getBundleId(), "cn.x0x01.xxxx") _project!.setBundleId(bundleId) }