Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format with scalafmt #237

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version = "3.7.17"
runner.dialect = scala213source3

maxColumn = 120

preset = IntelliJ

align {
preset = most
openParenDefnSite = true
arrowEnumeratorGenerator = true
multiline = true
}

danglingParentheses {
preset = true
}

includeCurlyBraceInSelectChains = true

includeNoParensInSelectChains = true

optIn {
breakChainOnFirstMethodDot = true
breaksInsideChains = false
}

rewrite.rules = [RedundantBraces, RedundantParens]

newlines {
source = keep
beforeMultiline = keep
beforeMultilineDef = unfold
topLevelStatementBlankLines = [
{
regex = "^Import",
minBreaks = 0,
blanks = {after = 2, before = 1}
}
]
}

verticalMultiline.atDefnSite = true
169 changes: 79 additions & 90 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def myScalacOptions(version: String) =
)

inThisBuild(List(
organization := "io.github.nafg.scalajs-facades",
organization := "io.github.nafg.scalajs-facades",
crossScalaVersions := Seq("2.13.12", "3.3.1"),
scalaVersion := (ThisBuild / crossScalaVersions).value.last,
scalacOptions ++= myScalacOptions(scalaVersion.value),
scalaVersion := (ThisBuild / crossScalaVersions).value.last,
scalacOptions ++= myScalacOptions(scalaVersion.value)
))

sonatypeProfileName := "io.github.nafg"
Expand All @@ -35,41 +35,40 @@ lazy val simpleFacade =
project
.enablePlugins(ScalaJSBundlerPlugin)
.settings(
description := "Library for react component facades that are simple to write and simple to use",
description := "Library for react component facades that are simple to write and simple to use",
sjsCrossTarget,
sonatypeProfileName := "io.github.nafg",
libraryDependencies ++= Seq(
"com.github.japgolly.scalajs-react" %%% "core" % "2.1.1",
"com.github.japgolly.scalajs-react" %%% "extra" % "2.1.1",
"me.shadaj" %%% "slinky-readwrite" % "0.7.4",
"org.scalameta" %%% "munit" % "0.7.29" % Test
"com.github.japgolly.scalajs-react" %%% "core" % "2.1.1",
"com.github.japgolly.scalajs-react" %%% "extra" % "2.1.1",
"me.shadaj" %%% "slinky-readwrite" % "0.7.4",
"org.scalameta" %%% "munit" % "0.7.29" % Test
)
)

def moduleConfig(npmName: String, npmVersion: String): Project => Project =
_.enablePlugins(ScalaJSBundlerPlugin)
.dependsOn(simpleFacade)
.settings(
name := npmName.stripPrefix("@") + "_" + (npmVersion match {
name := npmName.stripPrefix("@") + "_" + (npmVersion match {
case VersionNumber(Seq(n, _, _), _, _) => n
case s => s.takeWhile(_ != '.')
}),
description := s"Facade for $npmName version $npmVersion",
description := s"Facade for $npmName version $npmVersion",
sjsCrossTarget,
useYarn := true,
sonatypeProfileName := "io.github.nafg",
useYarn := true,
sonatypeProfileName := "io.github.nafg",
Compile / npmDependencies += npmName -> npmVersion,
scalacOptions ++= (if (scalaJSVersion.startsWith("0.6.")) Seq("-P:scalajs:sjsDefinedByDefault") else Nil)
)
)

lazy val reactSelect = project.configure(moduleConfig("react-select", "5.6.1"))
lazy val reactInputMask = project.configure(moduleConfig("react-input-mask", "2.0.4"))
lazy val reactSelect = project.configure(moduleConfig("react-select", "5.6.1"))
lazy val reactInputMask = project.configure(moduleConfig("react-input-mask", "2.0.4"))
lazy val reactPhoneNumberInput = project.configure(moduleConfig("react-phone-number-input", "3.2.12"))
lazy val reactAutocomplete = project.configure(moduleConfig("react-autocomplete", "1.8.1"))
lazy val reactWidgets = project.configure(moduleConfig("react-widgets", "5.8.4"))
lazy val reactWaypoint = project.configure(moduleConfig("react-waypoint", "10.3.0"))
lazy val reactDatepicker = project.configure(moduleConfig("react-datepicker", "4.8.0"))

lazy val reactAutocomplete = project.configure(moduleConfig("react-autocomplete", "1.8.1"))
lazy val reactWidgets = project.configure(moduleConfig("react-widgets", "5.8.4"))
lazy val reactWaypoint = project.configure(moduleConfig("react-waypoint", "10.3.0"))
lazy val reactDatepicker = project.configure(moduleConfig("react-datepicker", "4.8.0"))

def materialUiCoreVersion = "4.12.4"

Expand All @@ -86,7 +85,8 @@ def commonComponentInfoTransformer: ComponentInfoTransformer =
"onClick",
"ReactMouseEventFromHtml => Callback",
CommonImports.Callback + CommonImports.react("ReactMouseEventFromHtml")
))
)
)

def materialUiGitUrl = "https://github.com/mui-org/material-ui.git"

Expand All @@ -95,76 +95,69 @@ lazy val materialUiCore =
.configure(moduleConfig("@material-ui/core", materialUiCoreVersion))
.enablePlugins(FacadeGeneratorPlugin)
.settings(
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
case (ComponentInfo("ClickAwayListener" | "Tooltip", _, _), p @ PropInfo("children", _, _, _, _)) =>
p.copy(
required = true,
propTypeInfo = PropTypeInfo("VdomElement", CommonImports.VdomElement)
)
case (ComponentInfo("ClickAwayListener", _, _), p @ PropInfo("onClickAway", _, _, _, _)) =>
p.copy(
propTypeInfo = PropTypeInfo("() => Callback", CommonImports.Callback)
p.copy(propTypeInfo =
PropTypeInfo("() => Callback", CommonImports.Callback)
)
case (ComponentInfo("Dialog", _, _), p @ PropInfo("onClose", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo("(ReactEvent, String) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
p.copy(propTypeInfo =
PropTypeInfo("(ReactEvent, String) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
case (ComponentInfo("Icon", _, _), p @ PropInfo("fontSize", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(PropType.Enum(PropType.String, List("'inherit'", "'large'", "'medium'", "'small'")))
p.copy(propTypeInfo =
PropTypeInfo(PropType.Enum(PropType.String, List("'inherit'", "'large'", "'medium'", "'small'")))
)
case (ComponentInfo("IconButton" | "ListItem", _, _), p @ PropInfo("children", _, _, _, _)) =>
p.copy(
propTypeInfo = PropTypeInfo("VdomNode", CommonImports.VdomNode)
p.copy(propTypeInfo =
PropTypeInfo("VdomNode", CommonImports.VdomNode)
)
case (ComponentInfo("Menu", _, _), p @ PropInfo("anchorEl", _, _, _, _)) =>
p.copy(
propTypeInfo = PropTypeInfo("Element | (js.Object => Element)", CommonImports.Element ++ CommonImports.|)
p.copy(propTypeInfo =
PropTypeInfo("Element | (js.Object => Element)", CommonImports.Element ++ CommonImports.|)
)
case (ComponentInfo("Menu", _, _), p @ PropInfo("onClose", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(
"(ReactEvent, String) => Callback",
CommonImports.ReactEvent ++ CommonImports.Callback
)
p.copy(propTypeInfo =
PropTypeInfo(
"(ReactEvent, String) => Callback",
CommonImports.ReactEvent ++ CommonImports.Callback
)
)
case (ComponentInfo("Paper", _, _), p @ PropInfo("elevation", _, _, _, _)) =>
p.copy(propTypeInfo = PropTypeInfo("Int"))
case (ComponentInfo("Popper", _, _), p @ PropInfo("anchorEl", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(
"Element | js.Object | (js.Object => (Element | js.Object))",
CommonImports.Element ++ CommonImports.|
)
p.copy(propTypeInfo =
PropTypeInfo(
"Element | js.Object | (js.Object => (Element | js.Object))",
CommonImports.Element ++ CommonImports.|
)
)
case (ComponentInfo("TableCell", _, _), p @ PropInfo("padding", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(PropType.Enum(PropType.String, List("'normal'", "'checkbox'", "'none'")))
p.copy(propTypeInfo =
PropTypeInfo(PropType.Enum(PropType.String, List("'normal'", "'checkbox'", "'none'")))
)
case (ComponentInfo("TablePagination", _, _), p @ PropInfo("page" | "count" | "rowsPerPage", _, _, _, _)) =>
p.copy(propTypeInfo = PropTypeInfo("Int"))
case (ComponentInfo("TablePagination", _, _), p @ PropInfo("onChangePage" | "onPageChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo("(ReactEvent, Int) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
p.copy(propTypeInfo =
PropTypeInfo("(ReactEvent, Int) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
case (ComponentInfo("InputBase" | "OutlinedInput" | "TextField", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(
"ReactEventFromInput => Callback",
CommonImports.Callback + CommonImports.react("ReactEventFromInput")
)
p.copy(propTypeInfo =
PropTypeInfo(
"ReactEventFromInput => Callback",
CommonImports.Callback + CommonImports.react("ReactEventFromInput")
)
)
},
componentInfoTransformer := commonComponentInfoTransformer.andThen {
componentInfoTransformer := commonComponentInfoTransformer.andThen {
case c if Set("Container", "TextField").contains(c.name) =>
c.addPropIfNotExists(PropInfo("children", "VdomNode", CommonImports.VdomNode))
case c =>
Expand All @@ -182,33 +175,30 @@ lazy val materialUiLab =
.configure(moduleConfig("@material-ui/lab", "4.0.0-alpha.60"))
.enablePlugins(FacadeGeneratorPlugin)
.settings(
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
case (ComponentInfo("ToggleButtonGroup", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo("(ReactEvent, js.Any) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
p.copy(propTypeInfo =
PropTypeInfo("(ReactEvent, js.Any) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
case (ComponentInfo("Autocomplete", _, _), p) =>
p.name match {
case "filterOptions" => p.copy(propTypeInfo = PropTypeInfo("(Seq[js.Any], js.Object) => Seq[js.Any]"))
case "getOptionLabel" => p.copy(propTypeInfo = PropTypeInfo("js.Any => String"))
case "onChange" =>
p.copy(
propTypeInfo =
PropTypeInfo(
"(ReactEvent, js.Any) => Callback",
CommonImports.Callback ++ CommonImports.ReactEvent
)
p.copy(propTypeInfo =
PropTypeInfo(
"(ReactEvent, js.Any) => Callback",
CommonImports.Callback ++ CommonImports.ReactEvent
)
)
case "onInputChange" =>
p.copy(
propTypeInfo =
PropTypeInfo(
"(ReactEvent, String, String) => Callback",
CommonImports.Callback ++ CommonImports.ReactEvent
)
p.copy(propTypeInfo =
PropTypeInfo(
"(ReactEvent, String, String) => Callback",
CommonImports.Callback ++ CommonImports.ReactEvent
)
)
case "renderInput" =>
p.copy(propTypeInfo = PropTypeInfo("js.Dictionary[js.Any] => VdomNode", CommonImports.VdomNode))
Expand All @@ -218,7 +208,7 @@ lazy val materialUiLab =
p
}
},
componentInfoTransformer := commonComponentInfoTransformer,
componentInfoTransformer := commonComponentInfoTransformer,
componentCodeGenInfoTransformer := {
case c if Set("Breadcrumbs", "ToggleButtonGroup").contains(c.componentInfo.name) =>
c.copy(moduleTrait = "FacadeModule.ArrayChildren")
Expand All @@ -231,12 +221,11 @@ val generateInstallInstructions = taskKey[Unit]("Generate install instructions i

generateInstallInstructions := {
val info = Def.task((projectID.value, description.value, (publish / skip).value)).all(ScopeFilter(inAnyProject)).value
val lines =
for ((moduleId, descr, noPublish) <- info.sortBy(_._1.name) if !noPublish) yield {
"// " + descr + "\n" +
s"""libraryDependencies += "${moduleId.organization}" %%% "${moduleId.name}" % "${moduleId.revision}""""
}
val block =

val lines =
for ((moduleId, descr, noPublish) <- info.sortBy(_._1.name) if !noPublish) yield "// " + descr + "\n" +
s"""libraryDependencies += "${moduleId.organization}" %%% "${moduleId.name}" % "${moduleId.revision}""""
val block =
s"""|## Installation
|<!-- Begin autogenerated via sbt generateInstallInstructions -->
|```scala
Expand All @@ -246,11 +235,11 @@ generateInstallInstructions := {
|<!-- End autogenerated via sbt generateInstallInstructions -->
|
|""".stripMargin
val readmePath = os.pwd / "README.md"
val currentReadme = os.read.lines(readmePath)
val readmePath = os.pwd / "README.md"
val currentReadme = os.read.lines(readmePath)
val (before, rest) = currentReadme.span(_.trim != "## Installation")
val (_, after) = rest.span(s => s.trim == "## Installation" || !s.startsWith("##"))
val newReadme = before.map(_ + "\n").mkString + block + after.map(_ + "\n").mkString
val (_, after) = rest.span(s => s.trim == "## Installation" || !s.startsWith("##"))
val newReadme = before.map(_ + "\n").mkString + block + after.map(_ + "\n").mkString
os.write.over(readmePath, newReadme)
}
commands += Command.command("testQuickAndPublishLocal")("testQuick" :: "publishLocal" :: _)
16 changes: 8 additions & 8 deletions ci.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ mergifyExtraConditions := Seq(
)

inThisBuild(List(
homepage := Some(url("https://github.com/nafg/scalajs-facades")),
licenses := List("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
homepage := Some(url("https://github.com/nafg/scalajs-facades")),
licenses := List("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
Developer("nafg", "Naftoli Gugenheim", "[email protected]", url("https://github.com/nafg"))
),
dynverGitDescribeOutput ~= (_.map(o => o.copy(dirtySuffix = GitDirtySuffix("")))),
dynverSonatypeSnapshots := true,
versionScheme := Some("early-semver"),
dynverSonatypeSnapshots := true,
versionScheme := Some("early-semver"),
githubWorkflowJobSetup +=
WorkflowStep.Use(UseRef.Public("actions", "setup-node", "v2"), params = Map("node-version" -> "12")),
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
githubWorkflowPublish := Seq(
githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
Expand Down
10 changes: 5 additions & 5 deletions project/CommonImports.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
object CommonImports {
def react(s: String): String = "japgolly.scalajs.react." + s

val | = Set("scala.scalajs.js.|")
val Callback = Set(react("Callback"), "io.github.nafg.simplefacade.Implicits.callbackToWriter")
val Element = Set("org.scalajs.dom.Element")
val | = Set("scala.scalajs.js.|")
val Callback = Set(react("Callback"), "io.github.nafg.simplefacade.Implicits.callbackToWriter")
val Element = Set("org.scalajs.dom.Element")
val ElementType = Set("io.github.nafg.simplefacade.Implicits.elementTypeWriter")
val ReactEvent = Set(react("ReactEvent"))
val ReactEvent = Set(react("ReactEvent"))
val VdomElement = Set(react("vdom.VdomElement"), "io.github.nafg.simplefacade.Implicits.vdomElementWriter")
val VdomNode = Set(react("vdom.VdomNode"), "io.github.nafg.simplefacade.Implicits.vdomNodeWriter")
val VdomNode = Set(react("vdom.VdomNode"), "io.github.nafg.simplefacade.Implicits.vdomNodeWriter")
}
Loading
Loading