Init `Package.swift` from JSON

Viewed 102

Context

SPM allows to generate a JSON from your Package.swift using swift package dump-package command.

The result of calling dump-package command on:

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Foo",
    dependencies: [
        .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0")),
        .package(url: "https://github.com/Moya/Moya.git", .upToNextMajor(from: "14.0.0"))
    ]
)

is:

{
  "cLanguageStandard" : null,
  "cxxLanguageStandard" : null,
  "dependencies" : [
    {
      "name" : "Alamofire",
      "requirement" : {
        "range" : [
          {
            "lowerBound" : "5.2.0",
            "upperBound" : "6.0.0"
          }
        ]
      },
      "url" : "https:\/\/github.com\/Alamofire\/Alamofire.git"
    },
    {
      "name" : "Moya",
      "requirement" : {
        "range" : [
          {
            "lowerBound" : "14.0.0",
            "upperBound" : "15.0.0"
          }
        ]
      },
      "url" : "https:\/\/github.com\/Moya\/Moya.git"
    }
  ],
  "name" : "Foo",
  "pkgConfig" : null,
  "platforms" : [

  ],
  "products" : [

  ],
  "providers" : null,
  "swiftLanguageVersions" : null,
  "targets" : [

  ],
  "toolsVersion" : {
    "_version" : "5.3.0"
  }
}

Questions

Is it possible to make it in opposite direction? Can I generate Package.swift from JSON using Swift Package Manager?

0 Answers
Related