|
| 1 | +package name.rayrobdod.stringContextParserCombinator.build |
| 2 | + |
| 3 | +import sbt._ |
| 4 | +import sbt.Keys._ |
| 5 | + |
| 6 | +object OptimizeScaladocPlugin extends AutoPlugin { |
| 7 | + override def requires = sbt.plugins.JvmPlugin |
| 8 | + override def trigger = allRequirements |
| 9 | + |
| 10 | + object autoImport { |
| 11 | + val optdocMakeReplacementFontawesomeCss = taskKey[(File, String)]("") |
| 12 | + val optdocMakeReplacementFontawesomeIcons = taskKey[Seq[(File, String)]]("") |
| 13 | + } |
| 14 | + import autoImport._ |
| 15 | + |
| 16 | + override val globalSettings = Seq( |
| 17 | + ) |
| 18 | + |
| 19 | + private def states: Seq[(String, Seq[String], String, String)] = Seq( |
| 20 | + ("default", Seq("", ":disabled", ":focus"), "#6F6E77", "#A09FA6"), |
| 21 | + ("hover", Seq(":hover", ":active"), "#1A1523", "#CCCCCC"), |
| 22 | + ("selected", Seq(".selected"), "#1A1523", "#EDEDEF"), |
| 23 | + ) |
| 24 | + |
| 25 | + private def unscopedSettings = Seq( |
| 26 | + optdocMakeReplacementFontawesomeCss := { |
| 27 | + sbt.IO.createDirectory(target.value / "docopt") |
| 28 | + val outFile = target.value / "docopt" / "fontawesome.css" |
| 29 | + val clockLines = { |
| 30 | + val icon = "clock" |
| 31 | + for { |
| 32 | + theme <- Seq("light", "dark"); |
| 33 | + themeClass = if (theme == "light") {""} else {s".theme-$theme "}; |
| 34 | + line <- Seq( |
| 35 | + s"${themeClass}.fas.fa-${icon}::before {", |
| 36 | + s" content: url('../images/fontawesome/${icon}/${theme}/default.svg')", |
| 37 | + "}" |
| 38 | + ) |
| 39 | + } yield line |
| 40 | + } |
| 41 | + val playLines = { |
| 42 | + val icon = "play" |
| 43 | + for { |
| 44 | + theme <- Seq("light", "dark"); |
| 45 | + themeClass = if (theme == "light") {""} else {s".theme-$theme "}; |
| 46 | + (state, stateClasses, _, _) <- states; |
| 47 | + stateClass <- stateClasses; |
| 48 | + line <- Seq( |
| 49 | + s"${themeClass}.icon-button.run-button${stateClass}::before {", |
| 50 | + s" content: url('../images/fontawesome/${icon}/${theme}/${state}.svg')", |
| 51 | + "}" |
| 52 | + ) |
| 53 | + } yield line |
| 54 | + } |
| 55 | + |
| 56 | + sbt.io.IO.writeLines(outFile, playLines ++ clockLines) |
| 57 | + outFile -> "styles/fontawesome.css" |
| 58 | + }, |
| 59 | + optdocMakeReplacementFontawesomeIcons := { |
| 60 | + val outDir = target.value / "docopt" / "icons" |
| 61 | + sbt.IO.createDirectory(outDir) |
| 62 | + |
| 63 | + for { |
| 64 | + icon <- Seq("play", "clock"); |
| 65 | + theme <- Seq("light", "dark"); |
| 66 | + (state, _, lightColor, darkColor) <- if (icon == "play") {states} else {states.take(1)} |
| 67 | + } yield { |
| 68 | + val color = if (theme == "light") {lightColor} else {darkColor} |
| 69 | + val lines = icon match { |
| 70 | + case "play" => Seq( |
| 71 | + s"""<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" width="11.5" height="15.333" fill="${color}">""", |
| 72 | + "<!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.-->", |
| 73 | + """<path d="M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80L0 432c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9L361 297c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39z"/>""", |
| 74 | + "</svg>", |
| 75 | + ) |
| 76 | + case "clock" => Seq( |
| 77 | + s"""<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="13" height="13" fill="${color}">""", |
| 78 | + "<!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.-->", |
| 79 | + """<path d="M256 0a256 256 0 1 1 0 512A256 256 0 1 1 256 0zM232 120l0 136c0 8 4 15.5 10.7 20l96 64c11 7.4 25.9 4.4 33.3-6.7s4.4-25.9-6.7-33.3L280 243.2 280 120c0-13.3-10.7-24-24-24s-24 10.7-24 24z"/>""", |
| 80 | + "</svg>", |
| 81 | + ) |
| 82 | + } |
| 83 | + val outFile = outDir / s"$icon-$theme-$state.svg" |
| 84 | + sbt.io.IO.writeLines(outFile, lines) |
| 85 | + outFile -> s"images/fontawesome/${icon}/${theme}/${state}.svg" |
| 86 | + } |
| 87 | + }, |
| 88 | + ) |
| 89 | + |
| 90 | + private def perScopeSettings(config:sbt.librarymanagement.Configuration) = Seq( |
| 91 | + config / packageDoc / mappings := { |
| 92 | + scalaBinaryVersion.value match { |
| 93 | + case "3" => |
| 94 | + (config / packageDoc / mappings).value |
| 95 | + .filterNot({filePath => |
| 96 | + import java.io.File.separator |
| 97 | + val path = filePath._2 |
| 98 | + path.startsWith(s"images${separator}icon-buttons${separator}twitter${separator}") || |
| 99 | + path.startsWith(s"images${separator}twitter-icon-") || |
| 100 | + path.startsWith(s"images${separator}icon-buttons${separator}gitter${separator}") || |
| 101 | + path.startsWith(s"images${separator}gitter-icon-") || |
| 102 | + path.startsWith(s"styles${separator}fontawesome.css") || |
| 103 | + path.startsWith(s"webfonts${separator}fa-") || |
| 104 | + false |
| 105 | + }) |
| 106 | + .:+(optdocMakeReplacementFontawesomeCss.value) |
| 107 | + .++(optdocMakeReplacementFontawesomeIcons.value) |
| 108 | + case _ => |
| 109 | + (config / packageDoc / mappings).value |
| 110 | + } |
| 111 | + }, |
| 112 | + ) |
| 113 | + |
| 114 | + override lazy val projectSettings = unscopedSettings ++ perScopeSettings(Compile) ++ perScopeSettings(Test) |
| 115 | +} |
0 commit comments