Skip to content

Commit

Permalink
Add xmlOutputFileName for androidConfig.colors (#213)
Browse files Browse the repository at this point in the history
Co-authored-by: Egor Sysoykin <[email protected]>
  • Loading branch information
tujh2 and Egor Sysoykin authored Jul 26, 2023
1 parent fbf596d commit 8d715b0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
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

0 comments on commit 8d715b0

Please sign in to comment.