elm-lang / elm-reactor

Interactive development tool that makes it easy to develop and debug Elm programs.
BSD 3-Clause "New" or "Revised" License
428 stars 63 forks source link

Hide SideBar implementation #150

Closed bharrisau closed 8 years ago

bharrisau commented 9 years ago

As a solution to the issue of elm-reactor clobbering Elm imports, can we wrap the output of elm-make SideBar.elm and only expose Elm.SideBar? I've manually done this to my debug.js and it works (but I'm still getting up to speed on things)

var Elm = Elm || { Native: {} };
Elm.SideBar = (function () {
<-- elm-make frontend/SideBar.elm -->
return Elm.SideBar;
}());
<-- cat elm-implementation.js -->

Still learning Haskell, but the changes will be something like this in Setup.hs

myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
myPostBuild args flags pd lbi =
  do  putStrLn "Custom build step: creating and collecting all static resources"
+     writeFile output "var Elm = Elm || { Native: {} };\nElm.SideBar = (function () {"
      buildSideBar
+     src <- readFile (output ++ ".tmp")
+     appendFile output src
+     removeFile (output ++ ".tmp")
+     appendFile output "return Elm.SideBar;\n}());"
      src <- readFile ("frontend" </> "debugger-implementation.js")
      appendFile output src
      postBuild simpleUserHooks args flags pd lbi

buildSideBar :: IO ()
buildSideBar =
  do  (exitCode, out, err) <-
-        readProcessWithExitCode "elm-make" [ "--yes", "frontend" </> "SideBar.elm", "--output=" ++ output ] ""
+        readProcessWithExitCode "elm-make" [ "--yes", "frontend" </> "SideBar.elm", "--output=" ++ output ++ ".tmp" ] ""
bharrisau commented 9 years ago

cc #104

jvoigtlaender commented 8 years ago

Probably would also have helped address https://github.com/elm-lang/elm-reactor/pull/81.