Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
add sh versioning, add openapi server parameters (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
GErP83 authored Jul 15, 2024
1 parent 8a5c7ea commit 6ef683f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.swiftpm/xcode/xcshareddata/xcschemes/swift-plugins-Package.xcscheme
openapi/index.html
openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct RunOpenApiServerPlugin: CommandPlugin {
context: PackagePlugin.PluginContext,
arguments: [String]
) async throws {
try context.runScript(RunOpenApiServerScript())
try context.runScript(RunOpenApiServerScript(), arguments)
}

}
10 changes: 8 additions & 2 deletions Plugins/Shared/Extension + PluginContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import PackagePlugin
//https://forums.swift.org/t/difficulty-sharing-code-between-swift-package-manager-plugins/61690/6
extension PackagePlugin.PluginContext {

func createFile(fileName: String, fileContent: String) throws -> String {
let filePath = self.pluginWorkDirectory.appending(fileName).string
func createFile(
fileVersion: String = "",
fileName: String,
fileContent: String
) throws -> String {
let filePath = self.pluginWorkDirectory
.appending(fileVersion + fileName).string
let fm = FileManager.default

// check if file exist
Expand All @@ -40,6 +45,7 @@ extension PackagePlugin.PluginContext {
_ arguments: [String]? = nil
) throws {
let scriptFilePath = try createFile(
fileVersion: ScriptEnum.version.rawValue + "_",
fileName: script.shFile(),
fileContent: script.scriptToRun()
)
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Shared/ScriptEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

enum ScriptEnum: String {

case version = "4"

case head = """
#!/usr/bin/env bash
set -euo pipefail
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Shared/scripts/CheckOpenApiValidationScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
struct CheckOpenApiValidationScript: ScriptProtocol {

func shFile() -> String {
return "check-openapi-validation"
return "check-openapi-validation.sh"
}

func scriptToRun() -> String {
Expand Down
16 changes: 13 additions & 3 deletions Plugins/Shared/scripts/RunOpenApiServerScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
struct RunOpenApiServerScript: ScriptProtocol {

func shFile() -> String {
return "run-openapi-server"
return "run-openapi-server.sh"
}

func scriptToRun() -> String {
Expand All @@ -23,10 +23,20 @@ struct RunOpenApiServerScript: ScriptProtocol {
exit 0
fi
NAME="openapi-server"
PORT="8888:80"
while getopts ":n:p:": flag
do
case "${flag}" in
n) NAME=${OPTARG};;
p) PORT=${OPTARG};;
esac
done
# Run the Docker container to serve the OpenAPI files using Nginx
docker run --rm --name "run-openapi-server" \
docker run --rm --name "${NAME}" \
-v "${OPENAPI_YAML_LOCATION}:/usr/share/nginx/html" \
-p 8888:80 nginx
-p ${PORT} nginx
"""
}

Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This repository contains a set of Swift plugins designed to streamline various t
Add the repository as a dependency:

```swift
.package(url: "https://github.com/BinaryBirds/swift-plugins", from: "0.0.2"),
.package(url: "https://github.com/BinaryBirds/swift-plugins", from: "0.0.4"),
```

Update the packages and you are ready.
Expand Down Expand Up @@ -53,12 +53,12 @@ This plugin generates a list of contributors for the repository. It uses the git
Usage: `swift package --disable-sandbox generate-contributors-list`

### InstallSwiftFormatPlugin
This plugin installs the swift-format tool, the version can be optionally defined using the `-v` parameter.
This plugin installs the swift-format tool, the version can be optionally defined using the `-v` parameter. The default version is `510.1.0`.

Usage: `swift package --disable-sandbox install-swift-format`

### InstallSwiftOpenApiGeneratorPlugin
This plugin installs the Swift OpenAPI generator tool, the version can be optionally defined using the `-v` parameter.
This plugin installs the Swift OpenAPI generator tool, the version can be optionally defined using the `-v` parameter. The default version is `1.2.1`.

Usage: `swift package --disable-sandbox install-swift-openapi-generator`

Expand All @@ -73,14 +73,19 @@ This plugin cleans up build artifacts and other temporary files from the reposit
Usage: `swift package --disable-sandbox run-clean`

### RunOpenApiServerPlugin
This plugin serves the OpenAPI documentation using an Nginx server.
This plugin serves the OpenAPI documentation using an Nginx server. This try to run inside a Docker container.

Optional parameters:

- `-n` : add a custom identifier for the container, the default is `openapi-server`
- `-p` : add a custom port to bind it to the container, the default is `8888:80`

Usage: `swift package --disable-sandbox run-openapi-server`

### RunSwiftFormatPlugin
This plugin formats Swift code using the swift-format tool. It runs the tool on all Swift files in the repository, optionally fixing some of the issues if the `--fix` argument is provided.
This plugin checks/formats Swift code using the swift-format tool. It runs the tool on all Swift files in the repository, optionally fixing some of the issues if the `--fix` argument is provided.

Usage: `swift package --disable-sandbox run-swift-format` or `swift package--disable-sandbox run-swift-format --fix` for fixing
Usage: `swift package --disable-sandbox run-swift-format` for run lint or `swift package--disable-sandbox run-swift-format --fix` for fixing

## Makefile

Expand Down

0 comments on commit 6ef683f

Please sign in to comment.