Update docs for new template (#795)

This commit is contained in:
Tim Condon 2023-04-27 20:16:32 +01:00 committed by GitHub
parent 383d3c914f
commit fb66441b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 174 additions and 219 deletions

View File

@ -18,11 +18,11 @@ vapor run serve --help
### Xcode
You can run commands in Xcode by adding arguments to the `Run` scheme. To do this, follow these steps:
You can run commands in Xcode by adding arguments to the `App` scheme. To do this, follow these steps:
- Choose `Run` scheme (to the right of play/stop buttons)
- Choose `App` scheme (to the right of play/stop buttons)
- Click "Edit Scheme"
- Choose "Run" product
- Choose "App" product
- Select "Arguments" tab
- Add the name of the command to "Arguments Passed On Launch" (i.e., `serve`)

View File

@ -18,11 +18,11 @@ vapor run serve --help
### Xcode
U kunt in Xcode commando's uitvoeren door argumenten toe te voegen aan het `Run` schema. Om dit te doen volgt u deze stappen:
U kunt in Xcode commando's uitvoeren door argumenten toe te voegen aan het `App` schema. Om dit te doen volgt u deze stappen:
- Kies `Run` schema (rechts van de play/stop knoppen)
- Kies `App` schema (rechts van de play/stop knoppen)
- Klik op "Edit Scheme"
- Kies "Run" product
- Kies "App" product
- Selecteer het tabblad "Arguments"
- Voeg de naam van het commando toe aan "Arguments Passed On Launch" (d.w.z. `serve`)

View File

@ -18,11 +18,11 @@ vapor run serve --help
### Xcode
你可以通过加入参数到 Xcode 的 `Run` scheme 以运行指令。通过一下三步做到这点:
你可以通过加入参数到 Xcode 的 `App` scheme 以运行指令。通过一下三步做到这点:
- 选择 `Run` scheme (在 运行/停止 按钮的右边)
- 选择 `App` scheme (在 运行/停止 按钮的右边)
- 选择 "Edit Scheme"
- 选择 "Run"
- 选择 "App"
- 选择 "Arguments" 这一栏
- 将指令的名词添加到 "Arguments Passed On Launch" (例如, `serve`)

View File

@ -39,7 +39,7 @@ Let's take a look at how you can get started using Queues.
The first step to using Queues is adding one of the drivers as a dependency to your project in your SwiftPM package manifest file. In this example, we'll use the Redis driver.
```swift
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
@ -49,10 +49,10 @@ let package = Package(
.package(url: "https://github.com/vapor/queues-redis-driver.git", from: "1.0.0"),
],
targets: [
.target(name: "App", dependencies: [
.executableTarget(name: "App", dependencies: [
// Other dependencies
.product(name: "QueuesRedisDriver", package: "queues-redis-driver")
]),
.target(name: "Run", dependencies: [.target(name: "App")]),
.testTarget(name: "AppTests", dependencies: [.target(name: "App")]),
]
)
@ -316,11 +316,11 @@ The Queues package also allows you to schedule jobs to occur at certain points i
The scheduler requires a separate worker process to be running, similar to the queue worker. You can start the worker by running this command:
```sh
swift run Run queues --scheduled
swift run App queues --scheduled
```
!!! tip
Workers should stay running in production. Consult your hosting provider to find out how to keep long-running processes alive. Heroku, for example, allows you to specify "worker" dynos like this in your Procfile: `worker: Run queues --scheduled`
Workers should stay running in production. Consult your hosting provider to find out how to keep long-running processes alive. Heroku, for example, allows you to specify "worker" dynos like this in your Procfile: `worker: App queues --scheduled`
### Creating a `ScheduledJob`

View File

@ -39,20 +39,20 @@ Laten we eens kijken hoe je aan de slag kunt met wachtrijen.
De eerste stap om Queues te gebruiken is het toevoegen van een van de stuurprogramma's als een afhankelijkheid van je project in je SwiftPM package manifest bestand. In dit voorbeeld gebruiken we het Redis stuurprogramma.
```swift
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "MyApp",
dependencies: [
/// Alle andere afhankelijkheden ...
/// Any other dependencies ...
.package(url: "https://github.com/vapor/queues-redis-driver.git", from: "1.0.0"),
],
targets: [
.target(name: "App", dependencies: [
.executableTarget(name: "App", dependencies: [
// Other dependencies
.product(name: "QueuesRedisDriver", package: "queues-redis-driver")
]),
.target(name: "Run", dependencies: [.target(name: "App")]),
.testTarget(name: "AppTests", dependencies: [.target(name: "App")]),
]
)
@ -311,11 +311,11 @@ Met het pakket Queues kunt u ook taken plannen die op bepaalde tijdstippen moete
De scheduler vereist dat een afzonderlijk workerproces draait, gelijkaardig aan de queue worker. U kunt de worker starten door dit commando uit te voeren:
```sh
swift run Run queues --scheduled
swift run App queues --scheduled
```
!!! tip
Workers moeten blijven draaien in productie. Raadpleeg uw hosting provider om uit te vinden hoe u langlopende processen in leven kunt houden. Heroku, bijvoorbeeld, staat je toe om "worker" dyno's te specificeren zoals dit in je Procfile: `worker: Run queues --scheduled`
Workers moeten blijven draaien in productie. Raadpleeg uw hosting provider om uit te vinden hoe u langlopende processen in leven kunt houden. Heroku, bijvoorbeeld, staat je toe om "worker" dyno's te specificeren zoals dit in je Procfile: `worker: App queues --scheduled`
### Een `ScheduledJob` Maken

View File

@ -39,7 +39,7 @@ Queues 也有基于社区的驱动程序:
使用队列的第一步是在 SwiftPM 文件中添加一个驱动程序作为项目的依赖项。在本例中,我们将使用 Redis 驱动程序。
```swift
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
@ -49,10 +49,10 @@ let package = Package(
.package(url: "https://github.com/vapor/queues-redis-driver.git", from: "1.0.0"),
],
targets: [
.target(name: "App", dependencies: [
.executableTarget(name: "App", dependencies: [
// Other dependencies
.product(name: "QueuesRedisDriver", package: "queues-redis-driver")
]),
.target(name: "Run", dependencies: [.target(name: "App")]),
.testTarget(name: "AppTests", dependencies: [.target(name: "App")]),
]
)
@ -316,11 +316,11 @@ Queues 包还允许你安排在特定时间点发生的 job。
调度程序需要一个独立的 worker 进程来运行,类似于队列 worker 进程。可以通过以下命令启动 worker
```sh
swift run Run queues --scheduled
swift run App queues --scheduled
```
!!! tip "建议"
生产环境应该保持 worker 一直运行。请咨询你的服务托管提供商了解如何使长时间运行的进程保持活动状态。例如Heroku 允许你在 Procfile 中像这样指定 “worker” dynos`worker: Run queues --scheduled`
生产环境应该保持 worker 一直运行。请咨询你的服务托管提供商了解如何使长时间运行的进程保持活动状态。例如Heroku 允许你在 Procfile 中像这样指定 “worker” dynos`worker: App queues --scheduled`
### 创建一个 `ScheduledJob`

View File

@ -52,7 +52,7 @@ print(foo) // String?
#### - Bestimmen
In Xcode können wir eine Prozessvariable über das Schema _Run_ festlegen.
In Xcode können wir eine Prozessvariable über das Schema _App_ festlegen.
Im Terminal gibt es hierzu den Befehl _export_:

View File

@ -61,13 +61,13 @@ export FOO=BAR
vapor run serve
```
When running your app in Xcode, you can set environment variables by editing the `Run` scheme.
When running your app in Xcode, you can set environment variables by editing the `App` scheme.
## .env (dotenv)
Dotenv files contain a list of key-value pairs to be automatically loaded into the environment. These files make it easy to configure environment variables without needing to set them manually.
Vapor will look for dotenv files in the current working directory. If you're using Xcode, make sure to set the working directory by editing the `Run` scheme.
Vapor will look for dotenv files in the current working directory. If you're using Xcode, make sure to set the working directory by editing the `App` scheme.
Assume the following `.env` file placed in your projects root folder:

View File

@ -61,13 +61,13 @@ export FOO=BAR
vapor run serve
```
Wanneer u uw app in Xcode uitvoert, kunt u omgevingsvariabelen instellen door het `Run` schema te bewerken.
Wanneer u uw app in Xcode uitvoert, kunt u omgevingsvariabelen instellen door het `App` schema te bewerken.
## .env (dotenv)
Dotenv bestanden bevatten een lijst van sleutel-waarde paren die automatisch in de omgeving geladen worden. Deze bestanden maken het gemakkelijk om omgevingsvariabelen te configureren zonder ze handmatig te hoeven instellen.
Vapor zal zoeken naar dotenv bestanden in de huidige werkmap. Als u Xcode gebruikt, zorg er dan voor dat u de werkdirectory instelt door het `Run` schema aan te passen.
Vapor zal zoeken naar dotenv bestanden in de huidige werkmap. Als u Xcode gebruikt, zorg er dan voor dat u de werkdirectory instelt door het `App` schema aan te passen.
Veronderstel dat het volgende `.env` bestand in de hoofdmap van je project staat:

View File

@ -61,13 +61,13 @@ export FOO=BAR
vapor run serve
```
当在 Xcode 中运行应用程序时,你可以通过编辑 `Run` scheme 来设置环境变量。
当在 Xcode 中运行应用程序时,你可以通过编辑 `App` scheme 来设置环境变量。
## .env (dotenv)
Dotenv 文件包含一个键值对列表,这些键值对将自动加载到环境中。这些文件使配置环境变量变得很容易,而不需要手动设置它们。
Vapor 将在当前工作目录中查找 `.env` 文件。如果你使用 Xcode确保通过编辑 `Run` scheme 设置工作目录。
Vapor 将在当前工作目录中查找 `.env` 文件。如果你使用 Xcode确保通过编辑 `App` scheme 设置工作目录。
假设以下 `.env` 文件放在你的项目根文件夹中:

View File

@ -68,7 +68,7 @@ export LOG_LEVEL=debug
vapor run serve
```
Beides kann über das Schema _Run_ in Xcode eingestellt werden. Im Abschnitt [Xcode](../getting-started/xcode.md) erklären wir dir, wie du ein Schema bearbeitest.
Beides kann über das Schema _App_ in Xcode eingestellt werden. Im Abschnitt [Xcode](../getting-started/xcode.md) erklären wir dir, wie du ein Schema bearbeitest.
## Einrichtung

View File

@ -81,7 +81,7 @@ export LOG_LEVEL=debug
vapor run serve
```
Both of these can be done in Xcode by editing the `Run` scheme.
Both of these can be done in Xcode by editing the `App` scheme.
## Configuration

View File

@ -82,7 +82,7 @@ export LOG_LEVEL=debug
vapor run serve
```
Beide kunnen worden gedaan in Xcode door het `Run` schema te bewerken.
Beide kunnen worden gedaan in Xcode door het `App` schema te bewerken.
## Configuratie

View File

@ -83,7 +83,7 @@ export LOG_LEVEL=debug
vapor run serve
```
这两种方法可以在 Xcode 中编辑 `Run`scheme模式进行修改。
这两种方法可以在 Xcode 中编辑 `App`scheme模式进行修改。
## 配置

View File

@ -268,7 +268,7 @@ print(app.routes.all) // [Route]
Vapor also ships with a `routes` command that prints all available routes in an ASCII formatted table.
```sh
$ swift run Run routes
$ swift run App routes
+--------+----------------+
| GET | / |
+--------+----------------+

View File

@ -295,7 +295,7 @@ print(app.routes.all) // [Route]
Vapor also ships with a `routes` command that prints all available routes in an ASCII formatted table.
```sh
$ swift run Run routes
$ swift run App routes
+--------+----------------+
| GET | / |
+--------+----------------+

View File

@ -295,7 +295,7 @@ print(app.routes.all) // [Route]
Vapor wordt ook geleverd met een `routes` commando dat alle beschikbare routes afdrukt in een ASCII geformatteerde tabel.
```sh
$ swift run Run routes
$ swift run App routes
+--------+----------------+
| GET | / |
+--------+----------------+

View File

@ -303,7 +303,7 @@ print(app.routes.all) // [Route]
Vapor 还附带了一个 `routes` 命令,该命令以 ASCII 格式的表格打印所有可用的路由。
```sh
$ swift run Run routes
$ swift run App routes
+--------+----------------+
| GET | / |
+--------+----------------+

View File

@ -135,7 +135,7 @@ With `fly.toml`'s `release_command`, you can ask Fly to run a certain command be
```
!!! note
The code snippet above assumes you are using the default Vapor Dockerfile which sets your app `ENTRYPOINT` to `./Run`. Concretely, this means that when you set `release_command` to `migrate -y`, Fly will call `./Run migrate -y`. If your `ENTRYPOINT` is set to a different value, you will need to adapt the value of `release_command`.
The code snippet above assumes you are using the default Vapor Dockerfile which sets your app `ENTRYPOINT` to `./App`. Concretely, this means that when you set `release_command` to `migrate -y`, Fly will call `./App migrate -y`. If your `ENTRYPOINT` is set to a different value, you will need to adapt the value of `release_command`.
Fly will run your release command in a temporary instance that has access to your internal Fly network, secrets, and environment variables.

View File

@ -136,7 +136,7 @@ Met `fly.toml`'s `release_command` kun je Fly vragen om een bepaald commando uit
```
!!! opmerking
De bovenstaande code snippet gaat ervan uit dat je de standaard Vapor Dockerfile gebruikt die je app `ENTRYPOINT` op `./Run` zet. Concreet betekent dit dat wanneer je `release_command` instelt op `migrate -y`, Fly `./Run migrate -y` zal aanroepen. Als je `ENTRYPOINT` op een andere waarde is ingesteld, moet je de waarde van `release_command` aanpassen.
De bovenstaande code snippet gaat ervan uit dat je de standaard Vapor Dockerfile gebruikt die je app `ENTRYPOINT` op `./App` zet. Concreet betekent dit dat wanneer je `release_command` instelt op `migrate -y`, Fly `./App migrate -y` zal aanroepen. Als je `ENTRYPOINT` op een andere waarde is ingesteld, moet je de waarde van `release_command` aanpassen.
Fly zal uw release commando uitvoeren in een tijdelijke instantie die toegang heeft tot uw interne Fly netwerk, geheimen en omgevingsvariabelen.

View File

@ -133,7 +133,7 @@ if let databaseURL = Environment.get("DATABASE_URL") {
```
!!! note "注意"
上面的代码片段假设你正在使用默认的 Vapor Dockerfile该文件将你的应用程序 `ENTRYPOINT` 设置为 `./Run`。具体来说,这意味着当你将 `release_command` 设置为 `migrate -y`Fly 将调用 `./Run migrate -y`。如果你的 `ENTRYPOINT` 设置为其他值,则需要调整 `release_command` 的值。
上面的代码片段假设你正在使用默认的 Vapor Dockerfile该文件将你的应用程序 `ENTRYPOINT` 设置为 `./App`。具体来说,这意味着当你将 `release_command` 设置为 `migrate -y`Fly 将调用 `./App migrate -y`。如果你的 `ENTRYPOINT` 设置为其他值,则需要调整 `release_command` 的值。
Fly 将在具有访问 Fly 内部网络、密钥和环境变量的临时实例中运行你的发布命令。

View File

@ -125,13 +125,13 @@ This creates **.swift-version** with `5.2.1` as its contents.
Heroku uses the **Procfile** to know how to run your app, in our case it needs to look like this:
```
web: Run serve --env production --hostname 0.0.0.0 --port $PORT
web: App serve --env production --hostname 0.0.0.0 --port $PORT
```
we can create this with the following terminal command
```bash
echo "web: Run serve --env production" \
echo "web: App serve --env production" \
"--hostname 0.0.0.0 --port \$PORT" > Procfile
```
@ -218,16 +218,16 @@ git commit -m "configured heroku database"
### Reverting your database
You can revert or run other commmands on heroku with the `run` command. Vapor's project is by default also named `Run`, so it reads a little funny.
You can revert or run other commmands on heroku with the `run` command.
To revert your database:
```bash
heroku run Run -- migrate --revert --all --yes --env production
heroku run App -- migrate --revert --all --yes --env production
```
To migrate
```bash
heroku run Run -- migrate --env production
heroku run App -- migrate --env production
```

View File

@ -130,7 +130,7 @@ web: Run serve --env production --hostname 0.0.0.0 --port $PORT
we kunnen dit maken met het volgende terminal commando
```bash
echo "web: Run serve --env production" \
echo "web: App serve --env production" \
"--hostname 0.0.0.0 --port \$PORT" > Procfile
```
@ -217,16 +217,16 @@ git commit -m "configured heroku database"
### Uw Database Terugdraaien
U kunt andere commando's op heroku terugdraaien of uitvoeren met het `run` commando. Het project van Vapor heet standaard ook `Run`, dus het leest een beetje raar.
U kunt andere commando's op heroku terugdraaien of uitvoeren met het `run` commando.
Om uw database terug te zetten:
```bash
heroku run Run -- migrate --revert --all --yes --env production
heroku run App -- migrate --revert --all --yes --env production
```
Om te migreren
```bash
heroku run Run -- migrate --env production
heroku run App -- migrate --env production
```

View File

@ -124,13 +124,13 @@ echo "5.2.1" > .swift-version
Heroku 使用 **Procfile** 来知道如何运行你的应用程序,在我们的示例中它需要这样配置:
```
web: Run serve --env production --hostname 0.0.0.0 --port $PORT
web: App serve --env production --hostname 0.0.0.0 --port $PORT
```
我们可以使用以下终端命令来创建它
```bash
echo "web: Run serve --env production" \
echo "web: App serve --env production" \
"--hostname 0.0.0.0 --port \$PORT" > Procfile
```
@ -217,15 +217,15 @@ git commit -m "configured heroku database"
### 重置你的数据库
你可以使用 `run` 命令在 heroku 上恢复或运行其他命令。 Vapor 的项目默认也被命名为 `Run`,所以读起来有点怪。
你可以使用 `run` 命令在 heroku 上恢复或运行其他命令。
要重置你的数据库请运行:
```bash
heroku run Run -- revert --all --yes --env production
heroku run App -- revert --all --yes --env production
```
如要迁移请运行以下命令:
```bash
heroku run Run -- migrate --env production
heroku run App -- migrate --env production
```

View File

@ -313,7 +313,7 @@ app.migrations.add(CreateGalaxy())
### Migrate
To run migrations, call `vapor run migrate` from the command line or add `migrate` as an argument to Xcode's Run scheme.
To run migrations, call `vapor run migrate` from the command line or add `migrate` as an argument to Xcode's App scheme.
```

View File

@ -313,7 +313,7 @@ app.migrations.add(CreateGalaxy())
### Migreren
Om migraties uit te voeren, roep `vapor run migrate` op vanaf de commandoregel of voeg `migrate` toe als argument aan Xcode's Run schema.
Om migraties uit te voeren, roep `vapor run migrate` op vanaf de commandoregel of voeg `migrate` toe als argument aan Xcode's App schema.
```
$ vapor run migrate

View File

@ -10,10 +10,10 @@ Lass uns einen Blick auf die Ordnerstruktur von Vapor werfen. Die Ordnerstruktur
│ │ ├── Controllers
│ │ ├── Migrations
│ │ ├── Models
│ │ ├── configure.swift
│ │ ├── configure.swift
│ │ ├── entrypoint.swift
│ │ └── routes.swift
│ └── Run
│ └── main.swift
├── Tests
│ └── AppTests
└── Package.swift
@ -33,7 +33,9 @@ app.middleware.use(fileMiddleware)
## Sources
Im Ordner _Sources_ befinden sich die eigentlichen Anwendungsdateien, unterteilt in die Unterordner _App_ und _Run_. Die beiden Unterordnern stellen Paketmodule dar. Mehr dazu findest du im Abschnitt [Swift Package Manager](spm.md).
Dieser Ordner enthält alle Swift-Quelldateien für Ihr Projekt.
Der Ordner der obersten Ebene, "App", spiegelt das Modul Ihres Pakets wider,
wie im [SwiftPM-Manifest](spm.md) angegeben.
### App
@ -55,18 +57,14 @@ Der Ordner _Models_ beinhaltet die Klassendefinitionen für die Entitäten.
Die Datei _configure.swift_ umfasst die Methode `configure(_:)`. Sie wird in der Datei `main.swift` aufgerufen um die Anwendung mit entsprechenden Angaben zu Endpunkten, zur Datenbank oder zu Providern zu konfigurieren.
#### entrypoint.swift
Diese Datei enthält den `@main`-Einstiegspunkt für die Anwendung, die Ihre Vapor-Anwendung einrichtet, konfiguriert und ausführt.
#### routes.swift
Die Datei _routes.swift_ beinhaltet die Methode `routes(_:)`. Sie wird am Ende von der `configure(_:)`-Methode aufgerufen um die Endpunkte zu registrieren.
### Run
Der Ordner _Run_ stellt die Ausführungsdatei dar.
#### main.swift
Die Datei _main.swift_ erstellt eine Instanz der Anwendung und führt diese aus.
## Tests
Für jedes Paketmodul kann ein entsprechender Ordner unter _Tests_ angelegt werden.

View File

@ -10,10 +10,10 @@ Now that you've created, built, and run your first Vapor app, let's take a momen
│ │ ├── Controllers
│ │ ├── Migrations
│ │ ├── Models
│ │ ├── configure.swift
│ │ ├── configure.swift
│ │ ├── entrypoint.swift
│ │ └── routes.swift
│ └── Run
│ └── main.swift
├── Tests
│ └── AppTests
└── Package.swift
@ -38,8 +38,8 @@ app.middleware.use(fileMiddleware)
## Sources
This folder contains all of the Swift source files for your project.
The top level folders, `App` and `Run`, reflect your package's modules,
as declared in the [SPM](spm.md) manifest.
The top level folder, `App`, reflect your package's module,
as declared in the [SwiftPM](spm.md) manifest.
### App
@ -61,18 +61,14 @@ The models folder is a great place to store your `Content` structs or Fluent `Mo
This file contains the `configure(_:)` function. This method is called by `main.swift` to configure the newly created `Application`. This is where you should register services like routes, databases, providers, and more.
#### entrypoint.swift
This file contains the `@main` entry point for the application that sets up, configures and runs your Vapor application.
#### routes.swift
This file contains the `routes(_:)` function. This method is called near the end of `configure(_:)` to register routes to your `Application`.
### Run
This is the main executable target, containing just the code needed to get your application up and running.
#### main.swift
This file creates and runs a configured instance of your Vapor `Application`.
## Tests
Each non-executable module in your `Sources` folder can have a corresponding folder in `Tests`. This contains code built on the `XCTest` module for testing your package. Tests can be run using `swift test` on the command line or pressing ⌘+U in Xcode.

View File

@ -10,10 +10,10 @@ Nu dat je je eerste Vapor app hebt gemaakt, gebouwd en uitgevoerd, laten we een
│ │ ├── Controllers
│ │ ├── Migrations
│ │ ├── Models
│ │ ├── configure.swift
│ │ ├── configure.swift
│ │ ├── entrypoint.swift
│ │ └── routes.swift
│ └── Run
│ └── main.swift
├── Tests
│ └── AppTests
└── Package.swift
@ -61,18 +61,14 @@ De models map is een goede plaats om uw `Content` structs of Fluent `Model`s op
Dit bestand bevat de `configure(_:)` functie. Deze methode wordt aangeroepen door `main.swift` om de nieuw aangemaakte `Application` te configureren. Dit is waar je services zoals routes, databases, providers, en meer moet registreren.
#### entrypoint.swift
Dit bestand bevat het `@main`-toegangspunt voor de toepassing die uw Vapor-toepassing instelt, configureert en uitvoert.
#### routes.swift
Dit bestand bevat de `routes(_:)` functie. Deze methode wordt aangeroepen aan het einde van `configure(_:)` om routes te registreren voor je `Application`.
### Run
Dit het het belangrijkste uitvoerbare doel, dat enkel de code bevat die nodig is om je applicatie aan de gang te krijgen.
#### main.swift
Dit bestand maakt een geconfigureerde instantie van uw Vapor `Application` aan en voert deze uit.
## Tests
Elke niet-uitvoerbare module in je `Sources` folder kan een overeenkomstige folder hebben in `Tests`. Deze bevalt code gebouwd op de `XCTest` module om je pakket te testen. Testen kunnen uitgevoerd worden door `swift test` te gebruiken op de command line of door ⌘+U in te drukken in Xcode.

View File

@ -11,11 +11,10 @@
│ │ ├── Controllers
│ │ ├── Migrations
│ │ ├── Models
│ │ ├── app.swift
│ │ ├── configure.swift
│ │ ├── configure.swift
│ │ ├── entrypoint.swift
│ │ └── routes.swift
│ └── Run
│ └── main.swift
├── Tests
│ └── AppTests
└── Package.swift
@ -39,7 +38,7 @@ app.middleware.use(fileMiddleware)
## Sources
该文件夹包含项目的所有 Swift 代码源文件。文件夹 `App``Run` 反应软件包的模块,例如这篇 [SPM](spm.zh.md) 文章中所述
此文件夹包含项目的所有 Swift 源文件。 顶级文件夹“App”反映了您的包的模块如 [SwiftPM](spm.md) 清单中声明的那样
### App
@ -61,18 +60,14 @@ models 文件夹常用于存放 `Content` 和 Fluent `Model` 的类或结构体
这个文件包含 `configure(_:)` 函数,`main.swift` 调用这个方法用以配置新创建的 `Application` 实例。你可以在这里注册诸如路由、数据库、providers 等服务。
#### entrypoint.swift
该文件包含用于设置、配置和运行 Vapor 应用程序的应用程序的“@main”入口点。
#### routes.swift
这个文件包含 `routes(_:)` 方法,它会在 `configure(_:)` 结尾处被调用,用以将路由注册到你的`Application`。
### Run
这是主要的可执行目标,只包含启动和运行应用程序所需的代码。
#### main.swift
这个文件创建并运行一个配置好的 `Application` 实例。
## Tests
`Sources` 文件夹中的每个不可运行的模块在 `Tests` 中都可以创建一个对应的文件夹,包含 `XCTest` 模块上构建的用例,用来测试你的代码。可以在命令行使用 `swift test`或在 Xcode 中按 `⌘+U` 来进行测试。

View File

@ -29,7 +29,7 @@ Je nach System oder Entwicklungsumgebung muss das Projekt unterschiedlich ausgef
open Package.swift
```
Xcode öffnet sich und lädt zu Beginn alle notwendigen Paketverweise. Nach dem Laden sollte dir Xcode zur Verfügung stehen. Wähle anschließend in der Mitte eine Schema (oft einfach nur "My Mac") aus. Starte nun das Projekt über die Menüpunkte _Product_ > _Run_. Du solltest nun in der Konsole einen Eintrag wie diesen sehen:
Xcode öffnet sich und lädt zu Beginn alle notwendigen Paketverweise. Nach dem Laden sollte dir Xcode zur Verfügung stehen. Wähle anschließend in der Mitte eine Schema (oft einfach nur "My Mac") aus. Starte nun das Projekt über die Menüpunkte _Product_ > _App_. Du solltest nun in der Konsole einen Eintrag wie diesen sehen:
```sh
[ INFO ] Server starting on http://127.0.0.1:8080

View File

@ -7,27 +7,28 @@
Das Herzstück des Paketmanagers ist die Paketbeschreibung. Sie befindet sich im Hauptverzeichnis eines Paketes. Die Beschreibung beinhaltet unter anderem Angaben zu Swift-Tools, den Paketnamen, dem Paketinhalt und die Abhängigkeiten.
```swift
/// [Package.swift]
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "app",
name: "MyApp",
platforms: [
.macOS(.v10_15)
],
products: [
.executable(name: "Run", targets: ["Run"]),
.library(name: "App", targets: ["App"]),
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.76.0"),
],
targets: [
.target(name: "App", dependencies: [.product(name: "Vapor", package: "vapor")]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
.executableTarget(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
]
),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)
```
@ -42,11 +43,7 @@ Der Parameter _Name_ legt den Paketnamen fest.
#### - Platforms
Der Parameter _Platforms_ beschreibt für welche Systeme letzten Endes das Paket sein soll. Wenn z.B. als Plattform `.macOS(.v10.14)` angegeben wird, wird macOS Mojave oder neuer erwartet.
#### - Products
Der Parameter _Products_ fasst die Targets zusammen.
Der Parameter _Platforms_ beschreibt für welche Systeme letzten Endes das Paket sein soll. Wenn z.B. als Plattform `.macOS(.v12)` angegeben wird, wird macOS 12 oder neuer erwartet.
#### - Dependencies
@ -54,7 +51,7 @@ Dependencies sind Paketverweise, auf die das Paket aufbaut und daher für die Au
#### - Targets
Targets sind Module, Dateien oder Tests. Vapor-Anwendungen beinhalten bis zu drei Targets.
Targets sind Module, Dateien oder Tests. Vapor-Anwendungen beinhalten bis zu zwei Targets.
### Ordnerstruktur
@ -63,10 +60,8 @@ Die Ordnerstruktur eines Paketes sieht wie folgt aus:
```
.
├── Sources
│ ├── App
│ │ └── (Source code)
│ └── Run
│ └── main.swift
│ └── App
│ └── (Source code)
├── Tests
│ └── AppTests
└── Package.swift

View File

@ -11,28 +11,30 @@ The first place SPM looks in your project is the package manifest. This should a
Take a look at this example Package manifest.
```swift
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "app",
name: "MyApp",
platforms: [
.macOS(.v10_15)
],
products: [
.executable(name: "Run", targets: ["Run"]),
.library(name: "App", targets: ["App"]),
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.76.0"),
],
targets: [
.target(name: "App", dependencies: [.product(name: "Vapor", package: "vapor")]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
.executableTarget(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
]
),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)
```
Each part of the manifest is explained in the following sections.
@ -47,29 +49,20 @@ The first argument to `Package` is the package's name. If the package is public,
### Platforms
The `platforms` array specifies which platforms this package supports. By specifying `.macOS(.v10_14)` this package requires macOS Mojave or greater. When Xcode loads this project, it will automatically set the minimum deployment version to 10.14 so that you can use all available APIs.
### Products
Products are targets that your package produces when built. In this package, there are two targets. A library and an executable.
The `platforms` array specifies which platforms this package supports. By specifying `.macOS(.v12)` this package requires macOS 12 or later. When Xcode loads this project, it will automatically set the minimum deployment version to macOS 12 so that you can use all available APIs.
### Dependencies
Dependencies are other SPM packages that your package relies on. All Vapor applications rely on the Vapor package, but you can add as many other dependencies as you want.
In the above example, you can see [vapor/vapor](https://github.com/vapor/vapor) version 4.0.0 or later is a dependency of this package. When you add a dependency to your package, you must next signal which [targets](#targets) depend on
In the above example, you can see [vapor/vapor](https://github.com/vapor/vapor) version 4.76.0 or later is a dependency of this package. When you add a dependency to your package, you must next signal which [targets](#targets) depend on
the newly available modules.
### Targets
Targets are all of the modules, executables, and tests that your package contains. Most Vapor apps will have three targets, although you can add as many as you like to organize your code. Each target declares which modules it depends on. You must add module names here in order to import them in your code. A target can depend on other targets in your project or any modules exposed by packages you've added to
Targets are all of the modules, executables, and tests that your package contains. Most Vapor apps will have two targets, although you can add as many as you like to organize your code. Each target declares which modules it depends on. You must add module names here in order to import them in your code. A target can depend on other targets in your project or any modules exposed by packages you've added to
the [main dependencies](#dependencies) array.
!!! tip
Executable targets (targets that contain a `main.swift` file) cannot be imported by other modules.
This is why Vapor has both an `App` and a `Run` target.
Any code you include in `App` can be tested in the `AppTests`.
## Folder Structure
Below is the typical folder structure for an SPM package.
@ -77,16 +70,14 @@ Below is the typical folder structure for an SPM package.
```
.
├── Sources
│ ├── App
│ │ └── (Source code)
│ └── Run
│ └── main.swift
│ └── App
│ └── (Source code)
├── Tests
│ └── AppTests
└── Package.swift
```
Each `.target` corresponds to a folder in the `Sources` folder.
Each `.target` or `.executableTarget` corresponds to a folder in the `Sources` folder.
Each `.testTarget` corresponds to a folder in the `Tests` folder.
## Package.resolved

View File

@ -11,28 +11,30 @@ De eerste plaats waar SPM kijkt in uw project is het package manifest. Dit moet
Een voorbeeld van een package manifest kan hieronder gevonden worden.
```swift
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "app",
name: "MyApp",
platforms: [
.macOS(.v10_15)
],
products: [
.executable(name: "Run", targets: ["Run"]),
.library(name: "App", targets: ["App"]),
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.76.0"),
],
targets: [
.target(name: "App", dependencies: [.product(name: "Vapor", package: "vapor")]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
.executableTarget(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
]
),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)
```
Elk onderdeel van het manifest wordt in de volgende secties toegelicht.
@ -47,11 +49,7 @@ Het eerste argument voor `Package` is de naam van het pakket. Als het pakket pub
### Platforms
De `platforms` array specificeert welke platformen dit pakket ondersteunt. Door `.macOS(.v10_14)` op te geven heeft dit pakket macOS Mojave of hoger nodig. Wanneer Xcode dit project laadt, zal het automatisch de minimale deployment versie op 10.14 zetten, zodat je alle beschikbare APIs kunt gebruiken.
### Products
Producten zijn targets die je package produceert als het gebouwd is. In dit pakket zijn er twee targets. Een bibliotheek en een uitvoerbaar bestand.
De `platforms` array specificeert welke platformen dit pakket ondersteunt. Door `.macOS(.v12)` op te geven heeft dit pakket macOS 12 of hoger nodig. Wanneer Xcode dit project laadt, zal het automatisch de minimale deployment versie op macOS 12 zetten, zodat je alle beschikbare APIs kunt gebruiken.
### Dependencies
@ -62,14 +60,9 @@ de nieuw beschikbare modules.
### Targets
Targets zijn alle modules, executables, en testen die je package bevat. De meeste Vapor applicaties zullen drie targets hebben, hoewel je er zoveel kunt toevoegen als je wilt om je code te organiseren. Elke target verklaart van welke modules het afhankelijk is. Je moet hier namen van modules toevoegen om ze te kunnen importeren in je code. Een target kan afhangen van andere targets in je project of van modules die je hebt toegevoegd aan
Targets zijn alle modules, executables, en testen die je package bevat. De meeste Vapor applicaties zullen twee targets hebben, hoewel je er zoveel kunt toevoegen als je wilt om je code te organiseren. Elke target verklaart van welke modules het afhankelijk is. Je moet hier namen van modules toevoegen om ze te kunnen importeren in je code. Een target kan afhangen van andere targets in je project of van modules die je hebt toegevoegd aan
de [main dependencies](#dependencies) array.
!!! tip
Executable targets (targets die een `main.swift` bestand bevatten) kunnen niet door andere modules worden geïmporteerd.
Dit is de reden waarom Vapor zowel een `App` als een `Run` target heeft.
Alle code die u in `App` opneemt kan getest worden in de `AppTests`.
## Folder Structure
Hieronder ziet u de typische mappenstructuur voor een SPM-pakket.
@ -77,16 +70,14 @@ Hieronder ziet u de typische mappenstructuur voor een SPM-pakket.
```
.
├── Sources
│ ├── App
│ │ └── (Source code)
│ └── Run
│ └── main.swift
│ └── App
│ └── (Source code)
├── Tests
│ └── AppTests
└── Package.swift
```
Elk `.target` komt overeen met een map in de `Sources` map.
Elk `.target` of `.executableTarget` komt overeen met een map in de `Sources` map.
Elk `.testTarget` komt overeen met een map in de `Tests` map.
## Package.resolved

View File

@ -11,28 +11,30 @@ SPM 在项目中查找的第一项是 package 清单。它应始终位于项目
看一下这个示例:
```swift
// swift-tools-version:5.2
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "app",
name: "MyApp",
platforms: [
.macOS(.v10_15)
],
products: [
.executable(name: "Run", targets: ["Run"]),
.library(name: "App", targets: ["App"]),
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.76.0"),
],
targets: [
.target(name: "App", dependencies: [.product(name: "Vapor", package: "vapor")]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
.executableTarget(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
]
),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)
```
下面将对这段代码的各部分进行说明。
@ -47,11 +49,7 @@ let package = Package(
### Platforms
`platforms` 数组指定此程序包支持的平台和版本。通过指定 `.macOS.v10_14`,说明此软件包需要 macOS Mojave 或更高版本。 Xcode 加载该项目时,它将最低部署版本设置为 10.14,以便你可以使用所有可用的 API。
### Products
products 字段代表 package 构建的时候要生成的 targets。示例中有两个 target一个是库另一个是可执行文件。
`platforms` 数组指定此程序包支持的平台和版本。通过指定 `.macOS.v12`,说明此软件包需要 macOS 12 或更高版本。 Xcode 加载该项目时,它将最低部署版本设置为 macOS 12以便你可以使用所有可用的 API。
### Dependencies
@ -61,10 +59,7 @@ dependencies 字段代表项目需要依赖的 package。所有 Vapor 应用都
### Targets
Targets 是你的 package 里包含 modules、executables 以及 tests 总和。虽然可以添加任意多的 targets 来组织代码,但大部分 Vapor 应用有 3 个 target 就足够了。每个 target 声明了它依赖的 module。为了在代码中可以 import 这些 modules ,你必须在这里添加 module 名字。一个 target 可以依赖于工程中其它的 target 或者任意你添加在 [dependencies](#dependencies) 数组中且暴露出来的 modules。
!!! tip "建议"
可运行 targets包含 `main.swift` 文件的 target不能被其它 modules 导入。这就是为什么 Vapor 会有 `App``Run` 两种 target。任何包含在 App 中的代码都可以在 `AppTests` 中被测试验证。
Targets 是你的 package 里包含 modules、executables 以及 tests 总和。虽然可以添加任意多的 targets 来组织代码,但大部分 Vapor 应用有 2 个 target 就足够了。每个 target 声明了它依赖的 module。为了在代码中可以 import 这些 modules ,你必须在这里添加 module 名字。一个 target 可以依赖于工程中其它的 target 或者任意你添加在 [dependencies](#dependencies) 数组中且暴露出来的 modules。
## 目录结构
@ -73,16 +68,14 @@ Targets 是你的 package 里包含 modules、executables 以及 tests 总和。
```
.
├── Sources
│ ├── App
│ │ └── (Source code)
│ └── Run
│ └── main.swift
│ └── App
│ └── (Source code)
├── Tests
│ └── AppTests
└── Package.swift
```
每个 `.target` 对应 `Sources` 中的一个文件夹。
每个 `.target` `.executableTarget` 对应 `Sources` 中的一个文件夹。
每个 `.testTarget` 对应 `Tests` 中的一个文件夹。
## Package.resolved

View File

@ -10,7 +10,7 @@
[ WARNING ] No custom working directory set for this scheme, using /path/to/DerivedData/project-abcdef/Build/
```
Um das Problem zu lösen, musst du den Pfad zu deinem Projekt in Schemen-Editor hinterlegen. Rufe über die den Menüpunkte _Products > Scheme > Edit Scheme..._ den Editor auf und wähle das Schema _Run_ aus.
Um das Problem zu lösen, musst du den Pfad zu deinem Projekt in Schemen-Editor hinterlegen. Rufe über die den Menüpunkte _Products > Scheme > Edit Scheme..._ den Editor auf und wähle das Schema _App_ aus.
Klicke in der rechten Fensterhälfte auf den Reiter _Options_ und gebe unter dem Punkt _Working Directory_ den Pfad zu deinem Projekt mit an.

View File

@ -22,7 +22,7 @@ Select _Edit Scheme..._ from the dropdown.
![Xcode Scheme Menu](../images/xcode-scheme-menu.png)
In the scheme editor, choose the _Run_ action and the _Options_ tab. Check _Use custom working directory_ and enter the path to your project's root folder.
In the scheme editor, choose the _App_ action and the _Options_ tab. Check _Use custom working directory_ and enter the path to your project's root folder.
![Xcode Scheme Options](../images/xcode-scheme-options.png)

View File

@ -22,7 +22,7 @@ Selecteer _Edit Scheme..._ in de dropdown.
![Xcode Scheme Menu](../images/xcode-scheme-menu.png)
Kies in de schema editor de actie _Run_ en het tabblad _Options_. Vink _Use custom working directory_ aan en voer het pad in naar de hoofdmap van uw project.
Kies in de schema editor de actie _App_ en het tabblad _Options_. Vink _Use custom working directory_ aan en voer het pad in naar de hoofdmap van uw project.
![Xcode Scheme Options](../images/xcode-scheme-options.png)

View File

@ -22,7 +22,7 @@ Xcode 将默认在 _DerivedData_ 目录运行项目。这与项目的根目录
![Xcode Scheme Menu](../images/xcode-scheme-menu.png)
在 scheme 编辑器中,选择 _Run_ action 以及 _Options_ tab 页。选中 _Use custom working directory_ 然后输入你项目根目录。
在 scheme 编辑器中,选择 _App_ action 以及 _Options_ tab 页。选中 _Use custom working directory_ 然后输入你项目根目录。
![Xcode Scheme Options](../images/xcode-scheme-options.png)