@@ -1,13 +1,13 @@
1−module Spago.Search.IndexBuilder where
1+module Docs.Search.IndexBuilder where
22
33import Prelude
44
5−import Spago.Search.Config (config)
6−import Spago.Search.Declarations (Declarations(..), mkDeclarations)
7−import Spago.Search.Extra ((>#>))
8−import Spago.Search.Index (getPartId)
9−import Spago.Search.SearchResult (SearchResult)
10−import Spago.Search.TypeIndex (TypeIndex, mkTypeIndex)
5+import Docs.Search.Config (config)
6+import Docs.Search.Declarations (Declarations(..), mkDeclarations)
7+import Docs.Search.Extra ((>#>))
8+import Docs.Search.Index (getPartId)
9+import Docs.Search.SearchResult (SearchResult)
10+import Docs.Search.TypeIndex (TypeIndex, mkTypeIndex)
1111
1212import Data.Argonaut.Core (stringify)
1313import Data.Argonaut.Decode (decodeJson)
@@ -17,6 +17,7 @@ import Data.Array as Array
1717import Data.Either (Either(..))
1818import Data.List (List)
1919import Data.List as List
20+import Data.Map (Map)
2021import Data.Map as Map
2122import Data.Maybe (Maybe(..))
2223import Data.Newtype (unwrap)
@@ -37,7 +38,7 @@ import Node.Encoding (Encoding(UTF8))
3738import Node.FS.Aff (exists, mkdir, readTextFile, readdir, stat, writeTextFile)
3839import Node.FS.Stats (isDirectory, isFile)
3940import Node.Process as Process
40−import Spago.Search.DocsJson (DocsJson)
41+import Docs.Search.DocsJson (DocsJson)
4142
4243main :: Effect Unit
4344main = launchAff_ mainAff
@@ -74,9 +75,7 @@ checkDirectories :: Aff Unit
7475checkDirectories = do
7576 for_ config.requiredDirectories \dir -> do
7677 whenM (not <$> directoryExists dir) $
77− liftEffect $ do
78− log "Run `spago build && spago docs` first!"
79− Process.exit 1
78+ liftEffect $ logAndExit "Generate the documentation first!"
8079
8180-- | Read and decode all `docs.json` files in the `outputDir`.
8281collectDocsJsons :: String -> Aff (Array DocsJson)
@@ -94,7 +93,7 @@ collectDocsJsons outputDir = do
9493 case eiResult of
9594 Left error -> do
9695 liftEffect $ log $
97− "`docs.json` decoding failed failed for module " <> moduleName <> ": " <> show error
96+ "\"docs.json\" decoding failed failed for module " <> moduleName <> ": " <> show error
9897 pure Nothing
9998 Right result -> pure result
10099
@@ -113,8 +112,8 @@ writeTypeIndex typeIndex =
113112 (mkHeader typeShape <> stringify (encodeJson results))
114113 where
115114 mkHeader typeShape =
116− "// This file was generated by spago\n" <>
117− "window.spagoTypeIndex[\"" <> typeShape <> "\"] = "
115+ "// This file was generated by purescript-docs-search\n" <>
116+ "window.DocsSearchTypeIndex[\"" <> typeShape <> "\"] = "
118117 entries :: Array _
119118 entries = Map.toUnfoldableUnordered (unwrap typeIndex)
120119
@@ -140,13 +139,16 @@ writeIndex (Declarations trie) = do
140139 in
141140 { prefix, results }
142141
143− resultsMap = Array.foldr (\part -> Map.insertWith append (getPartId part.prefix) part) mempty parts
142+ resultsMap :: Map Int (Array (Tuple String (Array SearchResult)))
143+ resultsMap = Array.foldr insert mempty parts
144+
145+ insert part = Map.insertWith append (getPartId part.prefix) part.results
144146
145147 for_ (Map.toUnfoldableUnordered resultsMap :: Array _)
146148 \(Tuple indexPartId results) -> do
147149 let header =
148− "// This file was generated by spago.\n" <>
149− "window.spagoIndex[\"" <> show indexPartId <> "\"] = "
150+ "// This file was generated by purescript-docs-search.\n" <>
151+ "window.DocsSearchIndex[\"" <> show indexPartId <> "\"] = "
150152
151153 writeTextFile UTF8 (config.mkIndexPartPath indexPartId) $
152154 header <> stringify (encodeJson results)
@@ -155,11 +157,11 @@ patchDocs :: Aff Unit
155157patchDocs = do
156158 let dirname = "generated-docs/"
157159 pattern = Pattern "</body>"
158− patch = "<!-- Spago search index. -->" <>
159− "<script type=\"text/javascript\" src=\"../spago-search-app.js\"></script>" <>
160+ patch = "<!-- Docs search index. -->" <>
161+ "<script type=\"text/javascript\" src=\"../docs-search-app.js\"></script>" <>
160162 "<script type=\"text/javascript\">" <>
161− "window.spagoTypeIndex = {};" <>
162− "window.spagoIndex = {};" <>
163+ "window.DocsSearchTypeIndex = {};" <>
164+ "window.DocsSearchIndex = {};" <>
163165 "</script>" <>
164166 "</body>"
165167
@@ -182,7 +184,7 @@ createDirectories = do
182184 typeIndexDir = "generated-docs/index/types"
183185
184186 whenM (not <$> directoryExists generatedDocsDir) $ liftEffect do
185− logAndExit "Run `spago docs` first!"
187+ logAndExit "Generate the documentation first!"
186188
187189 whenM (not <$> directoryExists indexDir) do
188190 mkdir indexDir