Skip to content

Commit

Permalink
Updated to use ShellKit for downloading and unzipping
Browse files Browse the repository at this point in the history
  • Loading branch information
viaszkadi committed Oct 19, 2024
1 parent 28a5719 commit ce436f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
11 changes: 1 addition & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "d101b76e76d5b8396c0ead4a02b4bf6d6fcfc434915b3b10b0208df2f4f05e7c",
"originHash" : "0d221128da17c85390a02b1bd85d463806d537b671cd23cadad8713557a21f98",
"pins" : [
{
"identity" : "async-http-client",
Expand Down Expand Up @@ -252,15 +252,6 @@
"revision" : "3036ba9d69cf1fd04d433527bc339dc0dc75433d",
"version" : "5.1.3"
}
},
{
"identity" : "zipfoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/weichsel/ZIPFoundation.git",
"state" : {
"revision" : "02b6abe5f6eef7e3cbd5f247c5cc24e246efcfe0",
"version" : "0.9.19"
}
}
],
"version" : 3
Expand Down
4 changes: 0 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ let package = Package(
.package(url: "https://github.com/hummingbird-project/swift-mustache", from: "2.0.0"),
.package(url: "https://github.com/jpsim/Yams", from: "5.1.0"),
.package(url: "https://github.com/scinfu/SwiftSoup", from: "2.7.0"),
.package(url: "https://github.com/weichsel/ZIPFoundation.git", from: "0.9.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.1"),
] + deps,
targets: [
.executableTarget(
Expand All @@ -47,8 +45,6 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Logging", package: "swift-log"),
.product(name: "Hummingbird", package: "hummingbird"),
.product(name: "ZIPFoundation", package: "ZIPFoundation"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.target(name: "ToucanSDK"),
] + tdeps
),
Expand Down
31 changes: 10 additions & 21 deletions Sources/toucan-cli/Commands/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import ArgumentParser
import ToucanSDK
import Logging
import FileManagerKit
import ZIPFoundation
import AsyncHTTPClient
import NIOFoundationCompat
import ShellKit

extension Entrypoint {

Expand Down Expand Up @@ -40,10 +38,13 @@ extension Entrypoint {
fileManager: fileManager
)

logger.info("Preparing source files.")
try await source.resolve()

logger.info("Preparing theme files.")
try await theme.resolve()

logger.info("'\(siteDirectory)' was created successfully.")
logger.info("'\(siteDirectory)' was prepared successfully.")
}
catch {
logger.error("\(String(describing: error))")
Expand Down Expand Up @@ -101,27 +102,15 @@ extension Entrypoint.Init {
}

func resolve() async throws {
/// Downloading the ZIP file into a temporary directory.
let client = HTTPClient(eventLoopGroupProvider: .singleton)
defer { _ = client.shutdown() }
let shell = Shell()

let request = try HTTPClient.Request(
url: sourceUrl.absoluteString,
method: .GET
/// Downloading the ZIP file into a temporary directory.
try shell.run(
#"curl -L -o \#(zipUrl.path) \#(sourceUrl.absoluteString)"#
)
let response = try await client.execute(request: request).get()

guard
var body = response.body,
let data = body.readData(length: body.readableBytes)
else {
throw URLError(.badServerResponse)
}

try data.write(to: zipUrl)

/// Unzipping the file to a temporary directory.
try fileManager.unzipItem(at: zipUrl, to: url)
try shell.run(#"unzip \#(zipUrl.path) -d \#(url.path)"#)

/// Emptying the target directory. Git submodules can cause issues.
try? fileManager.removeItem(at: targetDirUrl)
Expand Down

0 comments on commit ce436f6

Please sign in to comment.