diff --git a/Package.resolved b/Package.resolved index 3234d131..451db985 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "d101b76e76d5b8396c0ead4a02b4bf6d6fcfc434915b3b10b0208df2f4f05e7c", + "originHash" : "0d221128da17c85390a02b1bd85d463806d537b671cd23cadad8713557a21f98", "pins" : [ { "identity" : "async-http-client", @@ -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 diff --git a/Package.swift b/Package.swift index 5b5782b6..b9aa60e7 100644 --- a/Package.swift +++ b/Package.swift @@ -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( @@ -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 ), diff --git a/Sources/toucan-cli/Commands/Init.swift b/Sources/toucan-cli/Commands/Init.swift index bd11087f..e30d8fd4 100644 --- a/Sources/toucan-cli/Commands/Init.swift +++ b/Sources/toucan-cli/Commands/Init.swift @@ -3,9 +3,7 @@ import ArgumentParser import ToucanSDK import Logging import FileManagerKit -import ZIPFoundation -import AsyncHTTPClient -import NIOFoundationCompat +import ShellKit extension Entrypoint { @@ -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))") @@ -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)