Skip to content

Commit b26d452

Browse files
committed
Add command to generate default config
Closes #31
1 parent a68f506 commit b26d452

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.2
1+
// swift-tools-version:5.3
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -32,6 +32,10 @@ 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")
3539
]
3640
),
3741

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,19 @@ Argument `-i` or `-input` specifies path to FigmaExport configuration file `figm
318318

319319
### Configuration
320320

321-
All available configuration options see in the [CONFIG.md](CONFIG.md) file.
321+
All available configuration options described in the [CONFIG.md](CONFIG.md) file.
322322

323323
Example of `figma-export.yaml` file for iOS project — [Examples/Example/figma-export.yaml](./Examples/Example/figma-export.yaml)
324324

325325
Example of `figma-export.yaml` file for Android project — [Examples/AndroidExample/figma-export.yaml](./Examples/AndroidExample/figma-export.yaml)
326326

327+
Generate `figma-export.yaml` config file using one of the following command:
328+
```
329+
figma-export init --platform android
330+
figma-export init --platform ios
331+
```
332+
It will generate config file in the current directory.
333+
327334
### Exporting Typography
328335

329336
1. Add a custom font to the Xcode project. Drag & drop font file to the Xcode project, set target membership, and add font file name in the Info.plist file. [See developer documentation for more info.](https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app)<br><img src="images/fonts.png" width="400" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
figma:
3+
# 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.
4+
lightFileId: shPilWnVdJfo10YF12345
5+
# [optional] Identifier of the file containing dark color palette and dark images.
6+
darkFileId: KfF6DnJTWHGZzC912345
7+
8+
# [optional] Android export parameters
9+
android:
10+
# Relative or absolute path to the `main/res` folder including it. The colors/icons/imags will be exported to this folder
11+
mainRes: "./main/res"
12+
# Parameters for exporting icons
13+
icons:
14+
# Where to place icons relative to `mainRes`? FigmaExport clears this directory every time your execute `figma-export icons` command
15+
output: "figma-export-icons"
16+
# Parameters for exporting images
17+
images:
18+
# Where to place images relative to `mainRes`? FigmaExport clears this directory every time your execute `figma-export images` command
19+
output: "figma-export-images"
20+
# Image file format: svg or png
21+
format: webp
22+
# Format options for webp format only
23+
webpOptions:
24+
# Encoding type: lossy or lossless
25+
encoding: lossy
26+
# Encoding quality in percents. Only for lossy encoding.
27+
quality: 90
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,3 @@ ios:
8484
generateLabels: true
8585
# Relative or absolute path to directory where to place UILabel for each text style (font) (Requred if generateLabels = true)
8686
labelsDirectory: "./Source/UIComponents/"
87-
88-
# [optional] Android export parameters
89-
android:
90-
# Relative or absolute path to the `main/res` folder including it. The colors/icons/imags will be exported to this folder
91-
mainRes: "./main/res"
92-
# Parameters for exporting icons
93-
icons:
94-
# Where to place icons relative to `mainRes`? FigmaExport clears this directory every time your execute `figma-export icons` command
95-
output: "figma-export-icons"
96-
# Parameters for exporting images
97-
images:
98-
# Where to place images relative to `mainRes`? FigmaExport clears this directory every time your execute `figma-export images` command
99-
output: "figma-export-images"
100-
# Image file format: svg or png
101-
format: webp
102-
# Format options for webp format only
103-
webpOptions:
104-
# Encoding type: lossy or lossless
105-
encoding: lossy
106-
# Encoding quality in percents. Only for lossy encoding.
107-
quality: 90
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import ArgumentParser
2+
import FigmaExportCore
3+
import Foundation
4+
import Logging
5+
6+
extension Platform: ExpressibleByArgument {}
7+
8+
extension FigmaExportCommand {
9+
10+
struct GenerateConfigFile: ParsableCommand {
11+
12+
static let configuration = CommandConfiguration(
13+
commandName: "init",
14+
abstract: "Generates config file",
15+
discussion: "Generates figma-export.yaml config file in the current directory")
16+
17+
@Option(name: .shortAndLong, help: "Platform: ios or android.")
18+
var platform: Platform
19+
20+
func run() throws {
21+
let logger = Logger(label: "com.redmadrobot.figma-export")
22+
23+
let fileName: String
24+
switch platform {
25+
case .android:
26+
fileName = "android"
27+
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
33+
}
34+
35+
let destination = FileManager.default.currentDirectoryPath + "/" + "figma-export.yaml"
36+
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)")
40+
}
41+
}
42+
}

Sources/FigmaExport/main.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ struct FigmaExportCommand: ParsableCommand {
3636
ExportColors.self,
3737
ExportIcons.self,
3838
ExportImages.self,
39-
ExportTypography.self
39+
ExportTypography.self,
40+
GenerateConfigFile.self
4041
],
4142
defaultSubcommand: ExportColors.self
4243
)

0 commit comments

Comments
 (0)