Skip to content

Instantly share code, notes, and snippets.

@mikezs
Created January 12, 2021 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikezs/83ed44b8bd9f1643bafd7a9f0ec52211 to your computer and use it in GitHub Desktop.
Save mikezs/83ed44b8bd9f1643bafd7a9f0ec52211 to your computer and use it in GitHub Desktop.
Create a Package.swift from the Package.resolved in an Xcode Project
#!/bin/sh
cat MyProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | python3 package_from_spm_xcodeproj.py > Package.swift && swiftlint --strict ./Package.swift
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