From 8e00801c65663c0c4f8ebd8800d272abb8070406 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:07:36 +0100 Subject: [PATCH 1/5] Add vapor.code-snippets --- .gitignore | 1 - .vscode/vapor.code-snippets | 19 +++++++++++++++++++ manifest.yml | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .vscode/vapor.code-snippets diff --git a/.gitignore b/.gitignore index 920fa82..db2dd8b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ db.sqlite .env .env.* ! .env.example -.vscode diff --git a/.vscode/vapor.code-snippets b/.vscode/vapor.code-snippets new file mode 100644 index 0000000..6ddb8c4 --- /dev/null +++ b/.vscode/vapor.code-snippets @@ -0,0 +1,19 @@ +{ + "Endpoint": { + "prefix": "endpoint", + "body": [ + "@Sendable", + "func ${1:functionName}(req: Request) async throws -> ${2:returnValue} {", + "\t${3:statements}", + "}" + ], + "description": "Vapor: Endpoint function" + }, + "throw Abort": { + "prefix": "abort", + "body": [ + "throw Abort(${code})" + ], + "description": "Vapor: throw Abort" + } +} \ No newline at end of file diff --git a/manifest.yml b/manifest.yml index 513ef65..11dcb6e 100644 --- a/manifest.yml +++ b/manifest.yml @@ -47,6 +47,9 @@ variables: - name: leaf description: Would you like to use Leaf (templating)? type: bool + - name: vscode + description: Would you like to include Visual Studio Code snippets? + type: bool files: - file: Package.swift dynamic: true @@ -95,5 +98,9 @@ files: dynamic: true - file: docker-compose.yml dynamic: true + - folder: .vscode + if: vscode + files: + - file: vapor.code-snippets - .gitignore - .dockerignore From 4a04d4b7d9f4e7aa2584306f8f1bc39b9c875df5 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:26:30 +0100 Subject: [PATCH 2/5] Add more snippets --- .vscode/vapor.code-snippets | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.vscode/vapor.code-snippets b/.vscode/vapor.code-snippets index 6ddb8c4..89617d9 100644 --- a/.vscode/vapor.code-snippets +++ b/.vscode/vapor.code-snippets @@ -9,6 +9,31 @@ ], "description": "Vapor: Endpoint function" }, + "AsyncMiddleware": { + "prefix": "middleware", + "body": [ + "struct ${1:Name}Middleware: AsyncMiddleware {", + "\tfunc respond(to request: Request, chainingTo next: AsyncResponder) async throws -> Response {", + "\t\t${2:return try await next.respond(to: request)}", + "\t}", + "}" + ], + "description": "Vapor: AsyncMiddleware" + }, + "req.parameters.get": { + "prefix": "parameter", + "body": [ + "req.parameters.get(\"${2:parameterName}\")" + ], + "description": "Vapor: Extract parameter from request path" + }, + "try req.content.decode": { + "prefix": "decode", + "body": [ + "try req.content.decode(${1:Type}.self)" + ], + "description": "Vapor: Decode request content" + }, "throw Abort": { "prefix": "abort", "body": [ From 30ccd532a701518d8b93c352c9caea8100de7264 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:47:42 +0100 Subject: [PATCH 3/5] Update CI --- .github/workflows/auto-template-creation.yml | 10 +++++----- .github/workflows/test-template.yml | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/auto-template-creation.yml b/.github/workflows/auto-template-creation.yml index 20e505b..122acc1 100644 --- a/.github/workflows/auto-template-creation.yml +++ b/.github/workflows/auto-template-creation.yml @@ -30,19 +30,19 @@ jobs: include: # No Fluent or Leaf repo - repository: template-bare - flags: --no-fluent --no-leaf + flags: --no-fluent --no-leaf --no-vscode # SQLite repo - repository: template-fluent-sqlite - flags: --fluent.db sqlite --no-leaf + flags: --fluent.db sqlite --no-leaf --no-vscode # MySQL repo - repository: template-fluent-mysql - flags: --fluent.db mysql --no-leaf + flags: --fluent.db mysql --no-leaf --no-vscode # Postgres repo - repository: template-fluent-postgres - flags: --fluent.db postgres --no-leaf + flags: --fluent.db postgres --no-leaf --no-vscode # Postgres with Leaf repo - repository: template-fluent-postgres-leaf - flags: --fluent.db postgres --leaf + flags: --fluent.db postgres --leaf --no-vscode runs-on: ubuntu-24.04 steps: - name: Get token diff --git a/.github/workflows/test-template.yml b/.github/workflows/test-template.yml index 05c025d..ffe5ff5 100644 --- a/.github/workflows/test-template.yml +++ b/.github/workflows/test-template.yml @@ -67,6 +67,9 @@ jobs: leafflags: - '--leaf' - '--no-leaf' + vscodeflags: + - '--vscode' + - '--no-vscode' include: #- fluentflags: '--fluent.db mysql' # dbhostname: mysql @@ -110,7 +113,7 @@ jobs: toolbox/vapor new template-test \ --template "${CLONE_URL}" --branch "${HEAD_REF}" \ --no-commit -o template-test \ - ${{ matrix.fluentflags }} ${{ matrix.leafflags }} + ${{ matrix.fluentflags }} ${{ matrix.leafflags }} ${{ matrix.vscodeflags }} - name: Build and test template run: swift test --package-path template-test env: @@ -137,6 +140,9 @@ jobs: leafflags: - '--leaf' - '--no-leaf' + vscodeflags: + - '--vscode' + - '--no-vscode' needs: cache-toolbox runs-on: ubuntu-24.04 steps: @@ -154,6 +160,6 @@ jobs: toolbox/vapor new template-test \ --template "${CLONE_URL}" --branch "${HEAD_REF}" \ --no-commit -o template-test \ - ${{ matrix.fluentflags }} ${{ matrix.leafflags }} + ${{ matrix.fluentflags }} ${{ matrix.leafflags }} ${{ matrix.vscodeflags }} - name: Build Docker container run: docker compose --project-directory template-test build From 94316981152b0fae316a639dffb58b4938795387 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:55:42 +0100 Subject: [PATCH 4/5] Make `--vscode` a nested variable --- .github/workflows/test-template.yml | 10 ++-------- manifest.yml | 8 ++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-template.yml b/.github/workflows/test-template.yml index ffe5ff5..43306de 100644 --- a/.github/workflows/test-template.yml +++ b/.github/workflows/test-template.yml @@ -67,9 +67,6 @@ jobs: leafflags: - '--leaf' - '--no-leaf' - vscodeflags: - - '--vscode' - - '--no-vscode' include: #- fluentflags: '--fluent.db mysql' # dbhostname: mysql @@ -113,7 +110,7 @@ jobs: toolbox/vapor new template-test \ --template "${CLONE_URL}" --branch "${HEAD_REF}" \ --no-commit -o template-test \ - ${{ matrix.fluentflags }} ${{ matrix.leafflags }} ${{ matrix.vscodeflags }} + ${{ matrix.fluentflags }} ${{ matrix.leafflags }} --no-vscode - name: Build and test template run: swift test --package-path template-test env: @@ -140,9 +137,6 @@ jobs: leafflags: - '--leaf' - '--no-leaf' - vscodeflags: - - '--vscode' - - '--no-vscode' needs: cache-toolbox runs-on: ubuntu-24.04 steps: @@ -160,6 +154,6 @@ jobs: toolbox/vapor new template-test \ --template "${CLONE_URL}" --branch "${HEAD_REF}" \ --no-commit -o template-test \ - ${{ matrix.fluentflags }} ${{ matrix.leafflags }} ${{ matrix.vscodeflags }} + ${{ matrix.fluentflags }} ${{ matrix.leafflags }} --no-vscode - name: Build Docker container run: docker compose --project-directory template-test build diff --git a/manifest.yml b/manifest.yml index 11dcb6e..32e89e6 100644 --- a/manifest.yml +++ b/manifest.yml @@ -48,8 +48,12 @@ variables: description: Would you like to use Leaf (templating)? type: bool - name: vscode - description: Would you like to include Visual Studio Code snippets? - type: bool + description: Will you use Visual Studio Code for development? + type: nested + variables: + - name: snippets + description: Would you like to include Visual Studio Code snippets? + type: bool files: - file: Package.swift dynamic: true From cd14b05bd5765a7bdd0d472efb98626b518e290e Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:58:24 +0100 Subject: [PATCH 5/5] Fix `manifest.yml` --- manifest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.yml b/manifest.yml index 32e89e6..b6059c0 100644 --- a/manifest.yml +++ b/manifest.yml @@ -106,5 +106,6 @@ files: if: vscode files: - file: vapor.code-snippets + if: vscode.snippets - .gitignore - .dockerignore