Skip to content

Commit e930017

Browse files
committed
[Gradle] Introduce ImageVector generation configuration, enhance task structure
1 parent 05fc373 commit e930017

File tree

16 files changed

+378
-241
lines changed

16 files changed

+378
-241
lines changed

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,32 @@ valkyrie {
408408
// Example: src/commonMain/valkyrieResources/, src/androidMain/valkyrieResources/
409409
resourceDirectoryName = "valkyrieResources"
410410

411-
// Optional: Output format for generated ImageVectors (default: BackingProperty)
412-
outputFormat = OutputFormat.BackingProperty // or OutputFormat.LazyProperty
413-
414-
// Optional: Code generation settings
415-
useComposeColors = true // Use androidx.compose.ui.graphics.Color (default: true)
416-
generatePreview = false // Generate @Preview composable functions (default: false)
417-
previewAnnotationType = PreviewAnnotationType.AndroidX // AndroidX or Jetbrains (default: AndroidX)
418-
useFlatPackage = false // Generate flat package structure without subfolders (default: false)
419-
useExplicitMode = false // Add explicit visibility modifiers (default: false)
420-
addTrailingComma = false // Add trailing commas in generated code (default: false)
421-
indentSize = 4 // Number of spaces for indentation (default: 4)
411+
// Optional: Generate flat package structure without subfolders (default: false)
412+
useFlatPackage = false
413+
414+
// Optional: ImageVector generation configuration
415+
imageVector {
416+
// Output format for generated ImageVectors (default: BackingProperty)
417+
outputFormat = OutputFormat.BackingProperty // or OutputFormat.LazyProperty
418+
419+
// Use predefined Compose colors instead of hex color codes (e.g. Color.Black instead of Color(0xFF000000)) (default: true)
420+
useComposeColors = true
421+
422+
// Generate `@Preview` function for ImageVector (default: false)
423+
generatePreview = false
424+
425+
// Specifies the type of Preview annotation to generate for @Preview
426+
previewAnnotationType = PreviewAnnotationType.AndroidX
427+
428+
// Add explicit `public` modifier to generated declarations (default: false)
429+
useExplicitMode = false
430+
431+
// Insert a trailing comma after the last element of ImageVector.Builder block and path params (default: false)
432+
addTrailingComma = false
433+
434+
// Number of spaces used for each level of indentation in generated code (default: 4)
435+
indentSize = 4
436+
}
422437

423438
// Optional: Custom output directory (default: build/generated/sources/valkyrie)
424439
outputDirectory = layout.buildDirectory.dir("generated/valkyrie")

tools/gradle-plugin/api/gradle-plugin.api

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
1-
public abstract class io/github/composegears/valkyrie/gradle/GenerateImageVectorsTask : org/gradle/api/DefaultTask {
2-
public fun <init> ()V
3-
public final fun execute ()V
4-
public abstract fun getAddTrailingComma ()Lorg/gradle/api/provider/Property;
5-
public abstract fun getGeneratePreview ()Lorg/gradle/api/provider/Property;
6-
public abstract fun getIconFiles ()Lorg/gradle/api/file/ConfigurableFileCollection;
7-
public abstract fun getIconPackName ()Lorg/gradle/api/provider/Property;
8-
public abstract fun getIndentSize ()Lorg/gradle/api/provider/Property;
9-
public abstract fun getNestedPackName ()Lorg/gradle/api/provider/Property;
10-
public abstract fun getOutputDirectory ()Lorg/gradle/api/file/DirectoryProperty;
11-
public abstract fun getOutputFormat ()Lorg/gradle/api/provider/Property;
12-
public abstract fun getPackageName ()Lorg/gradle/api/provider/Property;
13-
public abstract fun getPreviewAnnotationType ()Lorg/gradle/api/provider/Property;
14-
public abstract fun getUseComposeColors ()Lorg/gradle/api/provider/Property;
15-
public abstract fun getUseExplicitMode ()Lorg/gradle/api/provider/Property;
16-
public abstract fun getUseFlatPackage ()Lorg/gradle/api/provider/Property;
1+
public abstract class io/github/composegears/valkyrie/gradle/ImageVectorConfigExtension {
2+
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
3+
public final fun getAddTrailingComma ()Lorg/gradle/api/provider/Property;
4+
public final fun getGeneratePreview ()Lorg/gradle/api/provider/Property;
5+
public final fun getIndentSize ()Lorg/gradle/api/provider/Property;
6+
public final fun getOutputFormat ()Lorg/gradle/api/provider/Property;
7+
public final fun getPreviewAnnotationType ()Lorg/gradle/api/provider/Property;
8+
public final fun getUseComposeColors ()Lorg/gradle/api/provider/Property;
9+
public final fun getUseExplicitMode ()Lorg/gradle/api/provider/Property;
1710
}
1811

19-
public abstract interface class io/github/composegears/valkyrie/gradle/ValkyrieExtension {
20-
public abstract fun getAddTrailingComma ()Lorg/gradle/api/provider/Property;
21-
public abstract fun getGenerateAtSync ()Lorg/gradle/api/provider/Property;
22-
public abstract fun getGeneratePreview ()Lorg/gradle/api/provider/Property;
23-
public abstract fun getIconPackName ()Lorg/gradle/api/provider/Property;
24-
public abstract fun getIndentSize ()Lorg/gradle/api/provider/Property;
25-
public abstract fun getNestedPackName ()Lorg/gradle/api/provider/Property;
26-
public abstract fun getOutputDirectory ()Lorg/gradle/api/file/DirectoryProperty;
27-
public abstract fun getOutputFormat ()Lorg/gradle/api/provider/Property;
28-
public abstract fun getPackageName ()Lorg/gradle/api/provider/Property;
29-
public abstract fun getPreviewAnnotationType ()Lorg/gradle/api/provider/Property;
30-
public abstract fun getResourceDirectoryName ()Lorg/gradle/api/provider/Property;
31-
public abstract fun getUseComposeColors ()Lorg/gradle/api/provider/Property;
32-
public abstract fun getUseExplicitMode ()Lorg/gradle/api/provider/Property;
33-
public abstract fun getUseFlatPackage ()Lorg/gradle/api/provider/Property;
12+
public abstract class io/github/composegears/valkyrie/gradle/ValkyrieExtension {
13+
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
14+
public final fun getGenerateAtSync ()Lorg/gradle/api/provider/Property;
15+
public final fun getIconPackName ()Lorg/gradle/api/provider/Property;
16+
public final fun getNestedPackName ()Lorg/gradle/api/provider/Property;
17+
public final fun getOutputDirectory ()Lorg/gradle/api/file/DirectoryProperty;
18+
public final fun getPackageName ()Lorg/gradle/api/provider/Property;
19+
public final fun getResourceDirectoryName ()Lorg/gradle/api/provider/Property;
20+
public final fun getUseFlatPackage ()Lorg/gradle/api/provider/Property;
21+
public final fun imageVector (Lkotlin/jvm/functions/Function1;)V
3422
}
3523

3624
public final class io/github/composegears/valkyrie/gradle/ValkyrieGradlePlugin : org/gradle/api/Plugin {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.github.composegears.valkyrie.gradle
2+
3+
import io.github.composegears.valkyrie.generator.jvm.imagevector.OutputFormat
4+
import io.github.composegears.valkyrie.generator.jvm.imagevector.PreviewAnnotationType
5+
import io.github.composegears.valkyrie.gradle.dsl.property
6+
import javax.inject.Inject
7+
import org.gradle.api.model.ObjectFactory
8+
import org.gradle.api.provider.Property
9+
10+
abstract class ImageVectorConfigExtension @Inject constructor(objects: ObjectFactory) {
11+
/**
12+
* Specifies the output format for the generated ImageVector.
13+
*
14+
* Available options:
15+
* - [OutputFormat.BackingProperty]: Uses backing property for the output.
16+
* - [OutputFormat.LazyProperty]: Generates a lazy property representation.
17+
*
18+
* Default: [OutputFormat.BackingProperty]
19+
*/
20+
val outputFormat: Property<OutputFormat> = objects
21+
.property<OutputFormat>()
22+
.convention(OutputFormat.BackingProperty)
23+
24+
/**
25+
* Use predefined Compose colors instead of hex color codes (e.g. Color.Black instead of Color(0xFF000000))
26+
*
27+
* Default: `true`
28+
*/
29+
val useComposeColors: Property<Boolean> = objects
30+
.property<Boolean>()
31+
.convention(true)
32+
33+
/**
34+
* Generate `@Preview` function for ImageVector.
35+
*
36+
* Default: `false`
37+
*/
38+
val generatePreview: Property<Boolean> = objects
39+
.property<Boolean>()
40+
.convention(false)
41+
42+
/**
43+
* Specifies the type of Preview annotation to generate for @Preview.
44+
*
45+
* Available options:
46+
* - [PreviewAnnotationType.AndroidX]: Use AndroidX Preview annotation
47+
* (`androidx.compose.ui.tooling.preview.Preview`).
48+
* - [PreviewAnnotationType.Jetbrains]: Use JetBrains (Desktop) Preview annotation
49+
* (`androidx.compose.desktop.ui.tooling.preview.Preview`).
50+
*
51+
* Default: [PreviewAnnotationType.AndroidX]
52+
*/
53+
val previewAnnotationType: Property<PreviewAnnotationType> = objects
54+
.property<PreviewAnnotationType>()
55+
.convention(PreviewAnnotationType.AndroidX)
56+
57+
/**
58+
* Add explicit `public` modifier to generated declarations.
59+
*
60+
* Default: `false`
61+
*/
62+
val useExplicitMode: Property<Boolean> = objects
63+
.property<Boolean>()
64+
.convention(false)
65+
66+
/**
67+
* Insert a trailing comma after the last element of ImageVector.Builder block and path params.
68+
*
69+
* Default: `false`
70+
*/
71+
val addTrailingComma: Property<Boolean> = objects
72+
.property<Boolean>()
73+
.convention(false)
74+
75+
/**
76+
* Number of spaces used for each level of indentation in generated code.
77+
*
78+
* Default: `4`
79+
*/
80+
val indentSize: Property<Int> = objects
81+
.property<Int>()
82+
.convention(4)
83+
}

tools/gradle-plugin/src/main/kotlin/io/github/composegears/valkyrie/gradle/Utils.kt

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)