Skip to content

Commit

Permalink
new icon pack: astrit/css.gg
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSrSouza committed Mar 28, 2021
1 parent fe05d12 commit 5c8ce9b
Show file tree
Hide file tree
Showing 713 changed files with 47,503 additions and 2 deletions.
62 changes: 62 additions & 0 deletions android/css-gg/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
plugins {
id("com.android.library")
id("kotlin-android")
}

group = Publish.groupAndroid

dependencies {
api("androidx.compose.runtime:runtime:${Versions.composeAndroidVersion}")
api("androidx.compose.foundation:foundation:${Versions.composeAndroidVersion}")
api("androidx.compose.ui:ui:${Versions.composeAndroidVersion}")
}

android {
sourceSets["main"].java.srcDir("../../css-gg/src/commonMain/kotlin")

compileSdkVersion(29)
defaultConfig {
minSdkVersion(21)
targetSdkVersion(29)
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
useIR = true
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = Versions.composeAndroidVersion
kotlinCompilerVersion = "1.4.21"
}
}

val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(android.sourceSets["main"].java.srcDirs)
}

val javadocJar = tasks.register("javadocJar", Jar::class.java) {
archiveClassifier.set("javadoc")
}

afterEvaluate {
publishing {
publications {
create<MavenPublication>("maven") {
from(components["release"])
artifact(sourcesJar)
artifact(javadocJar)
setupPom(project)
}
}
}

setupSigning()
}
2 changes: 2 additions & 0 deletions android/css-gg/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="compose.icons.android.cssgg"/>
274 changes: 274 additions & 0 deletions css-gg/DOCUMENTATION.md

Large diffs are not rendered by default.

178 changes: 178 additions & 0 deletions css-gg/generate-source.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
@file:Repository("https://jitpack.io")
@file:Repository("https://maven.google.com")
@file:Repository("https://jetbrains.bintray.com/trove4j")
@file:Repository("file:///home/devsrsouza/.m2/repository")

// svg-to-compose
//@file:DependsOn("com.github.DevSrSouza:svg-to-compose:0.5.0")
@file:DependsOn("br.com.devsrsouza:svg-to-compose:0.6.0-SNAPSHOT")
@file:DependsOn("com.google.guava:guava:23.0")
@file:DependsOn("com.android.tools:sdk-common:27.2.0-alpha16")
@file:DependsOn("com.android.tools:common:27.2.0-alpha16")
@file:DependsOn("com.squareup:kotlinpoet:1.7.2")
@file:DependsOn("org.ogce:xpp3:1.1.6")

@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")

// Jgit
@file:DependsOn("org.eclipse.jgit:org.eclipse.jgit:3.5.0.201409260305-r")

import br.com.devsrsouza.svg2compose.ParsingResult
import br.com.devsrsouza.svg2compose.Svg2Compose
import br.com.devsrsouza.svg2compose.VectorType
import org.eclipse.jgit.api.Git
import java.io.File

fun File.makeDirs() = apply { mkdirs() }

val githubId = "astrit/css.gg"
val repository = "https://github.com/$githubId"
val version = "2.0.0"
val rawGithubRepository = "https://raw.githubusercontent.com/$githubId/$version"
val blobGithubRepository = "$repository/blob/$version"

val repoCloneDir = createTempDir(suffix = "git-repo")

println("Cloning repository")
val git = Git.cloneRepository()
.setURI(repository)
.setDirectory(repoCloneDir)
.call()
git.checkout().setName("refs/tags/$version").call()

val iconsDir = File(repoCloneDir, "icons/svg")

// renaming to match to svg-to-compose
iconsDir.walkTopDown().filter { it.extension == "svg" }
.forEach {
val newFile = File(it.parentFile, it.name.replace("-", "_"))
it.renameTo(newFile)
}

fun replacePathName(path: String): String {
val iconName = path.substringAfterLast('/')
val newIconName = iconName.replace("_", "-")
return path.replace(iconName, newIconName)
}

val srcDir = File("src/commonMain/kotlin").apply { mkdirs() }
srcDir.deleteRecursively()
srcDir.mkdirs()

fun String.removeSuffix(suffix: String, ignoreCase: Boolean): String {
if(ignoreCase) {
val index = lastIndexOf(suffix, ignoreCase = true)

return if(index > -1) substring(0, index) else this
} else {
return removeSuffix(suffix)
}
}

println("Generating all svg to compose")

val result = Svg2Compose.parse(
applicationIconPackage = "compose.icons",
accessorName = "CssGgIcons",
outputSourceDirectory = srcDir,
vectorsDirectory = iconsDir,
type = VectorType.SVG,
allAssetsPropertyName = "AllIcons",
)

println("Copying LICENSE from the Icon pack")

val licensePath = "LICENSE"
val licenseFile = File(repoCloneDir, licensePath)

val resDir = File("src/commonMain/resources").makeDirs()
val licenseInResource = File(resDir, "css-gg-license.txt")

licenseFile.copyTo(licenseInResource, overwrite = true)

println("Generating documentation")

data class DocumentationGroup(
val groupName: String,
val groupAccessingFormat: String,
val icons: List<DocumentationIcon>,
)

data class DocumentationIcon(
val accessingFormat: String,
val svgFilePathRelativeToRepository: String,
)

fun ParsingResult.asDocumentationGroupList(
previousAccessingGroupFormat: String? = null
): List<DocumentationGroup> {
val accessingGroupFormat = if(previousAccessingGroupFormat != null)
"$previousAccessingGroupFormat.${groupName.second}"
else groupName.second

return listOf(asDocumentationGroup(accessingGroupFormat)) + generatedGroups.flatMap {
it.asDocumentationGroupList(accessingGroupFormat)
}
}

fun ParsingResult.asDocumentationGroup(
accessingGroupFormat: String
): DocumentationGroup {
return DocumentationGroup(
groupName = groupName.second,
groupAccessingFormat = accessingGroupFormat,
icons = generatedIconsMemberNames.map {
DocumentationIcon(
"$accessingGroupFormat.${it.value.simpleName}",
it.key.relativeTo(repoCloneDir).path
)
}
)
}

fun markdownSvg(doc: DocumentationIcon): String {
return "![](${rawGithubRepository + "/" + replacePathName(doc.svgFilePathRelativeToRepository) })"
}

fun markdownIconDocumentation(doc: DocumentationIcon): String {
return "${markdownSvg(doc)} | ${doc.accessingFormat}"
}

val chunks = 3
fun List<DocumentationIcon>.iconsTableDocumentation(): String = sortedBy { it.accessingFormat }
.chunked(chunks).map {
"| ${it.map { markdownIconDocumentation(it) }.joinToString(" | ")} |"
}.joinToString("\n")

val documentationGroups = result.asDocumentationGroupList()
.filter { it.icons.isNotEmpty() }
.map {
"""
## ${it.groupName}
|${" Icon | In Code |".repeat(chunks)}
|${" --- | --- |".repeat(chunks)}
""".trimIndent() + "\n" + it.icons.iconsTableDocumentation()
}.joinToString("\n<br /><br />\n")

val header = """
# [css.gg](https://css.gg/)
<br />
""".trimIndent()

val license = """
## [License]($blobGithubRepository/$licensePath)
<br />
```
""".trimIndent() + licenseFile.readText().trimEnd { it == '\n' } + "\n```\n\n<br /><br />\n\n"

File("DOCUMENTATION.md").apply{
if(exists().not()) createNewFile()
}.writeText(
header + "\n" + license + "\n" + documentationGroups
)
Loading

0 comments on commit 5c8ce9b

Please sign in to comment.