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

Commit 6ef683f

Browse files
authored
add sh versioning, add openapi server parameters (#4)
1 parent 8a5c7ea commit 6ef683f

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ DerivedData/
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
99
.swiftpm/xcode/xcshareddata/xcschemes/swift-plugins-Package.xcscheme
10+
openapi/index.html
11+
openapi/openapi.yaml

Plugins/RunOpenApiServerPlugin/RunOpenApiServerPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct RunOpenApiServerPlugin: CommandPlugin {
1313
context: PackagePlugin.PluginContext,
1414
arguments: [String]
1515
) async throws {
16-
try context.runScript(RunOpenApiServerScript())
16+
try context.runScript(RunOpenApiServerScript(), arguments)
1717
}
1818

1919
}

Plugins/Shared/Extension + PluginContext.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ import PackagePlugin
1313
//https://forums.swift.org/t/difficulty-sharing-code-between-swift-package-manager-plugins/61690/6
1414
extension PackagePlugin.PluginContext {
1515

16-
func createFile(fileName: String, fileContent: String) throws -> String {
17-
let filePath = self.pluginWorkDirectory.appending(fileName).string
16+
func createFile(
17+
fileVersion: String = "",
18+
fileName: String,
19+
fileContent: String
20+
) throws -> String {
21+
let filePath = self.pluginWorkDirectory
22+
.appending(fileVersion + fileName).string
1823
let fm = FileManager.default
1924

2025
// check if file exist
@@ -40,6 +45,7 @@ extension PackagePlugin.PluginContext {
4045
_ arguments: [String]? = nil
4146
) throws {
4247
let scriptFilePath = try createFile(
48+
fileVersion: ScriptEnum.version.rawValue + "_",
4349
fileName: script.shFile(),
4450
fileContent: script.scriptToRun()
4551
)

Plugins/Shared/ScriptEnum.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
enum ScriptEnum: String {
88

9+
case version = "4"
10+
911
case head = """
1012
#!/usr/bin/env bash
1113
set -euo pipefail

Plugins/Shared/scripts/CheckOpenApiValidationScript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
struct CheckOpenApiValidationScript: ScriptProtocol {
88

99
func shFile() -> String {
10-
return "check-openapi-validation"
10+
return "check-openapi-validation.sh"
1111
}
1212

1313
func scriptToRun() -> String {

Plugins/Shared/scripts/RunOpenApiServerScript.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
struct RunOpenApiServerScript: ScriptProtocol {
88

99
func shFile() -> String {
10-
return "run-openapi-server"
10+
return "run-openapi-server.sh"
1111
}
1212

1313
func scriptToRun() -> String {
@@ -23,10 +23,20 @@ struct RunOpenApiServerScript: ScriptProtocol {
2323
exit 0
2424
fi
2525
26+
NAME="openapi-server"
27+
PORT="8888:80"
28+
while getopts ":n:p:": flag
29+
do
30+
case "${flag}" in
31+
n) NAME=${OPTARG};;
32+
p) PORT=${OPTARG};;
33+
esac
34+
done
35+
2636
# Run the Docker container to serve the OpenAPI files using Nginx
27-
docker run --rm --name "run-openapi-server" \
37+
docker run --rm --name "${NAME}" \
2838
-v "${OPENAPI_YAML_LOCATION}:/usr/share/nginx/html" \
29-
-p 8888:80 nginx
39+
-p ${PORT} nginx
3040
"""
3141
}
3242

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This repository contains a set of Swift plugins designed to streamline various t
77
Add the repository as a dependency:
88

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

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

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

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

6060
### InstallSwiftOpenApiGeneratorPlugin
61-
This plugin installs the Swift OpenAPI generator tool, the version can be optionally defined using the `-v` parameter.
61+
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`.
6262

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

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

7575
### RunOpenApiServerPlugin
76-
This plugin serves the OpenAPI documentation using an Nginx server.
76+
This plugin serves the OpenAPI documentation using an Nginx server. This try to run inside a Docker container.
77+
78+
Optional parameters:
79+
80+
- `-n` : add a custom identifier for the container, the default is `openapi-server`
81+
- `-p` : add a custom port to bind it to the container, the default is `8888:80`
7782

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

8085
### RunSwiftFormatPlugin
81-
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.
86+
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.
8287

83-
Usage: `swift package --disable-sandbox run-swift-format` or `swift package--disable-sandbox run-swift-format --fix` for fixing
88+
Usage: `swift package --disable-sandbox run-swift-format` for run lint or `swift package--disable-sandbox run-swift-format --fix` for fixing
8489

8590
## Makefile
8691

0 commit comments

Comments
 (0)