Generate swift packages directory structure on the fly

Ankit Agarwal
1 min readDec 20, 2015

--

I have been experimenting a lot with Apple’s Swift Package Manager and one thing that annoys me a lot of creating the directory structure and manifest file by hand. Right now theres no way to automate this task via SPM itself but it is in the scope of the project.

In the meantime, I wrote a simple commandline utility called swiftpm to generate the directory structure needed for a swift package.

Installation

Make sure you have swift development snapshot installed:

https://swift.org/download/#latest-development-snapshots

Ensure that you’ve exported the snapshot’s path:

for OSX:
$ export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
for Linux:
$ export PATH=/path/to/snapshot/usr/bin:"${PATH}"

Confirm using:

$ swift --version
Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 0ddf238ad7)
Target: x86_64-apple-macosx10.9

this should output something like this with -dev in version number

Install swiftpm

$ git clone https://github.com/aciidb0mb3r/swiftpm
$ cd swiftpm
$ swift build
$ ln -s $PWD/.build/debug/swiftpm /usr/local/bin/swiftpm

Usage Instructions

Help

$ swiftpm
USAGE: swiftpm <Package Name> (lib|exec|exec-flat) [options]
Example: swiftpm HelloWorldPackage exec stubPackage Name Name of the Package
lib Library Package
exec Executable Package
exec-flat Executable Package without Sources folder
OPTIONS:
stub Generates sample commented out code in Package.swift

Examples

Create an executable package

$ swiftpm HelloApp exec

Create an executable package with flat folder structure

$ swiftpm HelloAppFlat exec-flat

Create an library package

$ swiftpm HelloLib lib

Uninstall

$ rm /usr/local/bin/swiftpm
$ rm -rf path/to/swiftpm

File any issues you encounter at : https://github.com/aciidb0mb3r/swiftpm/issues

--

--