Vapor-Day1

安装-Mac

查看当前swift版本

$ swift --version
Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0

梯子设置

$ export all_proxy="http://127.0.0.1:9999"

安装vapor

$ brew install vapor/tap/vapor-beta
-bash: brew: command not found

官翻机居然没得brew

安装brew

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

过了很久很久……
继续安装

$ brew install vapor/tap/vapor-beta
...
xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

又报错......

选择Xcode

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
$ brew install vapor/tap/vapor-beta

Updating Homebrew...

==>Installing vapor-beta from vapor/tap

==>Downloading https://github.com/vapor/toolbox/archive/18.0.0-beta.27.tar.gz

Already downloaded: /Users/luckin/Library/Caches/Homebrew/downloads/a17328593022736d0658058db21d6d516deb7c561c088ed71d02f0949e905954--toolbox-18.0.0-beta.27.tar.gz

==>swift build --disable-sandbox

==>mv .build/debug/vapor vapor-beta

  /usr/local/Cellar/vapor-beta/18.0.0-beta.27: 5 files, 7.2MB, built in 4 minutes 29 seconds

Luckins-Air:~ luckin$ vapor-beta --help

Usage: vapor-beta  

Vapor Toolbox (Server-side Swift web framework)

Commands:

       build Builds an app in the console.

       clean Cleans temporary files.

         new Generates a new app.

      heroku Commands for working with Heroku

  supervisor Commands for working with Supervisord

       xcode Opens an app in Xcode.

         run Runs an app from the console.

Use `vapor-beta  [--help,-h]` for more information on a command.

vapor就算安装好了

创建项目

$ vapor-beta new vapor_project
Cloning template...
name: vapor_project
Would you like to use Fluent?
y/n> y
fluent: Yes
db: MySQL
Generating project files
+ Package.swift
+ main.swift
+ configure.swift
+ routes.swift
+ Todo.swift
+ CreateTodo.swift
+ .gitkeep
+ TodoController.swift
+ AppTests.swift
+ Dockerfile
+ docker-compose.yml
+ .gitignore
+ .dockerignore
Creating git repository
Adding first commit
                                                        
                                       **               
                                     **~~**             
                                   **~~~~~~**           
                                 **~~~~~~~~~~**         
                               **~~~~~~~~~~~~~~**       
                             **~~~~~~~~~~~~~~~~~~**     
                           **~~~~~~~~~~~~~~~~~~~~~~**   
                          **~~~~~~~~~~~~~~~~~~~~~~~~**  
                         **~~~~~~~~~~~~~~~~~~~~~~~~~~** 
                        **~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
                        **~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
                        **~~~~~~~~~~~~~~~~~~~~~++++~~~**
                         **~~~~~~~~~~~~~~~~~~~++++~~~** 
                          ***~~~~~~~~~~~~~~~++++~~~***  
                            ****~~~~~~~~~~++++~~****    
                               *****~~~~~~~~~*****      
                                  *************         
                                                        
                         _       __    ___   ___   ___  
                        \ \  /  / /\  | |_) / / \ | |_) 
                         \_\/  /_/--\ |_|   \_\_/ |_| \ 
                           a web framework for Swift    
                                                        
                    Project vapor_project has been created!
                                       
              Use cd vapor_project to enter the project directory
                 Use vapor xcode to open the project in Xcode

用Xcode打开

$ cd vapor_project/
$ vapor-beta xcode
Opening project in Xcode.

进入漫长的等待……

等所有库都安装好了,就可以 command + R跑项目了。

访问 localhost:8080/hello , 看到 Hello, world! 就算项目跑起来了。

你可能感兴趣的:(Vapor-Day1)