Skip to content

Commit 06e9d76

Browse files
authored
Revise the component plugin (#147)
* Revise the component plugin Add a more convenient way to deploy the files to the public directory of Vapor. * Update the documentation
1 parent 42760d4 commit 06e9d76

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

Package.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ let package = Package(
125125
capability: .command(
126126
intent: .custom(
127127
verb: "convert",
128-
description: "Convert html content"),
129-
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the converted file.")]
128+
description: "Converts HTML markup into Swift syntax."),
129+
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the file.")]
130130
),
131131
dependencies: [
132132
.target(name: "ConvertCommand")
@@ -137,8 +137,9 @@ let package = Package(
137137
capability: .command(
138138
intent: .custom(
139139
verb: "deploy",
140-
description: "Deploy css files"),
141-
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the minified css file.")]
140+
description: "Deploys the CSS and JS files for the HTMLKit components."
141+
),
142+
permissions: [.writeToPackageDirectory(reason: "The command needs the permission to create the files.")]
142143
),
143144
dependencies: [
144145
.target(name: "DeployCommand")

Plugins/ComponentsPlugin/plugin.swift renamed to Plugins/ComponentsPlugin/Plugin.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ComponentsPlugin: CommandPlugin {
1818
USAGE: deploy --target-path <path>
1919
2020
ARGUMENTS:
21-
<target path> - The path, where the converted files should be saved into.
21+
<target path> - The destination directory where the files should be saved.
2222
"""
2323

2424
print(explanation)
@@ -31,7 +31,7 @@ struct ComponentsPlugin: CommandPlugin {
3131

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

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

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

4848
} else {
49-
Diagnostics.error("Missing argument --target-path.")
49+
50+
if try context.dependency(named: "vapor") != nil {
51+
processArguments.insert(context.package.directory.appending(subpath: "Public").string, at: 1)
52+
53+
} else {
54+
Diagnostics.error("Missing argument --target-path.")
55+
}
5056
}
5157

52-
print("The deploy starts...")
58+
print("The deployment starts...")
5359

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

5763
if process.terminationReason == .exit && process.terminationStatus == 0 {
58-
print("The deploy has finished.")
64+
print("The deployment has finished.")
5965

6066
} else {
61-
Diagnostics.error("The deploy has failed: \(process.terminationReason)")
67+
Diagnostics.error("The deployment has failed: \(process.terminationReason)")
6268
}
6369

6470
}

Sources/Commands/Components/DeployCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal struct DeployCommand {
4444

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

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

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

100100
if !manager.fileExists(atPath: target) {

Sources/HTMLKit/Documentation.docc/Tutorials/Chapters/Design with Htmlkit.tutorial

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@
1313
> Note: _The public folder contains any public files that will be served by your application._
1414
}
1515
@Step {
16-
Open `Terminal` and change the directory to your project folder.
16+
Make a right click on the project in the project navigator and select `ComponentsPlugin`. It will build the plugin and start the deployment.
1717

18-
@Code(name: "shell.swift", file: "shell-S1.swift", reset: true)
19-
}
20-
@Step {
21-
Use the following command to start the deployment.
22-
23-
> Note: _HTMLKit creates the dependency folder at the given path._
24-
25-
@Code(name: "shell.swift", file: "shell-S2.swift", reset: true)
18+
> Note: _HTMLKit creates a vendor folder at the public directory._
2619
}
2720
@Step {
2821
Select `Product` > `Scheme` > `Edit Scheme` to set the working directory for your project.

0 commit comments

Comments
 (0)