Skip to content

Commit

Permalink
Revise the component plugin (#147)
Browse files Browse the repository at this point in the history
* Revise the component plugin

Add a more convenient way to deploy the files to the public directory of Vapor.

* Update the documentation
  • Loading branch information
mattesmohr authored Mar 20, 2024
1 parent 42760d4 commit 06e9d76
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
9 changes: 5 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ let package = Package(
capability: .command(
intent: .custom(
verb: "convert",
description: "Convert html content"),
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the converted file.")]
description: "Converts HTML markup into Swift syntax."),
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the file.")]
),
dependencies: [
.target(name: "ConvertCommand")
Expand All @@ -137,8 +137,9 @@ let package = Package(
capability: .command(
intent: .custom(
verb: "deploy",
description: "Deploy css files"),
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the minified css file.")]
description: "Deploys the CSS and JS files for the HTMLKit components."
),
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the files.")]
),
dependencies: [
.target(name: "DeployCommand")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ComponentsPlugin: CommandPlugin {
USAGE: deploy --target-path <path>
ARGUMENTS:
<target path> - The path, where the converted files should be saved into.
<target path> - The destination directory where the files should be saved.
"""

print(explanation)
Expand All @@ -31,7 +31,7 @@ struct ComponentsPlugin: CommandPlugin {

if let dependency = try context.dependency(named: "HTMLKit") {

if let target = try? dependency.package.targets(named: ["HTMLKitComponents"]).first {
if let target = try dependency.package.targets(named: ["HTMLKitComponents"]).first {
processArguments.insert(target.directory.string, at: 0)

} else {
Expand All @@ -46,19 +46,25 @@ struct ComponentsPlugin: CommandPlugin {
processArguments.insert(target, at: 1)

} else {
Diagnostics.error("Missing argument --target-path.")

if try context.dependency(named: "vapor") != nil {
processArguments.insert(context.package.directory.appending(subpath: "Public").string, at: 1)

} else {
Diagnostics.error("Missing argument --target-path.")
}
}

print("The deploy starts...")
print("The deployment starts...")

let process = try Process.run(URL(fileURLWithPath: tool.path.string), arguments: processArguments)
process.waitUntilExit()

if process.terminationReason == .exit && process.terminationStatus == 0 {
print("The deploy has finished.")
print("The deployment has finished.")

} else {
Diagnostics.error("The deploy has failed: \(process.terminationReason)")
Diagnostics.error("The deployment has failed: \(process.terminationReason)")
}

}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Sources/Commands/Components/DeployCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal struct DeployCommand {

let template = """
@charset "utf-8";
/* Copyright (c) 2019 - 2023 Vapor Community - Licensed under MIT (https://github.com/vapor-community/HTMLKit/blob/main/LICENSE) */
/* Copyright (c) 2019 - 2024 Vapor Community - Licensed under MIT (https://github.com/vapor-community/HTMLKit/blob/main/LICENSE) */
"""

if !manager.fileExists(atPath: target) {
Expand Down Expand Up @@ -94,7 +94,7 @@ internal struct DeployCommand {
private static func bundle(js source: String, to target: String, with filename: String, option: BundleOption = .minified) throws {

let template = """
/* Copyright (c) 2019 - 2023 Vapor Community - Licensed under MIT (https://github.com/vapor-community/HTMLKit/blob/main/LICENSE) */
/* Copyright (c) 2019 - 2024 Vapor Community - Licensed under MIT (https://github.com/vapor-community/HTMLKit/blob/main/LICENSE) */
"""

if !manager.fileExists(atPath: target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@
> Note: _The public folder contains any public files that will be served by your application._
}
@Step {
Open `Terminal` and change the directory to your project folder.
Make a right click on the project in the project navigator and select `ComponentsPlugin`. It will build the plugin and start the deployment.

@Code(name: "shell.swift", file: "shell-S1.swift", reset: true)
}
@Step {
Use the following command to start the deployment.

> Note: _HTMLKit creates the dependency folder at the given path._

@Code(name: "shell.swift", file: "shell-S2.swift", reset: true)
> Note: _HTMLKit creates a vendor folder at the public directory._
}
@Step {
Select `Product` > `Scheme` > `Edit Scheme` to set the working directory for your project.
Expand Down

0 comments on commit 06e9d76

Please sign in to comment.