diff --git a/Examples/AndroidExample/app/build.gradle b/Examples/AndroidExample/app/build.gradle
index 3fb80d5d..43555fb5 100644
--- a/Examples/AndroidExample/app/build.gradle
+++ b/Examples/AndroidExample/app/build.gradle
@@ -29,6 +29,12 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
+ sourceSets {
+ main {
+ res.srcDirs += "src/main/res/figma-export-icons"
+ res.srcDirs += "src/main/res/figma-export-images"
+ }
+ }
}
dependencies {
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_16_key_emergency.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_16_key_emergency.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_16_key_emergency.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_16_key_emergency.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_16_key_sandglass.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_16_key_sandglass.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_16_key_sandglass.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_16_key_sandglass.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_16_notification.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_16_notification.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_16_notification.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_16_notification.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_arrow_back.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_arrow_back.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_arrow_back.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_arrow_back.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_arrow_right.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_arrow_right.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_arrow_right.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_arrow_right.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_close.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_close.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_close.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_close.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_dots.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_dots.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_dots.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_dots.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_dropdown_down.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_dropdown_down.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_dropdown_down.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_dropdown_down.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_dropdown_up.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_dropdown_up.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_dropdown_up.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_dropdown_up.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_fullscreen_disable.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_fullscreen_disable.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_fullscreen_disable.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_fullscreen_disable.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_fullscreen_enable.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_fullscreen_enable.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_fullscreen_enable.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_fullscreen_enable.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable/ic_24_share_android.xml b/Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_share_android.xml
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable/ic_24_share_android.xml
rename to Examples/AndroidExample/app/src/main/res/figma-export-icons/drawable/ic_24_share_android.xml
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-hdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-hdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-hdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-hdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-hdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-hdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-mdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-mdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-mdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-mdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-mdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-mdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-hdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-hdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-hdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-hdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-hdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-hdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-mdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-mdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-mdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-mdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-mdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-mdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xhdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xhdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xhdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xhdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xhdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xhdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxhdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxhdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxhdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxhdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxhdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxhdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxxhdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxxhdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxxhdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxxhdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxxhdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-night-xxxhdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xhdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xhdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xhdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xhdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xhdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xhdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxhdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxhdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxhdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxhdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxhdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxhdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxxhdpi/img_zero_empty.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxxhdpi/img_zero_empty.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxxhdpi/img_zero_error.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxxhdpi/img_zero_error.webp
diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxxhdpi/img_zero_internet.webp
similarity index 100%
rename from Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.webp
rename to Examples/AndroidExample/app/src/main/res/figma-export-images/drawable-xxxhdpi/img_zero_internet.webp
diff --git a/Examples/AndroidExample/app/src/main/res/layout/fragment_icons.xml b/Examples/AndroidExample/app/src/main/res/layout/fragment_icons.xml
index 163ab5c7..2746dba9 100644
--- a/Examples/AndroidExample/app/src/main/res/layout/fragment_icons.xml
+++ b/Examples/AndroidExample/app/src/main/res/layout/fragment_icons.xml
@@ -80,7 +80,7 @@
(light: [ImagePack], dark: [ImagePack]?) {
- switch (platform, params.android?.images.format) {
+ switch (platform, params.android?.images?.format) {
case (.android, .png), (.android, .webp), (.ios, .none):
let lightImages = try loadPNGImages(
fileId: params.figma.lightFileId,
diff --git a/Sources/FigmaExport/Subcommands/ExportColors.swift b/Sources/FigmaExport/Subcommands/ExportColors.swift
index 6a33e5cf..81fc506c 100644
--- a/Sources/FigmaExport/Subcommands/ExportColors.swift
+++ b/Sources/FigmaExport/Subcommands/ExportColors.swift
@@ -107,6 +107,13 @@ extension FigmaExportCommand {
private func exportAndroidColors(colorPairs: [AssetPair], androidParams: Params.Android) throws {
let exporter = AndroidColorExporter(outputDirectory: androidParams.mainRes)
let files = exporter.export(colorPairs: colorPairs)
+
+ let lightColorsFileURL = androidParams.mainRes.appendingPathComponent("values/colors.xml")
+ let darkColorsFileURL = androidParams.mainRes.appendingPathComponent("values-night/colors.xml")
+
+ try? FileManager.default.removeItem(atPath: lightColorsFileURL.path)
+ try? FileManager.default.removeItem(atPath: darkColorsFileURL.path)
+
try fileWritter.write(files: files)
}
}
diff --git a/Sources/FigmaExport/Subcommands/ExportIcons.swift b/Sources/FigmaExport/Subcommands/ExportIcons.swift
index a98d2353..a548e286 100644
--- a/Sources/FigmaExport/Subcommands/ExportIcons.swift
+++ b/Sources/FigmaExport/Subcommands/ExportIcons.swift
@@ -44,7 +44,10 @@ extension FigmaExportCommand {
}
private func exportiOSIcons(client: FigmaClient, params: Params, logger: Logger) throws {
- guard let ios = params.ios else { return }
+ guard let ios = params.ios else {
+ logger.info("Nothing to do. You haven’t specified ios parameter in the config file.")
+ return
+ }
logger.info("Fetching icons info from Figma. Please wait...")
let loader = ImagesLoader(figmaClient: client, params: params, platform: .ios)
@@ -94,7 +97,10 @@ extension FigmaExportCommand {
}
private func exportAndroidIcons(client: FigmaClient, params: Params, logger: Logger) throws {
- guard let android = params.android else { return }
+ guard let android = params.android, let androidIcons = android.icons else {
+ logger.info("Nothing to do. You haven’t specified android.icons parameter in the config file.")
+ return
+ }
// 1. Get Icons info
logger.info("Fetching icons info from Figma. Please wait...")
@@ -130,9 +136,15 @@ extension FigmaExportCommand {
logger.info("Converting SVGs to XMLs...")
try svgFileConverter.convert(inputDirectoryPath: tempDirectoryURL.path)
- // Create output directory main/res/drawable/
- let outputDirectory = URL(fileURLWithPath: android.mainRes.path)
- .appendingPathComponent("drawable", isDirectory: true)
+ // Create output directory main/res/custom-directory/drawable/
+ let outputDirectory = URL(fileURLWithPath: android.mainRes
+ .appendingPathComponent(androidIcons.output)
+ .appendingPathComponent("drawable", isDirectory: true).path)
+
+ if filter == nil {
+ // Clear output directory
+ try? FileManager.default.removeItem(atPath: outputDirectory.path)
+ }
// 6. Move XML files to main/res/drawable/
localFiles = localFiles.map { fileContents -> FileContents in
diff --git a/Sources/FigmaExport/Subcommands/ExportImages.swift b/Sources/FigmaExport/Subcommands/ExportImages.swift
index 37962d8d..f616c013 100644
--- a/Sources/FigmaExport/Subcommands/ExportImages.swift
+++ b/Sources/FigmaExport/Subcommands/ExportImages.swift
@@ -44,7 +44,10 @@ extension FigmaExportCommand {
}
private func exportiOSImages(client: FigmaClient, params: Params, logger: Logger) throws {
- guard let ios = params.ios else { return }
+ guard let ios = params.ios else {
+ logger.info("Nothing to do. You haven’t specified ios parameter in the config file.")
+ return
+ }
logger.info("Fetching images info from Figma. Please wait...")
let loader = ImagesLoader(figmaClient: client, params: params, platform: .ios)
@@ -93,7 +96,10 @@ extension FigmaExportCommand {
}
private func exportAndroidImages(client: FigmaClient, params: Params, logger: Logger) throws {
- guard let android = params.android else { return }
+ guard let androidImages = params.android?.images else {
+ logger.info("Nothing to do. You haven’t specified android.images parameter in the config file.")
+ return
+ }
logger.info("Fetching images info from Figma. Please wait...")
let loader = ImagesLoader(figmaClient: client, params: params, platform: .android)
@@ -107,7 +113,7 @@ extension FigmaExportCommand {
)
let images = try processor.process(light: imagesTuple.light, dark: imagesTuple.dark).get()
- switch android.images.format {
+ switch androidImages.format {
case .svg:
try exportAndroidSVGImages(images: images, params: params, logger: logger)
case .png, .webp:
@@ -118,7 +124,10 @@ extension FigmaExportCommand {
}
private func exportAndroidSVGImages(images: [AssetPair], params: Params, logger: Logger) throws {
- guard let android = params.android else { return }
+ guard let android = params.android, let androidImages = android.images else {
+ logger.info("Nothing to do. You haven’t specified android.images parameter in the config file.")
+ return
+ }
// Create empty temp directory
let tempDirectoryLightURL = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
@@ -155,12 +164,22 @@ extension FigmaExportCommand {
}
logger.info("Writting files to Android Studio project...")
+
// Create output directory main/res/drawable/
- let lightDirectory = URL(fileURLWithPath: android.mainRes.path)
- .appendingPathComponent("drawable", isDirectory: true)
- let darkDirectory = URL(fileURLWithPath: android.mainRes.path)
- .appendingPathComponent("drawable-night", isDirectory: true)
+ let lightDirectory = URL(fileURLWithPath: android.mainRes
+ .appendingPathComponent(androidImages.output)
+ .appendingPathComponent("drawable", isDirectory: true).path)
+
+ let darkDirectory = URL(fileURLWithPath: android.mainRes
+ .appendingPathComponent(androidImages.output)
+ .appendingPathComponent("drawable-night", isDirectory: true).path)
+
+ if filter == nil {
+ // Clear output directory
+ try? FileManager.default.removeItem(atPath: lightDirectory.path)
+ try? FileManager.default.removeItem(atPath: darkDirectory.path)
+ }
// Move XML files to main/res/drawable/
localFiles = localFiles.map { fileContents -> FileContents in
@@ -187,7 +206,10 @@ extension FigmaExportCommand {
}
private func exportAndroidRasterImages(images: [AssetPair], params: Params, logger: Logger) throws {
- guard let android = params.android else { return }
+ guard let android = params.android, let androidImages = android.images else {
+ logger.info("Nothing to do. You haven’t specified android.images parameter in the config file.")
+ return
+ }
// Create empty temp directory
let tempDirectoryURL = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
@@ -210,7 +232,7 @@ extension FigmaExportCommand {
try fileWritter.write(files: localFiles)
// Convert to WebP
- if android.images.format == .webp, let options = android.images.webpOptions {
+ if androidImages.format == .webp, let options = androidImages.webpOptions {
logger.info("Converting PNG files to WebP...")
let converter: WebpConverter
switch (options.encoding, options.quality) {
@@ -226,13 +248,20 @@ extension FigmaExportCommand {
return file.changingExtension(newExtension: "webp")
}
}
+
+ if filter == nil {
+ // Clear output directory
+ let outputDirectory = URL(fileURLWithPath: android.mainRes.appendingPathComponent(androidImages.output).path)
+ try? FileManager.default.removeItem(atPath: outputDirectory.path)
+ }
logger.info("Writting files to Android Studio project...")
- // Move PNG/WebP files to main/res/drawable-XXXdpi/
+ // Move PNG/WebP files to main/res/figma-export-images/drawable-XXXdpi/
localFiles = localFiles.map { fileContents -> FileContents in
let directoryName = Drawable.scaleToDrawableName(fileContents.scale, dark: fileContents.dark)
- let directory = URL(fileURLWithPath: android.mainRes.path).appendingPathComponent(directoryName, isDirectory: true)
+ let directory = URL(fileURLWithPath: android.mainRes.appendingPathComponent(androidImages.output).path)
+ .appendingPathComponent(directoryName, isDirectory: true)
return FileContents(
destination: Destination(directory: directory, file: fileContents.destination.file),
dataFile: fileContents.destination.url