Skip to content

Commit 167e308

Browse files
committed
Fix generating config file
1 parent af84a2d commit 167e308

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

Package.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ let package = Package(
3232
.product(name: "ArgumentParser", package: "swift-argument-parser"),
3333
.product(name: "Yams", package: "Yams"),
3434
.product(name: "Logging", package: "swift-log")
35-
],
36-
resources: [
37-
.copy("Resources/android.yaml"),
38-
.copy("Resources/ios.yaml")
3935
]
4036
),
4137

Sources/FigmaExport/Resources/android.yaml renamed to Sources/FigmaExport/Resources/androidConfig.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
let androidConfigFileContents = #"""
12
---
23
figma:
34
# Identifier of the file containing light color palette, icons and light images. To obtain a file id, open the file in the browser. The file id will be present in the URL after the word file and before the file name.
@@ -25,3 +26,5 @@ android:
2526
encoding: lossy
2627
# Encoding quality in percents. Only for lossy encoding.
2728
quality: 90
29+
30+
"""#

Sources/FigmaExport/Resources/ios.yaml renamed to Sources/FigmaExport/Resources/iOSConfig.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
let iosConfigFileContents = #"""
12
---
23
figma:
34
# Identifier of the file containing light color palette, icons and light images. To obtain a file id, open the file in the browser. The file id will be present in the URL after the word file and before the file name.
@@ -8,12 +9,12 @@ figma:
89
# [optional] Common export parameters
910
common:
1011
colors:
11-
# RegExp pattern for color name validation before exporting
12+
# RegExp pattern for color name validation before exporting
1213
nameValidateRegexp: '^[a-zA-Z_]+$' # RegExp pattern for: background, background_primary, widget_primary_background
1314
icons:
1415
# Name of the Figma's frame where icons components are located
1516
figmaFrameName: Colors
16-
# RegExp pattern for icon name validation before exporting
17+
# RegExp pattern for icon name validation before exporting
1718
nameValidateRegexp: '^(ic)_(\d\d)_([a-z0-9_]+)$' # RegExp pattern for: ic_24_icon_name, ic_24_icon
1819
images:
1920
# Name of the Figma's frame where image components are located
@@ -84,3 +85,5 @@ ios:
8485
generateLabels: true
8586
# Relative or absolute path to directory where to place UILabel for each text style (font) (Requred if generateLabels = true)
8687
labelsDirectory: "./Source/UIComponents/"
88+
89+
"""#

Sources/FigmaExport/Subcommands/GenerateConfigFile.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ extension FigmaExportCommand {
2020
func run() throws {
2121
let logger = Logger(label: "com.redmadrobot.figma-export")
2222

23-
let fileName: String
23+
let fileContents: String
2424
switch platform {
2525
case .android:
26-
fileName = "android"
26+
fileContents = androidConfigFileContents
2727
case .ios:
28-
fileName = "ios"
29-
}
30-
guard let url = Bundle.module.url(forResource: fileName, withExtension: "yaml") else {
31-
logger.info("Unable to generate config file.")
32-
return
28+
fileContents = iosConfigFileContents
3329
}
30+
let fileData = fileContents.data(using: .utf8)
3431

3532
let destination = FileManager.default.currentDirectoryPath + "/" + "figma-export.yaml"
3633
try? FileManager.default.removeItem(atPath: destination)
37-
try FileManager.default.copyItem(atPath: url.path, toPath: destination)
38-
39-
logger.info("Config file generated at:\n\(destination)")
34+
let success = FileManager.default.createFile(atPath: destination, contents: fileData, attributes: nil)
35+
if success {
36+
logger.info("Config file generated at:\n\(destination)")
37+
} else {
38+
logger.error("Unable to generate config file at:\n\(destination)")
39+
}
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)