进击的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!

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

  • API --template=api 使用Fluent数据库提供json的api
  • Web --template=web 使用leaf模版创建的html网站
  • Auth --template=auth https://github.com/vapor/auth- template
  • Nodes-Vapor --template=nodes-vapor
  • Truemetal --template=truemetal
  • UserRepo --template=user/repo http://github.com/user/repo
  • FullPath --template=http://example.com/repo-path

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

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

你可能感兴趣的:(进击的vapor之vapor本地环境配置)