Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nafg committed Dec 11, 2023
1 parent 5e39f71 commit 21ded3e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
77 changes: 52 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ lazy val reactWaypoint = project.configure(moduleConfig("react-waypoint", "10.3.
lazy val reactDatepicker = project.configure(moduleConfig("react-datepicker", "4.8.0"))


def materialUiCoreVersion = "5.7.0"
def materialUiCoreVersion = "5.14.20"

val emotionNpmDeps = Compile / npmDependencies ++= Seq(
"@emotion/react" -> "11.11.1",
"@emotion/styled" -> "11.11.0",
)

def commonPropInfoTransformer: PropInfoTransformer = {
case (_, p @ PropInfo("classes", _, _, _, true)) =>
Expand All @@ -90,11 +95,40 @@ def commonComponentInfoTransformer: ComponentInfoTransformer =

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

lazy val materialUiBase =
project
.configure(moduleConfig("@mui/base", "5.0.0-beta.26"))
.enablePlugins(FacadeGeneratorPlugin)
.settings(
emotionNpmDeps,
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
case (ComponentInfo("ClickAwayListener", _, _), 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)
)
},
componentInfoTransformer := commonComponentInfoTransformer.andThen {
case c if Set("Container", "TextField").contains(c.name) =>
c.addPropIfNotExists(PropInfo("children", "VdomNode", CommonImports.VdomNode))
case c =>
c
},
Compile / sourceGenerators += generateReactDocGenFacades("packages/mui-base/src", "@mui/base", "mui.base")
)

lazy val materialUiCore =
project
.configure(moduleConfig("@mui/material", materialUiCoreVersion))
.enablePlugins(FacadeGeneratorPlugin)
.settings(
emotionNpmDeps,
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
Expand Down Expand Up @@ -125,15 +159,11 @@ lazy val materialUiCore =
case _ =>
p
}
case (ComponentInfo("ClickAwayListener" | "Tooltip", _, _), p @ PropInfo("children", _, _, _, _)) =>
case (ComponentInfo("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)
)
case (ComponentInfo("Dialog", _, _), p @ PropInfo("onClose", _, _, _, _)) =>
p.copy(
propTypeInfo =
Expand All @@ -148,6 +178,14 @@ lazy val materialUiCore =
p.copy(
propTypeInfo = PropTypeInfo("VdomNode", CommonImports.VdomNode)
)
case (ComponentInfo("InputBase" | "OutlinedInput" | "TextField", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(
"ReactEventFromInput => Callback",
CommonImports.Callback + CommonImports.react("ReactEventFromInput")
)
)
case (ComponentInfo("Menu", _, _), p @ PropInfo("anchorEl", _, _, _, _)) =>
p.copy(
propTypeInfo = PropTypeInfo("Element | (js.Object => Element)", CommonImports.Element ++ CommonImports.|)
Expand Down Expand Up @@ -182,13 +220,10 @@ lazy val materialUiCore =
propTypeInfo =
PropTypeInfo("(ReactEvent, Int) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
case (ComponentInfo("InputBase" | "OutlinedInput" | "TextField", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
case (ComponentInfo("ToggleButtonGroup", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(
"ReactEventFromInput => Callback",
CommonImports.Callback + CommonImports.react("ReactEventFromInput")
)
PropTypeInfo("(ReactEvent, js.Any) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
},
componentInfoTransformer := commonComponentInfoTransformer.andThen {
Expand All @@ -200,31 +235,23 @@ lazy val materialUiCore =
componentCodeGenInfoTransformer := {
case c @ ComponentCodeGenInfo(ComponentInfo("ButtonGroup" | "List", _, _), _, _) =>
c.copy(moduleTrait = "FacadeModule.ArrayChildren")
case c if Set("Breadcrumbs", "ToggleButtonGroup").contains(c.componentInfo.name) =>
c.copy(moduleTrait = "FacadeModule.ArrayChildren")
},
Compile / sourceGenerators += generateReactDocGenFacades("packages/mui-material/src", "@mui/material", "mui")
)

lazy val materialUiLab =
project
.configure(moduleConfig("@mui/lab", "5.0.0-alpha.110"))
.configure(moduleConfig("@mui/lab", "5.0.0-alpha.155"))
.enablePlugins(FacadeGeneratorPlugin)
.settings(
emotionNpmDeps,
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)
)
},
propInfoTransformer := commonPropInfoTransformer,
componentInfoTransformer := commonComponentInfoTransformer,
componentCodeGenInfoTransformer := {
case c if Set("Breadcrumbs", "ToggleButtonGroup").contains(c.componentInfo.name) =>
c.copy(moduleTrait = "FacadeModule.ArrayChildren")
},
Compile / sourceGenerators +=
generateReactDocGenFacades("packages/mui-lab/src", "@mui/lab", "mui.lab")
Compile / sourceGenerators += generateReactDocGenFacades("packages/mui-lab/src", "@mui/lab", "mui.lab")
)

val generateInstallInstructions = taskKey[Unit]("Generate install instructions in README.md")
Expand Down
13 changes: 0 additions & 13 deletions project/FacadeGeneratorPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,6 @@ object FacadeGeneratorPlugin extends AutoPlugin {
// workaround for https://github.com/reactjs/react-docgen/issues/463
val dir = autoImport.reactDocGenDir.value
FacadeGenerator.doCached[Unit](streams.value.cacheStoreFactory.make("yarn-install"), dir) {
os.proc("yarn", "remove", "--mutex", "network", "-W", "vrtest-mui")
.call(cwd = dir, stderr = os.Inherit, stdout = os.Inherit, check = false)
val toAdd =
List(
"@babel/[email protected]",
"@babel/[email protected]",
"@babel/[email protected]",
"@babel/[email protected]",
"@babel/[email protected]",
"@jridgewell/[email protected]"
)
os.proc("yarn", "add", "--mutex", "network", "-W", "-D", "[email protected]", toAdd)
.call(cwd = dir, stderr = os.Inherit, stdout = os.Inherit)
os.proc("yarn", "install", "--mutex", "network", "--prefer-offline")
.call(cwd = dir, stderr = os.Inherit, stdout = os.Inherit)
}
Expand Down
7 changes: 5 additions & 2 deletions project/Identifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ case class Identifier(value: String) {

object Identifier {
val keywords = Set("type", "true", "false")
def quotedIfNecessary(value: String) =
if (keywords.contains(value) || value.contains('-') || value.headOption.forall(_.isDigit))
def quotedIfNecessary(value: String) = {
if (value == "")
"`''`"
else if (keywords.contains(value) || value.contains('-') || value.headOption.forall(_.isDigit))
"`" + value + "`"
else
value
}
implicit val jf: JsonFormat[Identifier] = caseClass(apply _, unapply(_: Identifier))("value")
}

0 comments on commit 21ded3e

Please sign in to comment.