Created
January 12, 2021 09:38
-
-
Save mikezs/83ed44b8bd9f1643bafd7a9f0ec52211 to your computer and use it in GitHub Desktop.
Create a Package.swift from the Package.resolved in an Xcode Project
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
#!/bin/sh | |
cat MyProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | python3 package_from_spm_xcodeproj.py > Package.swift && swiftlint --strict ./Package.swift |
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
import sys | |
import json | |
print("// swift-tools-version:5.3") | |
print("// The swift-tools-version declares the minimum version of Swift required to build this package.") | |
print("import PackageDescription\n") | |
print("let package = Package(\n\tname: \"Fake\",\n\tdependencies: [") | |
names = [] | |
packages = [] | |
for package in json.load(sys.stdin)['object']['pins']: | |
names.append(package["package"]) | |
current = "" | |
current += "\t\t.package(name: \"" + package["package"] + \ | |
"\", url: \"" + package["repositoryURL"] + "\",\n" | |
state = package["state"] | |
if state["version"] != None: | |
current += "\t\t\t.exact(\"" + state["version"] + "\"))" | |
elif state["branch"] != None: | |
current += "\t\t\t.branch(\"" + state["branch"] + "\"))" | |
elif state["revision"] != None: | |
current += "\t\t\t.revision(\"" + state["revision"] + "\"))" | |
packages.append(current) | |
print(",\n".join([package for package in packages])) | |
print("\t],\n\ttargets: [\n\t\t.target(name: \"Fake\", dependencies: [") | |
print(",\n".join(["\t\t\t\"" + name + "\"" for name in names])) | |
print("\t\t])\n\t]\n)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment