git.iko.soy/lynxjs-elm/compiler
on master help sign in
Improve DX: add fork suggestions, clean command, and better dev feedback
9c9b074iko
builder/src/Lynx/Patches.hs+17
@@ -3,6 +3,7 @@ module Lynx.Patches
3 ( installFork
3 ( installFork
4 , installAllForks
4 , installAllForks
5 , isFork
5 , isFork
6+ , forkSuggestion
6 , injectRegistry
7 , injectRegistry
7 , forkContentHash
8 , forkContentHash
8 )
9 )
@@ -98,6 +99,22 @@ isFork pkg =
98 pkg == Pkg.virtualDom || pkg == Pkg.browser || pkg == Pkg.http || pkg == Pkg.ui || pkg == Pkg.crypto
99 pkg == Pkg.virtualDom || pkg == Pkg.browser || pkg == Pkg.http || pkg == Pkg.ui || pkg == Pkg.crypto
99
100
100
101
102+-- FORK SUGGESTION
103+--
104+-- When a user tries to install elm/browser, elm/virtual-dom, or elm/http,
105+-- suggest the lynxjs-elm fork instead.
106+
107+
108+forkSuggestion :: Pkg.Name -> Maybe Pkg.Name
109+forkSuggestion pkg
110+ | chars == "elm/virtual-dom" = Just Pkg.virtualDom
111+ | chars == "elm/browser" = Just Pkg.browser
112+ | chars == "elm/http" = Just Pkg.http
113+ | otherwise = Nothing
114+ where
115+ chars = Pkg.toChars pkg
116+
117+
101
118
102-- INSTALL ALL FORKS
119-- INSTALL ALL FORKS
103--
120--
builder/src/Reporting/Exit.hs+14
@@ -746,6 +746,7 @@ data Install
746 | InstallHadSolverTrouble Solver
746 | InstallHadSolverTrouble Solver
747 | InstallUnknownPackageOnline Pkg.Name [Pkg.Name]
747 | InstallUnknownPackageOnline Pkg.Name [Pkg.Name]
748 | InstallUnknownPackageOffline Pkg.Name [Pkg.Name]
748 | InstallUnknownPackageOffline Pkg.Name [Pkg.Name]
749+ | InstallForkSuggestion Pkg.Name Pkg.Name
749 | InstallBadDetails Details
750 | InstallBadDetails Details
750
751
751
752
@@ -890,6 +891,19 @@ installToReport exit =
890 , D.reflow $ "Maybe you want one of these instead?"
891 , D.reflow $ "Maybe you want one of these instead?"
891 ]
892 ]
892
893
894+ InstallForkSuggestion pkg forkPkg ->
895+ Help.docReport "FORKED PACKAGE" Nothing
896+ (
897+ D.fillSep
898+ ["The","package",D.red (D.fromPackage pkg),"has","been","replaced"
899+ ,"by",D.green (D.fromPackage forkPkg),"for","LynxJS."
900+ ]
901+ )
902+ [ D.reflow "Try this instead:"
903+ , D.indent 4 $ D.green $ D.fromChars $
904+ "lynxjs-elm install " ++ Pkg.toChars forkPkg
905+ ]
906+
893 InstallBadDetails details ->
907 InstallBadDetails details ->
894 toDetailsReport details
908 toDetailsReport details
895
909
lynxjs-elm.cabal+1
@@ -53,6 +53,7 @@ Executable lynxjs-elm
53
53
54 other-modules:
54 other-modules:
55 Bump
55 Bump
56+ Clean
56 Dev
57 Dev
57 Develop
58 Develop
58 Diff
59 Diff
terminal/src/Clean.hsnew file+38
@@ -0,0 +1,38 @@
1+module Clean
2+ ( run
3+ )
4+ where
5+
6+
7+import Control.Monad (when)
8+import qualified System.Directory as Dir
9+
10+import qualified Stuff
11+
12+
13+
14+-- RUN
15+
16+
17+run :: () -> () -> IO ()
18+run () () =
19+ do maybeRoot <- Stuff.findRoot
20+ case maybeRoot of
21+ Nothing ->
22+ putStrLn "I cannot find an elm.json file. There is nothing to clean here."
23+
24+ Just root ->
25+ do let elmStuff = root ++ "/elm-stuff"
26+ exists <- Dir.doesDirectoryExist elmStuff
27+ when exists $
28+ do Dir.removeDirectoryRecursive elmStuff
29+ putStrLn "Removed elm-stuff/"
30+ home <- Stuff.getElmHome
31+ let bundlerDir = home ++ "/bundler"
32+ bundlerExists <- Dir.doesDirectoryExist bundlerDir
33+ when bundlerExists $
34+ do Dir.removeDirectoryRecursive bundlerDir
35+ putStrLn "Removed bundler cache."
36+ if exists || bundlerExists
37+ then putStrLn "All clean!"
38+ else putStrLn "Already clean — nothing to remove."
terminal/src/Dev.hs+5−1
@@ -114,6 +114,8 @@ run path (Flags maybePort verbose) =
114 putStrLn ""
114 putStrLn ""
115
115
116 -- Watch for changes, recompile, and rebuild
116 -- Watch for changes, recompile, and rebuild
117+ putStrLn " Watching for changes..."
118+ putStrLn ""
117 let cleanup = do Process.terminateProcess serveHandle
119 let cleanup = do Process.terminateProcess serveHandle
118 _ <- Process.waitForProcess serveHandle
120 _ <- Process.waitForProcess serveHandle
119 return ()
121 return ()
@@ -296,7 +298,9 @@ printQrCode bundlerDir url =
296 exitCode <- Process.waitForProcess ph
298 exitCode <- Process.waitForProcess ph
297 case exitCode of
299 case exitCode of
298 SysExit.ExitSuccess -> return ()
300 SysExit.ExitSuccess -> return ()
299− SysExit.ExitFailure _ -> return () -- silently skip if not available
301+ SysExit.ExitFailure _ ->
302+ do putStrLn " Scan the URL above in LynxJS Explorer to preview."
303+ putStrLn ""
300
304
301
305
302
306
terminal/src/Install.hs+17−11
@@ -18,6 +18,7 @@ import qualified Elm.Details as Details
18import qualified Elm.Package as Pkg
18import qualified Elm.Package as Pkg
19import qualified Elm.Outline as Outline
19import qualified Elm.Outline as Outline
20import qualified Elm.Version as V
20import qualified Elm.Version as V
21+import qualified Lynx.Patches as Patches
21import qualified Reporting
22import qualified Reporting
22import Reporting.Doc ((<+>))
23import Reporting.Doc ((<+>))
23import qualified Reporting.Doc as D
24import qualified Reporting.Doc as D
@@ -50,17 +51,22 @@ run args () =
50 return (Left (Exit.InstallNoArgs elmHome))
51 return (Left (Exit.InstallNoArgs elmHome))
51
52
52 Install pkg ->
53 Install pkg ->
54+ case Patches.forkSuggestion pkg of
55+ Just forkPkg ->
56+ return (Left (Exit.InstallForkSuggestion pkg forkPkg))
57+
58+ Nothing ->
53− Task.run $
59+ Task.run $
54− do env <- Task.eio Exit.InstallBadRegistry $ Solver.initEnv
60+ do env <- Task.eio Exit.InstallBadRegistry $ Solver.initEnv
55− oldOutline <- Task.eio Exit.InstallBadOutline $ Outline.read root
61+ oldOutline <- Task.eio Exit.InstallBadOutline $ Outline.read root
56− case oldOutline of
62+ case oldOutline of
57− Outline.App outline ->
63+ Outline.App outline ->
58− do changes <- makeAppPlan env pkg outline
64+ do changes <- makeAppPlan env pkg outline
59− attemptChanges root env oldOutline V.toChars changes
65+ attemptChanges root env oldOutline V.toChars changes
60−
66+
61− Outline.Pkg outline ->
67+ Outline.Pkg outline ->
62− do changes <- makePkgPlan env pkg outline
68+ do changes <- makePkgPlan env pkg outline
63− attemptChanges root env oldOutline C.toChars changes
69+ attemptChanges root env oldOutline C.toChars changes
64
70
65
71
66
72
terminal/src/Main.hs+25
@@ -15,6 +15,7 @@ import Terminal
15import Terminal.Helpers
15import Terminal.Helpers
16
16
17import qualified Bump
17import qualified Bump
18+import qualified Clean
18import qualified Dev
19import qualified Dev
19import qualified Develop
20import qualified Develop
20import qualified Diff
21import qualified Diff
@@ -40,6 +41,7 @@ main =
40 , make
41 , make
41 , install
42 , install
42 , uninstall
43 , uninstall
44+ , clean
43 , bump
45 , bump
44 , diff
46 , diff
45 , publish
47 , publish
@@ -288,6 +290,29 @@ uninstall =
288
290
289
291
290
292
293+-- CLEAN
294+
295+
296+clean :: Terminal.Command
297+clean =
298+ let
299+ summary =
300+ "Remove cached build artifacts. This clears elm-stuff/ in the current\
301+ \ project and the shared bundler cache."
302+
303+ details =
304+ "The `clean` command removes cached build artifacts:"
305+
306+ example =
307+ reflow
308+ "This is useful when you hit strange build errors or want a fresh start.\
309+ \ It removes elm-stuff/ from your project and the bundler cache. Your\
310+ \ source code and elm.json are not touched."
311+ in
312+ Terminal.Command "clean" (Common summary) details example noArgs noFlags Clean.run
313+
314+
315+
291-- PUBLISH
316-- PUBLISH
292
317
293
318