Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xmlOutputFileName for androidConfig.colors #213

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/AndroidExport/AndroidColorExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import PathKit
final public class AndroidColorExporter: AndroidExporter {

private let output: AndroidOutput
private let xmlOutputFileName: String

public init(output: AndroidOutput) {
public init(output: AndroidOutput, xmlOutputFileName: String?) {
self.output = output
self.xmlOutputFileName = xmlOutputFileName ?? "colors.xml"
super.init(templatesPath: output.templatesPath)
}

Expand Down Expand Up @@ -45,7 +47,7 @@ final public class AndroidColorExporter: AndroidExporter {
let contents = try makeColorsContents(colorPairs, dark: dark)

let directoryURL = output.xmlOutputDirectory.appendingPathComponent(dark ? "values-night" : "values")
let fileURL = URL(string: "colors.xml")!
let fileURL = URL(string: xmlOutputFileName)!

return try makeFileContents(for: contents, directory: directoryURL, file: fileURL)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/FigmaExport/Input/Params.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct Params: Decodable {
let composePackageName: String?
}
struct Colors: Decodable {
let xmlOutputFileName: String?
let composePackageName: String?
}
struct Images: Decodable {
Expand Down
2 changes: 2 additions & 0 deletions Sources/FigmaExport/Resources/androidConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ android:
colors:
# [optional] The package to export the Jetpack Compose color code to. Note: To export Jetpack Compose code, also `mainSrc` and `resourcePackage` above must be set
composePackageName: "com.example"
# [optional] File name for XML file with exported colors (default is "colors.xml")
xmlOutputFileName: "colors.xml"
# Parameters for exporting icons
icons:
# Where to place icons relative to `mainRes`? FigmaExport clears this directory every time your execute `figma-export icons` command
Expand Down
8 changes: 5 additions & 3 deletions Sources/FigmaExport/Subcommands/ExportColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ extension FigmaExportCommand {
packageName: androidParams.colors?.composePackageName,
templatesPath: androidParams.templatesPath
)
let exporter = AndroidColorExporter(output: output)
let exporter = AndroidColorExporter(output: output, xmlOutputFileName: androidParams.colors?.xmlOutputFileName)
let files = try exporter.export(colorPairs: colorPairs)

let lightColorsFileURL = androidParams.mainRes.appendingPathComponent("values/colors.xml")
let darkColorsFileURL = androidParams.mainRes.appendingPathComponent("values-night/colors.xml")
let fileName = androidParams.colors?.xmlOutputFileName ?? "colors.xml"

let lightColorsFileURL = androidParams.mainRes.appendingPathComponent("values/" + fileName)
let darkColorsFileURL = androidParams.mainRes.appendingPathComponent("values-night/" + fileName)

try? FileManager.default.removeItem(atPath: lightColorsFileURL.path)
try? FileManager.default.removeItem(atPath: darkColorsFileURL.path)
Expand Down
2 changes: 1 addition & 1 deletion Tests/AndroidExportTests/AndroidColorExporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class AndroidColorExporterTests: XCTestCase {
// MARK: - Setup

func testExport() throws {
let exporter = AndroidColorExporter(output: output)
let exporter = AndroidColorExporter(output: output, xmlOutputFileName: nil)

let result = try exporter.export(colorPairs: [colorPair1, colorPair2])
XCTAssertEqual(result.count, 3)
Expand Down