Skip to content

Commit

Permalink
Merge pull request #3 from iodigital-com/improvements
Browse files Browse the repository at this point in the history
Allow for easier testing
  • Loading branch information
crysxd authored Jun 26, 2024
2 parents 16345b5 + 31374a9 commit 34cd180
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ captures
.externalNativeBuild
.cxx
local.properties
xcuserdata
xcuserdata
figma-exporter/sampleconfig.json
figma-exporter/.figmatoken
2 changes: 1 addition & 1 deletion .run/Run sample.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<option name="taskNames">
<list>
<option value="jvmRun" />
<option value="--args='-c ../samples/config.json'" />
<option value="--args='-c sampleconfig.json'" />
</list>
</option>
<option name="vmOptions" />
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,9 @@ Hint: You can also use Jinja filters to modify the name, e.g. `{{ color.name|low
## Build the project

- Clone the Git
- To test, open in Android Studio and
- Create a `.figmatoken` file containing your token in `figma-exporter/.figmatoken`
- Create a `sampleconfig.file` with a config in `figma-exporter/.figmatoken`
- Run the `Run sample` configuration
- `./gradlew clean build` will build the project and create files
in `figma-exported/build/distributions`
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ object FigEx {
startStatusAnimation(exportScope)
info(tag = tag, "Using cache at $cacheDir")

if (!configFile.exists()) {
throw IllegalArgumentException("Config file does not exist: ${configFile.absolutePath}")
}

val configJson = configFile.readText()
val config = ConfigJson.decodeFromString<FigExConfig>(configJson)
val api =
Expand Down
10 changes: 6 additions & 4 deletions figma-exporter/src/commonMain/kotlin/com/iodigital/figex/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ private const val tokenEnvVar = "FIGMA_TOKEN"

fun main(args: Array<String>): Unit = runBlocking {
try {
val token = System.getenv(tokenEnvVar) ?: let {
println("Missing Figma token as FIGMA_TOKEN environment variable")
exitProcess(127)
}
val token = System.getenv(tokenEnvVar)
?: File(".figmatoken").takeIf { it.exists() }?.readText()
?: let {
println("Missing Figma token as FIGMA_TOKEN environment variable")
exitProcess(127)
}

val configFile = loadConfig(args)
FigEx.doExport(configFile = configFile, figmaToken = token)
Expand Down

0 comments on commit 34cd180

Please sign in to comment.