diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index d57fb340..59845ed1 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -5,35 +5,11 @@ env: IMAGE_ID: $IMAGE_ID steps: - - label: ':react: Build React App' - command: make build REFRESH_L10N=1 - plugins: &plugins - - $CI_TOOLKIT_PLUGIN - - $NVM_PLUGIN - - - label: ':eslint: Lint React App' - command: make lint-js - plugins: *plugins - - label: ':javascript: Test JavaScript' command: make test-js plugins: *plugins - - label: ':android: Publish Android Library' - command: | - make build REFRESH_L10N=1 - echo "--- :android: Publishing Android Library" - ./android/gradlew -p ./android :gutenberg:prepareToPublishToS3 $(prepare_to_publish_to_s3_params) :gutenberg:publish - agents: - queue: android - plugins: *plugins - - - label: ':android: Test Android Library' - command: make test-android - agents: - queue: android - plugins: *plugins - - label: ':swift: Test Swift Package' - command: swift test + # With the HTML assets in the GutenbergKitResources package and ignored by Git, we need to generated on demand for the moment + command: make build && swift test plugins: *plugins diff --git a/Makefile b/Makefile index 7882bbef..c318d90f 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,7 @@ build: npm-dependencies prep-translations ## Build the project for all platforms @echo "--- :open_file_folder: Copying Build Products into place" rm -rf ./ios/Sources/GutenbergKit/Gutenberg/ ./android/Gutenberg/src/main/assets/ cp -r ./dist/. ./ios/Sources/GutenbergKit/Gutenberg/ + cp -r ./dist/. ./ios/Sources/GutenbergKitResources/Resources/ cp -r ./dist/. ./android/Gutenberg/src/main/assets .PHONY: build-swift-package diff --git a/Package.swift b/Package.swift index 9bb02fcb..d7104f1a 100644 --- a/Package.swift +++ b/Package.swift @@ -16,7 +16,11 @@ let package = Package( targets: [ .target( name: "GutenbergKit", - dependencies: ["SwiftSoup", "SVGView"], + dependencies: [ + "SwiftSoup", + "SVGView", + .target(name: "GutenbergKitResources") + ], path: "ios/Sources/GutenbergKit", exclude: [], resources: [.copy("Gutenberg")] @@ -29,6 +33,12 @@ let package = Package( resources: [ .process("Resources") ] + ), + + .target( + name: "GutenbergKitResources", + path: "ios/Sources/GutenbergKitResources", + resources: [.copy("Resources")] ) ] ) diff --git a/ios/Sources/GutenbergKitResources/Resources/.gitkeep b/ios/Sources/GutenbergKitResources/Resources/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/ios/Sources/GutenbergKitResources/Sources/GutenbergKitResources.swift b/ios/Sources/GutenbergKitResources/Sources/GutenbergKitResources.swift new file mode 100644 index 00000000..a8f95ed1 --- /dev/null +++ b/ios/Sources/GutenbergKitResources/Sources/GutenbergKitResources.swift @@ -0,0 +1,21 @@ +import Foundation + +struct GutenbergKitResources { + + /// Loads the Gutenberg CSS from the bundled assets. + public static func loadGutenbergCSS() -> String? { + guard let assetsURL = Bundle.module.url(forResource: "Gutenberg", withExtension: nil) else { + assertionFailure("Gutenberg resource not found in bundle") + return nil + } + + let assetsDirectory = assetsURL.appendingPathComponent("assets") + guard let files = try? FileManager.default.contentsOfDirectory(at: assetsDirectory, includingPropertiesForKeys: nil), + let cssURL = files.first(where: { $0.lastPathComponent.hasPrefix("index-") && $0.lastPathComponent.hasSuffix(".css") }), + let css = try? String(contentsOf: cssURL, encoding: .utf8) else { + assertionFailure("Failed to load Gutenberg CSS from bundle") + return nil + } + return css + } +}