bow-swift / nef

💊 steroids for Xcode Playgrounds
https://nef.bow-swift.io
Other
267 stars 6 forks source link

Update nef playgroundbook generator #169

Closed miguelangel-dev closed 4 years ago

miguelangel-dev commented 4 years ago

Details

This PR updates how nef generates PlaygroundBooks from a Swift Package. Currently, it takes the whole targets (and its dependencies) from a Package and map to .playgroundmodules to build a Swift Playground compatible; this PR changes how it works, taking only the targets necessaries (and its dependencies) from the products -libraries- defined in the Package.

It fixes bugs about including targets do not necessary to build the final library.

How is it implemented?

Using a new swift package option: dump-package; it prints parsed Package.swift as JSON. It lets us read the products and the targets section of a Package to filter extracted modules.

   packageProducts <- readPackageGraph()     // (helper: swift package dump-packate)
     reposProducts <- repos.flatTraverse(readPackageGraph)
      reposModules <- readModulesInPackage() // (helper: swift package describe)
          products <- filterReposProducts(reposProducts, byPackage: packageProducts)
           modules <- extractPackageModules(reposModules, inProducts: products)

return modules // These modules will be used to generate the Playground Book

You can test thisdump package command,

swift package --package-path <repo> dump-package