Giter Site home page Giter Site logo

johnsundell / swiftplate Goto Github PK

View Code? Open in Web Editor NEW
1.8K 31.0 88.0 471 KB

Easily generate cross platform Swift framework projects from the command line

License: MIT License

Swift 89.18% Ruby 3.24% Makefile 2.54% Python 5.05%
cli swift script xcode generate

swiftplate's Introduction

SwiftPlate

Easily generate cross platform Swift framework projects from the command line.

SwiftPlate will generate Xcode projects for you in seconds, that support:

  • CocoaPods
  • Carthage
  • Swift Package Manager
  • iOS
  • macOS
  • watchOS
  • tvOS
  • Linux

Just run swiftplate, and you’ll be presented with a simple step-by-step guide:

Screenshot

Usage

Using Homebrew (recommended)

$ brew install swiftplate
$ swiftplate

Using Make

$ git clone [email protected]:JohnSundell/SwiftPlate.git
$ cd swiftplate
$ make

Using Marathon

$ git clone [email protected]:JohnSundell/SwiftPlate.git
$ marathon run swiftplate/main

Using the Swift interpreter directly

$ git clone [email protected]:JohnSundell/SwiftPlate.git
$ swift swiftplate/main.swift

Using Xcode

$ git clone [email protected]:JohnSundell/SwiftPlate.git
$ open swiftplate/SwiftPlate.xcodeproj

Command line arguments

Besides using the guide to input information, SwiftPlate also supports command line arguments when launched. When a certain piece of information is supplied through an argument, SwiftPlate won't ask for that information when run. These are the arguments currently supported:

Name Description Long parameter Short parameter
Destination Where the generated project should be saved --destination -d
Project name The name of your project --project -p
Author name Your name --name -n
Author email Your email (for Podspec) --email -e
GitHub URL Any URL you'll be hosting the project at (for Podspec) --url -u
Organization name The name of your organization --organization -o
Repo Any custom SwiftPlate repository that should be used for templates --repo -r
Force Prevent user prompt at the end (for CIs etc.) --force -f

Questions or feedback?

Feel free to open an issue, or find me @johnsundell on Twitter.

swiftplate's People

Contributors

adellibovi avatar artsabintsev avatar christoff-1992 avatar codeofrobin avatar dani-mp avatar gperdomor avatar idcrook avatar johnsundell avatar kieranharper avatar kiliankoe avatar marmelroy avatar marvinnazari avatar nerosnm avatar noremac avatar onmyway133 avatar sungmin-kim568 avatar turushan avatar vijaytholpadi avatar vknabel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftplate's Issues

Ignore copying README & LICENSE files if they already exist

If SwiftPlate is run in a repo that has been cloned from an empty GitHub repo, it will already contain a README.md and LICENSE files, which will cause SwiftPlate to error. What should happen is that if any (or both) of those files already exists, SwiftPlate should not attempt to overwrite them.

License put in by default

It looks like the generated files have the MIT License put in by default at the top of all files. Though it doesn't really make a difference to my org (we're open sourcing most of our stuff), people might have a problem with it.
screen shot 2016-11-23 at 4 42 27 pm

Command line option for local cloning of templates?

Resolving this issue could be helpful for Template development/maintenance and testing.

Noticed as I was testing Template changes that SwiftPlate always clones from the main GitHub repo. It would be useful to have a command line switch to clone instead from the local clone on the filesystem. Something like --local-clone

If it is running from inside a cloned git repository, and the flag is specified,rather than cloning from GitHub, it could instead git clone from the local filesystem.

Template creation

I use cookiecutter and my custom template for project generation. I guess you have the same problem - it's very hand to update or create a new template. How you do it? It would be great if you add a command for template generation based on existing project. I want to write a script for it, but if you have a plan for it, I'll wait πŸ˜ƒ

Homebrew support

Hey! Not sure how and if it could work, but would it be possible to install SwiftPlate via Homebrew? πŸ‘

Dependencies

Not sure if I'm being stupid here or not, but what's the best way of managing subdependencies with this? For Cocoapods I could specify them in the podspec via s.dependency ... but can't really install them without a Podfile (something that would require an .xcworkspace as well).

Also those using the framework project built like this will probably have to use my dependency manager of choice as well, which is far from ideal. Is there a way to work around this? Or is it just not practical working with subdependencies when making a framework for use with all three currently used dependency managers?

Add .gitignore file

Hi! SwiftPlate is awesome, thanks for creating it. I was wondering if it makes sense to include a default .gitignore file for Xcode/Swift projects, I've seen other tools like this doing it.

Error when using `--repo`option

I have this error when trying to do swiftplate -r ./swiftplate:

πŸš€  Starting to generate project Test...
πŸ‘‰  Removing any previous temporary folder...
βœ…  Done
πŸ‘‰  Making temporary folder (Test/swiftplate_temp)...
βœ…  Done
πŸ‘‰  Making a local clone of the SwiftPlate repo...
βœ…  Done
πŸ‘‰  Copying template folder...
An error was encountered πŸ™
Error: Error Domain=NSCocoaErrorDomain Code=260 "The folder β€œTemplate” doesn’t exist." UserInfo={NSFilePath=Test/swiftplate_temp/SwiftPlate/Template, NSUserStringVariant=(
    Folder
), NSUnderlyingError=0x7f926940afa0 {Error Domain=NSOSStatusErrorDomain Code=-43 "fnfErr: File not found"}}

Maybe I'm missing something ? πŸ€”
It work well without the option -r

Test dependencies

Wonder if we could add Quick and Nimble as test dependencies, would make the whole process faster! we can use Carthage for that.

Help with dependencies

Hi, I use Carthage to handle dependencies.

I need use Alamofire and RxSwift for prod, and Nimble and Quick for test.

I add Alamofire and RxSwift to iOS target, and tests still run, but when I add the Quick and Nimble to iOS test target, I get this error when tried to run tests
screen shot 2017-01-18 at 9 55 19 pm

In the case of macOS target, the same error occurs after add Alamofire or RxSwift to prod target, no in tests target as occurs with iOS

This is the source code, please take a look :D. I don't know if the problem is the template, Carthage or anything else :(
project.zip

Error while creating a new project

Error output

πŸš€  Starting to generate project SmartAPI...
πŸ‘‰  Removing any previous temporary folder...
βœ…  Done
πŸ‘‰  Making temporary folder (/Users/Amadeu/Developer/swiftplate_temp)...
βœ…  Done
πŸ‘‰  Making a local clone of the SwiftPlate repo...
βœ…  Done
πŸ‘‰  Copying template folder...
βœ…  Done
πŸ‘‰  Removing temporary folder...
βœ…  Done
πŸ‘‰  Filling in template...
An error was encountered πŸ™
Error: Error Domain=NSCocoaErrorDomain Code=264 "The file β€œA.cpython-36.pyc” couldn’t be opened because the text encoding of its contents can’t be determined." UserInfo={NSFilePath=/Users/Amadeu/Developer/AREPL-vscode/test/manualAreplTests/__pycache__/A.cpython-36.pyc}

GitHub URL default fails on non-https remote scheme

I'm using SSH authentication for my remote. SwiftPlate defaults to reading my remote, which isn't a valid HTTP(S) URL to be used for the podspec or similar.

🌍 Any GitHub URL that you'll be hosting this project at (for Podspec)? (Leave empty to use the remote URL of your repo: [email protected]:kiliankoe/{projectname})

Encoding of its contents can’t be determined

Hi,

I was trying to use the generator and got this error in the generation phase:

Error: Error Domain=NSCocoaErrorDomain Code=264 "The file β€œUserInterfaceState.xcuserstate” couldn’t be opened because the text encoding of its contents can’t be determined." UserInfo={NSFilePath=/Users/or/dev/Back/Back.xcodeproj/project.xcworkspace/xcuserdata/or.xcuserdatad/UserInterfaceState.xcuserstate}

Now a second run prints the following error:

Error: Error Domain=NSCocoaErrorDomain Code=516 "β€œConfigs” couldn’t be copied to β€œdev” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Users/or/dev/swiftplate_temp/SwiftPlate/Template/Configs, NSUserStringVariant=( Copy ), NSDestinationFilePath=/Users/or/dev/Configs, NSFilePath=/Users/or/dev/swiftplate_temp/SwiftPlate/Template/Configs, NSUnderlyingError=0x7ff59d6185a0 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}

I tried deleting /Users/or/dev/swiftplate_temp but I get the same error.

Let me know if I can provide addional information,
Cheers 🍻
Or.

Does not build under Linux

Not sure if this is a requirement for this project-- or is supported-- but wanted to put an issue out there. It might never be supported.

I do not need this for myself as I can build/run SwiftPlate on macOS, and once I have the boilerplate build, I can use git clones to share in Linux environment.

building under linux

I tried to build SwiftPlate from recent clone on Linux (Ubuntu 16.04), and get build errors. Most of them look like they are Swift Core library/Foundation related, which is known to be lagging in completeness compared to macOS/*OS.

$ swift ../SwiftPlate/main.swift test
../SwiftPlate/main.swift:56:16: error: value of type 'ObjCBool' (aka 'Bool') has no member 'boolValue'
        return objCBool.boolValue
               ^~~~~~~~ ~~~~~~~~~
../SwiftPlate/main.swift:176:19: error: use of unresolved identifier 'Process'
    let process = Process()
                  ^~~~~~~
Foundation.NSProgress:1:12: note: did you mean 'NSProgress'?
open class NSProgress : Foundation.NSObject {
           ^
Foundation.ProcessInfo:1:12: note: did you mean 'ProcessInfo'?
open class ProcessInfo : Foundation.NSObject {
           ^

Process changed to CommandLine?

I didn't really dig much into these errors. Googling the Process() one yielded something that would appear to related, but after further investigation, I do not think it is: Rename Process to CommandLine [SE-0086] apple/swift@f65c139

The change referred to has been in place for a while on Swift 3 branch.

I was able to confirm that Process is available in Foundation on macOS, but is not present in Foundation on Linux (at this time).

Platform versions

OS: Ubuntu 16.04.1

$ swift --version
Swift version 3.0.1 (swift-3.0.1-RELEASE)
Target: x86_64-unknown-linux-gnu
$ uname -a
Linux vader 4.4.0-49-generic #70-Ubuntu SMP Fri Nov 11 16:40:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Add feature where users can choose the schemes to generate

Will be good a feature where the users could choose the schemes to be generated in the xcode project.

One solution is by command line argument. For example:

swift swiftplate/main.swift  # create all schemes (iOS, macOS, watchOS, tvOS)
swift swiftplate/main.swift  --ios # create schemes only for iOS
swift swiftplate/main.swift  --ios --tvos # create schemes only for iOS and tvOS

Generate one single (fat) framework

Hi, nice work.
I'm wondering if is it possible to generate one single Framework instead of 4.
Something similar to the old fashion fat libraries.

{PROJECT} is not replaced

Hi,

I'm running through SwiftPlate, on the last step of generating the project, I see that the {PROJECT} placeholder is not being updated. This is the screenshot

swift

This is my terminal

./main.swift
Welcome to the SwiftPlate project generator 🐣
πŸ“¦  Where would you like to generate a project? (Leave empty to use current directory)
/Users/khoa/Downloads/Superman
πŸ“›  What's the name of your project? (Leave empty to use the name of the project folder: Superman)

πŸ‘Ά  What's your name? (Leave empty to use your git config name: Khoa Pham)

πŸ“«  What's your email address (for Podspec)? (Leave empty to use your git config email: [email protected])

🌍  Any GitHub URL that you'll be hosting this project at (for Podspec)? You may leave this empty.

🏒  What's your organization name? You may leave this empty.

---------------------------------------------------------------------
SwiftPlate will now generate a project with the following parameters:
πŸ“¦  Destination: /Users/khoa/Downloads/Superman
πŸ“›  Name: Superman
πŸ‘Ά  Author: Khoa Pham
πŸ“«  Author email: [email protected]
---------------------------------------------------------------------
Proceed? βœ… (Y/N)
y
πŸš€  Starting to generate project Superman...
πŸ‘‰  Removing any previous temporary folder...
βœ…  Done
πŸ‘‰  Making temporary folder (/Users/khoa/Downloads/Superman/swiftplate_temp)...
βœ…  Done
πŸ‘‰  Making a local clone of the SwiftPlate repo...
βœ…  Done
πŸ‘‰  Copying template folder...
βœ…  Done
πŸ‘‰  Removing temporary folder...
βœ…  Done
πŸ‘‰  Filling in template...
βœ…  Done
All done! πŸŽ‰  Good luck with your project! πŸš€

I expect the {PROJECT} placeholder be replaced by Superman, maybe I miss something πŸ€”

Github URL

Hi, πŸ‘ for this tool

I'm running through SwiftPlate, at this Github URL step

Any GitHub URL that you'll be hosting this project at (for Podspec)? (Leave empty to use the remote URL of your repo: https://github.com/JohnSundell/SwiftPlate)

I think most people use Github now so it's more convenient if we support it directly. My proposal is to ask for Github username instead, and generate Github URL as https://github.com/{user_name}/{project_name}

What do you think? I would happily make a PR

{TODAY} is not replaced

I've just tried generating a new project with swiftplate with the name "SwiftPlateTest", and I've found that the {TODAY} placeholder in the header of each of the files hasn't been replaced with a value.

Here's my terminal output:

screen shot 2017-03-30 at 14 25 23

And the header of a file:

screen shot 2017-03-30 at 14 22 52

Objective-C Support?

I am assuming this doesn't work with Objective-C projects? If so it would be great if it could. πŸ™‚

Problem with Tests

Hi, I try to run test using package manager and return this error: error: no tests found to execute, create a module in your 'Tests' directory

Linux support missing from cross-platform?

Noticed that Swift libraries that are to be run on Linux have one slight variation in the testing that is missing from SwiftPlate.

Swift Package Manager (swift package init --type library) does additionally the following:

In Tests/{PROJECT}Tests/{PROJECT}Tests.swift it adds:

    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        XCTAssertEqual({PROJECT}().text, "Hello, World!")
    }
    static var allTests : [(String, ({PROJECT}Tests) -> () throws -> Void)] {
        return [
            ("testExample", testExample),
        ]
    }

the example assert is related to boilerplate code in the Sources/ implementation, but the allTests is more interesting, as that is the convention for the slightly different testing flow for Swift encountered under Linux.

For Linux it adds another, related file Tests/LinuxMain.swift. Its contents:

import XCTest
@testable import {PROJECT}Tests

XCTMain([
     testCase({PROJECT}Tests.allTests),
])

Could the "cross-platformness" of SwiftPlate be updated to include libraries on Linux?

Remove temporary folder if git clone failed

Currently, SwiftPlate just leaves the temporary directory it creates as one of its first steps if the git clone of the SwiftPlate repo failed. If there's a failure, we should clean up so that SwiftPlate may be run again.

Fails without much warning in Linux

Apparently it does not support Linux right now, but it also does not inform what is failing under Ubuntu.

Calling it generates the following:

└─λ swiftplate --verbose
Welcome to the SwiftPlate project generator 🐣
πŸ“¦  Where would you like to generate a project? (Leave empty to use current directory)

πŸ“›  What's the name of your project? (Leave empty to use the name of the project folder: bum)
lubaluba
πŸ‘Ά  What's your name?
lf-araujo
πŸ“«  What's your email address (for Podspec)? You may leave this empty.

🌍  Any GitHub URL that you'll be hosting this project at (for Podspec)? You may leave this empty.
lf-araujo/lubaluba
🏒  What's your organization name? You may leave this empty.

---------------------------------------------------------------------
SwiftPlate will now generate a project with the following parameters:
πŸ“¦  Destination: /tmp/bum
πŸ“›  Name: lubaluba
πŸ‘Ά  Author: lf-araujo
🌍  GitHub URL: lf-araujo/lubaluba
---------------------------------------------------------------------
Proceed? βœ… (Y/N)
y
πŸš€  Starting to generate project lubaluba...
πŸ‘‰  Removing any previous temporary folder...
βœ…  Done
πŸ‘‰  Making temporary folder (/tmp/bum/swiftplate_temp)...
βœ…  Done
πŸ‘‰  Making a local clone of the SwiftPlate repo...
βœ…  Done
πŸ‘‰  Copying template folder...
An error was encountered πŸ™
Error: The operation could not be completed

SwiftPlate fails if there are other files in the directory

Hey John!

I tried to generate my first SwiftPlate project today πŸŽ‰
I cd'ed into my Desktop and then run swiftplate. I have other files in my Desktop and the script failed with the following error.
screen shot 2017-04-08 at 7 06 41 pm

I expected it to create a new folder with my project name. I think you didn't consider the case where I would like to generate a project in an existing directory with other files. Or maybe it's just that if there are files without standard text encoding (in my case a Sketch file) in the current directory, the script fails.

I expected it to work like Xcode -> New -> Project does. A brand new folder with the project name is created in the chosen directory.

Optional Gather coverage data

Hi John,
First of all, thanks for this tool, it has been very helpful for me.
Do you think that an option to enable the "Gather coverage data" for all the testing targets would be useful? Does it suit in this project?
If so, I would like to work on that and prepare a PR.

Optional playground support

Adding a playground to a project generated with SwiftPlate is a bit convoluted, you need to wrap it in a workspace and then create and register in the plist an empty umbrella c header (that swiftplate normally doesn't include).

It would be nice to have all this done automatically when creating the project, if someone else is interested i could implement it.

Add CI support

Could be nice to have setup for CI, i.e. generated .yml etc. Maybe only Travis would be a good start. Keep up the good work πŸ‘

Fails to clone repo .. 'Too many arguments'

Hi there at the moment when I try to use SwiftPlate it fails to download the repo, correct me if I'm doing anything wrong. If you need further info more than happy to help. Just a heads up I normally use gitKrakken client but also have the git client installed, if it's a case of installing git via brew and making sure it's up-to-date I will proceed and feedback.

Thanks!

git version 2.8.4 (Apple Git-73)

DEBUG:

(lldb) expr dump(process.arguments)
([String]?) $R1 = 2 values {
[0] = "-c"
[1] = "git clone https://github.com/JohnSundell/SwiftPlate.git /Users/xxxxx/Documents/Personal Development/swiftplate_temp/SwiftPlate -q"
}

INPUT:

Welcome to the SwiftPlate project generator 🐣
πŸ“¦ Where would you like to generate a project? (Leave empty to use current directory)
/Users/xxxxx/Documents/Personal Development
πŸ“› What's the name of your project?
Test
πŸ‘Ά What's your name?
xxxxx xxxxx
πŸ“« What's your email address (for Podspec)? You may leave this empty.

🌍 Any GitHub URL that you'll be hosting this project at (for Podspec)? You may leave this empty.


SwiftPlate will now generate a project with the following parameters:
πŸ“¦ Destination: /Users/xxxxx/Documents/Personal Development
πŸ“› Name: Test
πŸ‘Ά Author: xxxxxx xxxxxxx

Proceed? βœ… (Y/N)
Y
πŸš€ Starting to generate project Test...
πŸ‘‰ Removing any previous temporary folder...
βœ… Done
πŸ‘‰ Making temporary folder (/Users/xxxxx/Documents/Personal Development/swiftplate_temp)...
βœ… Done
πŸ‘‰ Making a local clone of the SwiftPlate repo...
Too many arguments.

usage: git clone [] [--] [

]

-v, --verbose         be more verbose
-q, --quiet           be more quiet
--progress            force progress reporting
-n, --no-checkout     don't create a checkout
--bare                create a bare repository
--mirror              create a mirror repository (implies bare)
-l, --local           to clone from a local repository
--no-hardlinks        don't use local hardlinks, always copy
-s, --shared          setup as shared repository
--recursive           initialize submodules in the clone
--recurse-submodules  initialize submodules in the clone
--template <template-directory>
                      directory from which templates will be used
--reference <repo>    reference repository
--dissociate          use --reference only while cloning
-o, --origin <name>   use <name> instead of 'origin' to track upstream
-b, --branch <branch>
                      checkout <branch> instead of the remote's HEAD
-u, --upload-pack <path>
                      path to git-upload-pack on the remote
--depth <depth>       create a shallow clone of that depth
--single-branch       clone only one branch, HEAD or --branch
--separate-git-dir <gitdir>
                      separate git dir from working tree
-c, --config <key=value>
                      set config inside the new repository
-4, --ipv4            use IPv4 addresses only
-6, --ipv6            use IPv6 addresses only

βœ… Done
πŸ‘‰ Copying template folder...
An error was encountered πŸ™
Error: Error Domain=NSCocoaErrorDomain Code=260 "The folder β€œTemplate” doesn’t exist." UserInfo={NSFilePath=/Users/xxxxx/Documents/Personal Development//swiftplate_temp/SwiftPlate/Template, NSUserStringVariant=(
Folder
), NSUnderlyingError=0x100905080 {Error Domain=NSOSStatusErrorDomain Code=-43 "fnfErr: File not found"}}
Program ended with exit code: 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.