进击的vapor之vapor本地环境配置

安装xcode

从App Store下载xcode

检查Swift版本依赖

eval "$(curl -sL check.vapor.sh)"
✅  Compatible Xcode
✅  Compatible with Vapor 2

安装Vapor

  • 安装homebrew

  • 添加Homebrew Tap

在macOS安装Vapor的tap后,它会让homebrew拥有安装所有package的权限。

MrleedeMBP:YorkLee mrlee$ brew tap vapor/homebrew-tap
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/mrlee/Library/Caches/Homebrew..
==> Deleting /Library/Caches/Homebrew...
==> Updated Formulae
cromwell        gutenberg       nco             sslyze          wget
duplicity       ldns            pwntools        superlu
emscripten      mercurial       saldl           transmission
gcc             mingw-w64       socat           w3m
==> Deleted Formulae
pcap_dnsproxy

MrleedeMBP:YorkLee mrlee$ brew update
Already up-to-date.

安装vapor

brew install vapor
==> Installing vapor from vapor/tap
==> Downloading https://github.com/vapor/toolbox/releases/download/3.1.3/macOS-s
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws
######################################################################## 100.0%
🍺  /usr/local/Cellar/vapor/3.1.3: 4 files, 17.0MB, built in 24 seconds

常用命令

Commands:
         new Creates a new Vapor application from a template.
             Use --template=repo/template for github templates
             Use --template=full-url-here.git for non github templates
             Use --web to create a new web app
             Use --auth to create a new authenticated API app
             Use --api (default) to create a new API
       build Compiles the application.
         run Runs the compiled application.
       fetch Fetches the application's dependencies.
      update Updates your dependencies.
       clean Cleans temporary files--usually fixes
             a plethora of bizarre build errors.
        test Runs the application's tests.
       xcode Generates an Xcode project for development.
             Additionally links commonly used libraries.
     version Displays Vapor CLI version
       cloud Commands for interacting with Vapor Cloud.
  cloud-beta [BETA!] Commands for interacting with Vapor Cloud.
      heroku Commands to help deploy to Heroku.
    provider Commands to help manage providers.

创建第一个工程

MrleedeMBP:Desktop mrlee$ vapor new hello
Cloning Template [Done]
Updating Package Name [Done]
Initializing git repository [Done]

                                          **
                                        **~~**
                                      **~~~~~~**
                                    **~~~~~~~~~~**
                                  **~~~~~~~~~~~~~~**
                                **~~~~~~~~~~~~~~~~~~**
                              **~~~~~~~~~~~~~~~~~~~~~~**
                             **~~~~~~~~~~~~~~~~~~~~~~~~**
                            **~~~~~~~~~~~~~~~~~~~~~~~~~~**
                           **~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
                           **~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
                           **~~~~~~~~~~~~~~~~~~~~~++++~~~**
                            **~~~~~~~~~~~~~~~~~~~++++~~~**
                             ***~~~~~~~~~~~~~~~++++~~~***
                               ****~~~~~~~~~~++++~~****
                                  *****~~~~~~~~~*****
                                     *************
                            
                            _       __    ___   ___   ___
                           \ \  /  / /\  | |_) / / \ | |_)
                            \_\/  /_/--\ |_|   \_\_/ |_| \
                              a web framework for Swift

                        Project "HelloWorld" has been created.
                 Type `cd HelloWorld` to enter the project directory.
                Use `vapor cloud deploy` to host your project for free!
                                        Enjoy!

在创建工程时候可以指定模板

如果我们要创建一个网站,则可以用下面命令:

vapor new hello --template=web

Xocde打开工程

  • cd 到工程目录 例如:cd hello
  • 利用命令打开Xcode
MrleedeMBP:hello mrlee$ vapor xcode
Generating Xcode Project [Done]
Select the `Run` scheme to run.
Open Xcode project?
y/n> y

运行

run.png

结果

ruest.png

最后

欢迎广大iOS开发者入坑,技术交流QQ群:431296189

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 如果你想尝试使用swift来进行web开发,从现在开始吧。 Swift开源以来就有了许多服务器的框架,以下是目前g...
    leacode阅读 2,219评论 2 3
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,256评论 19 139
  • 1.我走在你风景如画的长廊,呼吸着一种甜蜜清新的空气。你不知道,你宛如一束带露的鲜花,在我心的庭院里洒落一地温馨。...
    美文头条阅读 316评论 1 2
  • 很喜欢一句话“没有人会突然改变,现在的自己是一次又一次自我选择之后叠加的结果”,而我的选择就是让自己慢慢变的强大,...
    艾Dora阅读 195评论 1 0