From 06e9d769ace3a746db55b25e52993710b92c1ec2 Mon Sep 17 00:00:00 2001 From: Mattes Mohr Date: Wed, 20 Mar 2024 19:08:24 +0100 Subject: [PATCH] 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 --- Package.swift | 9 +++++---- .../{plugin.swift => Plugin.swift} | 18 ++++++++++++------ .../{plugin.swift => Plugin.swift} | 0 .../Commands/Components/DeployCommand.swift | 4 ++-- .../Chapters/Design with Htmlkit.tutorial | 11 ++--------- .../view/{view-s10.swift => view-S10.swift} | 0 6 files changed, 21 insertions(+), 21 deletions(-) rename Plugins/ComponentsPlugin/{plugin.swift => Plugin.swift} (74%) rename Plugins/ConverterPlugin/{plugin.swift => Plugin.swift} (100%) rename Sources/HTMLKit/Documentation.docc/Tutorials/Resources/Snippets/view/{view-s10.swift => view-S10.swift} (100%) diff --git a/Package.swift b/Package.swift index 19654c66..394bdd52 100644 --- a/Package.swift +++ b/Package.swift @@ -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") @@ -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") diff --git a/Plugins/ComponentsPlugin/plugin.swift b/Plugins/ComponentsPlugin/Plugin.swift similarity index 74% rename from Plugins/ComponentsPlugin/plugin.swift rename to Plugins/ComponentsPlugin/Plugin.swift index f732a0f8..182f1d36 100644 --- a/Plugins/ComponentsPlugin/plugin.swift +++ b/Plugins/ComponentsPlugin/Plugin.swift @@ -18,7 +18,7 @@ struct ComponentsPlugin: CommandPlugin { USAGE: deploy --target-path ARGUMENTS: - - The path, where the converted files should be saved into. + - The destination directory where the files should be saved. """ print(explanation) @@ -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 { @@ -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)") } } diff --git a/Plugins/ConverterPlugin/plugin.swift b/Plugins/ConverterPlugin/Plugin.swift similarity index 100% rename from Plugins/ConverterPlugin/plugin.swift rename to Plugins/ConverterPlugin/Plugin.swift diff --git a/Sources/Commands/Components/DeployCommand.swift b/Sources/Commands/Components/DeployCommand.swift index a63983e8..d1a0b15e 100644 --- a/Sources/Commands/Components/DeployCommand.swift +++ b/Sources/Commands/Components/DeployCommand.swift @@ -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) { @@ -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) { diff --git a/Sources/HTMLKit/Documentation.docc/Tutorials/Chapters/Design with Htmlkit.tutorial b/Sources/HTMLKit/Documentation.docc/Tutorials/Chapters/Design with Htmlkit.tutorial index ca5563a6..29f5df71 100644 --- a/Sources/HTMLKit/Documentation.docc/Tutorials/Chapters/Design with Htmlkit.tutorial +++ b/Sources/HTMLKit/Documentation.docc/Tutorials/Chapters/Design with Htmlkit.tutorial @@ -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. diff --git a/Sources/HTMLKit/Documentation.docc/Tutorials/Resources/Snippets/view/view-s10.swift b/Sources/HTMLKit/Documentation.docc/Tutorials/Resources/Snippets/view/view-S10.swift similarity index 100% rename from Sources/HTMLKit/Documentation.docc/Tutorials/Resources/Snippets/view/view-s10.swift rename to Sources/HTMLKit/Documentation.docc/Tutorials/Resources/Snippets/view/view-S10.swift