PackageGen

PackageGen is command line tool that generates Package.swift
files based on Packagefile
and package.yml
files. It helps to minimize manifest code writing for new modules.
In addition it can render dependencies graph to give you visual representation of your dependencies (see Rendering Dependencies Graph for more info).
This tool is simply allow you to write same Package.swift
manifest files in yml and omit some repeating properties by declaring all of them in one place - Packagefile
(which is also written in yml).
It seems not really useful when your project has few modules, but process of writing whole Package.swift
over and over againg can become messy and tedious when your projects grows (with number of modules respectively).
Here is simple comparison between two approaches (note that Packagefile
is one for whole project):
Vanilla Package.swift
// swift-tools-version:5.3
import PackageDescription
let name: String = "ModuleA"
let platforms: [SupportedPlatform] = [
.iOS(.v14)
]
let dependencies: [Package.Dependency] = [
.package(path: "../ModuleB"),
.package(path: "../ModuleC"),
.package(path: "../ModuleD"),
.package(url: "https://github.com/ReactiveX/RxSwift.git", .exact("6.2.0")),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0"))
]
let products: [Product] = [
.library(
name: "ModuleA",
targets: [
"ModuleA"
]
)
]
let targets: [Target] = [
.target(
name: "ModuleA",
dependencies: [
.product(name: "ModuleB", package: "ModuleB"),
.product(name: "ModuleC", package: "ModuleC"),
.product(name: "ModuleD", package: "ModuleD"),
.product(name: "RxSwift", package: "RxSwift"),
.product(name: "Alamofire", package: "Alamofire")
],
path: "Sources"
)
]
let package = Package(
name: name,
platforms: platforms,
products: products,
dependencies: dependencies,
targets: targets
)
PackageGen's package.yml
Packagefile
:
swiftToolsVersion: '5.3'
platforms:
iOS: v14
dependencies:
- github: ReactiveX/RxSwift
exact: '6.2.0'
id: RxSwift
- github: Alamofire/Alamofire
upToNextMajor: '5.2.0'
id: Alamofire
package.yml
:
dependencies:
- ModuleB
- ModuleC
- ModuleD
- RxSwift
- Alamofire
Installing
From release (recommended)
git clone https://github.com/kulikov-ivan/pkgen pkgen
cd pkgen
git checkout release/1.0.0
swift build
cp .build/debug/pkgen /your/path/to/pkgen
Homebrew (not supported yet)
brew install pkgen
Swift Package Manager
.package(url: "https://github.com/kulikov-ivan/pkgen.git", from: "1.0.0")
Usage
Basically, all you need to do is:
- Create
Packagefile
in root of your project
- Fill
Packagefile
with all external dependencies and default parameters (swiftToolsVersion
, platforms
, swiftLanguageVersions
etc.) you need (see Packagefile Spec for more info)
- Add
package.yml
(in root of package) for every package you have
- Fill
package.yml
with required parameters. In most cases it’s just module dependencies, but you can also customize any parameters that vanilla Package.swift
has (see Manifest Spec for more info)
- Run
pkgen generate
to generate Package.swift
for every pacakge
- [Optional] add
Package.swift
to your .gitignore
to keep things clear 🙂
Available Commands
pkgen generate
This will look for a Packagefile
in the current directory and traverse all subdirectories (excluding hidden directories) in current directory for any package.yml
files. For every package.yml
found this command will generate Package.swift file next to it.
Options:
- -q –quietly - Disable all logs
- –use-cache - Generate
Package.swift
for only modifies package.yml
from last generation (or if Packagefile
was changed). Cache file will be located at ~/.pkgen/cache/pkgen_cache.json
pkgen graph
This will take provided Packagefile
and render graph.pdf
to output path.
Arguments:
- packagefile - Path to
Packagefile
- path - Path to
graph.pdf
output file
pkgen help
Get detailed usage information from cli.
Documentation
Contributing
Feel free to make pull requests for any bugs, features, or documentation, they are always welcome!
To contribute to pkgen, follow these steps:
- Fork this repository
- Create a branch:
git checkout -b <branch_name>
- Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin dev
- Create the pull request
License
MIT license. See LICENSE for details.
PackageGen

PackageGen is command line tool that generates
Package.swift
files based onPackagefile
andpackage.yml
files. It helps to minimize manifest code writing for new modules.In addition it can render dependencies graph to give you visual representation of your dependencies (see Rendering Dependencies Graph for more info).
This tool is simply allow you to write same
Package.swift
manifest files in yml and omit some repeating properties by declaring all of them in one place -Packagefile
(which is also written in yml).It seems not really useful when your project has few modules, but process of writing whole
Package.swift
over and over againg can become messy and tedious when your projects grows (with number of modules respectively).Here is simple comparison between two approaches (note that
Packagefile
is one for whole project):Vanilla Package.swift
PackageGen's package.yml
Packagefile
:package.yml
:Installing
From release (recommended)
Homebrew (not supported yet)
Swift Package Manager
Usage
Basically, all you need to do is:
Packagefile
in root of your projectPackagefile
with all external dependencies and default parameters (swiftToolsVersion
,platforms
,swiftLanguageVersions
etc.) you need (see Packagefile Spec for more info)package.yml
(in root of package) for every package you havepackage.yml
with required parameters. In most cases it’s just module dependencies, but you can also customize any parameters that vanillaPackage.swift
has (see Manifest Spec for more info)pkgen generate
to generatePackage.swift
for every pacakgePackage.swift
to your.gitignore
to keep things clear 🙂Available Commands
This will look for a
Packagefile
in the current directory and traverse all subdirectories (excluding hidden directories) in current directory for anypackage.yml
files. For everypackage.yml
found this command will generate Package.swift file next to it.Options:
Package.swift
for only modifiespackage.yml
from last generation (or ifPackagefile
was changed). Cache file will be located at~/.pkgen/cache/pkgen_cache.json
This will take provided
Packagefile
and rendergraph.pdf
to output path.Arguments:
Packagefile
graph.pdf
output fileGet detailed usage information from cli.
Documentation
Contributing
Feel free to make pull requests for any bugs, features, or documentation, they are always welcome!
To contribute to pkgen, follow these steps:
git checkout -b <branch_name>
git commit -m '<commit_message>'
git push origin dev
License
MIT license. See LICENSE for details.