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

Spago docs, now with indexing and search #1063

Merged
merged 27 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1cc06eb
Fix FFI getDirName()
CharlesTaylor7 Sep 30, 2023
e977b15
Integrate spago docs with docs-search IndexBuilder
CharlesTaylor7 Sep 30, 2023
1c1a69b
Bundle docs-search app during build
CharlesTaylor7 Sep 30, 2023
46905e0
Remove redundant format:check
CharlesTaylor7 Oct 7, 2023
2cd2971
Fix parsing
CharlesTaylor7 Oct 7, 2023
e281cde
Bundle markdown-it by externalizing punycode
CharlesTaylor7 Oct 8, 2023
36befc0
Alias punycode for browser bundle
CharlesTaylor7 Oct 8, 2023
6c4efbd
Fix link to docs-search
CharlesTaylor7 Oct 8, 2023
1c37963
Move client-halogen bundle
CharlesTaylor7 Oct 8, 2023
a9acdc0
remove trailing comma
CharlesTaylor7 Oct 8, 2023
067c6dc
Bundle before publish
CharlesTaylor7 Oct 8, 2023
73c1a44
Comment on the bundle alias
CharlesTaylor7 Oct 8, 2023
b2bf849
Merge branch 'master' into spago-docs-search
CharlesTaylor7 Oct 8, 2023
799e3a5
temporarily - silence test logs for CI
CharlesTaylor7 Oct 8, 2023
7fb942a
Include sym link
CharlesTaylor7 Oct 8, 2023
1a734b5
Use qualified imports
CharlesTaylor7 Oct 8, 2023
4f13bd1
Copy app bundle from symlink
CharlesTaylor7 Oct 9, 2023
44111fc
Revert "temporarily - silence test logs for CI"
CharlesTaylor7 Oct 9, 2023
f5d18f3
Revert code and fix symlink path
CharlesTaylor7 Oct 9, 2023
6f36983
Limit output for CI
CharlesTaylor7 Oct 9, 2023
1352d71
Group by packages
CharlesTaylor7 Oct 10, 2023
0fb3b64
Fix test case
CharlesTaylor7 Oct 10, 2023
84a90e9
Merge branch 'master' into spago-docs-search
CharlesTaylor7 Oct 11, 2023
33d0a78
Merge branch 'master' into spago-docs-search
f-f Oct 11, 2023
e201fb0
Construct paths with Path.concat
CharlesTaylor7 Oct 11, 2023
948dad7
Use stubfile for docs-search-app
CharlesTaylor7 Oct 11, 2023
05a6b88
Merge branch 'master' into spago-docs-search
CharlesTaylor7 Oct 11, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ jobs:
- name: Bootstrap executable
run: ./bin/index.dev.js bundle -p spago-bin

- name: Check code format
run: npm run format:check
CharlesTaylor7 marked this conversation as resolved.
Show resolved Hide resolved
- name: Bundle docs-search client
run: ./bin/index.dev.js bundle -p docs-search-client-halogen

- name: Run tests
run: spago test
Expand Down
9 changes: 9 additions & 0 deletions docs-search/client-halogen/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ package:
- web-html
- web-storage
- web-uievents
bundle:
type: "app"
minify: true
sourceMaps: true
module: Docs.Search.App
outfile: "../../output/Docs.Search.IndexBuilder/docs-search-app.js"
CharlesTaylor7 marked this conversation as resolved.
Show resolved Hide resolved
platform: browser
extra_args:
- "--alias:punycode=punycode/"
CharlesTaylor7 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion docs-search/client-halogen/src/Docs/Search/App.purs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ insertVersionInfo = do
prefix <- Document.createTextNode " - patched by " doc <#> Text.toNode
linkElement <- Document.createElement "a" doc
let linkNode = Element.toNode linkElement
Element.setAttribute "href" "https://github.com/purescript/purescript-docs-search" linkElement
Element.setAttribute "href" "https://github.com/purescript/spago/tree/master/docs-search" linkElement
Element.setAttribute "target" "_blank" linkElement
linkText <- Document.createTextNode ("docs-search") doc <#> Text.toNode
suffix <- Document.createTextNode (" " <> Config.version) doc <#> Text.toNode
Expand Down
15 changes: 12 additions & 3 deletions docs-search/common/src/Docs/Search/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,22 @@ penalties =
, excessiveConstraint: 1
}

defaultPackageName :: PackageName
defaultPackageName = wrap "<local package>"

-- | Find in which part of the index this path can be found.
getPartId :: List Char -> PartId
getPartId (a : b : _) =
PartId $ (Char.toCharCode a + Char.toCharCode b) `mod` numberOfIndexParts
getPartId (a : _) =
PartId $ Char.toCharCode a `mod` numberOfIndexParts
getPartId _ = PartId 0

defaultPackageName :: PackageName
defaultPackageName = wrap "<local package>"

defaultDocsFiles :: Array String
defaultDocsFiles = [ "output/**/docs.json" ]

defaultBowerFiles :: Array String
defaultBowerFiles = [ ".spago/*/*/bower.json", "bower_components/purescript-*/bower.json" ]

defaultSourceFiles :: Array String
defaultSourceFiles = [ "src/**/*.purs" ]
f-f marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 9 additions & 5 deletions docs-search/index/src/Docs/Search/IndexBuilder.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/* global __dirname require exports */

import globMain from "glob";
import path from "node:path";
import { fileURLToPath } from "node:url";

export function getDirname () {
return __dirname;
};
export function getDirname() {
const fileName = fileURLToPath(import.meta.url);
const dirName = path.dirname(fileName);
return dirName;
}
CharlesTaylor7 marked this conversation as resolved.
Show resolved Hide resolved

export function glob (pattern) {
export function glob(pattern) {
return function () {
return globMain.sync(pattern);
};
};
}
21 changes: 10 additions & 11 deletions docs-search/index/src/Docs/Search/IndexBuilder.purs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ run' cfg = do
<> show countOfModules
<> " modules from "
<> show countOfPackages
<>
" packages..."
<> " packages..."

let
scores = mkScores packageMetas
Expand Down Expand Up @@ -169,14 +168,18 @@ decodeDocsJsons cfg@{ docsFiles } = do
if doesExist then do

contents <- readTextFile UTF8 jsonFile
let eiResult = jsonParser contents >>= left JsonCodec.printDecodeError <<< decodeDocModule
let
eiResult :: Either String DocModule
eiResult =
jsonParser contents >>=
(Docs.toDocModule >>> left JsonCodec.printDecodeError)

case eiResult of
Left error -> do
liftEffect $ log $
"\"docs.json\" decoding failed failed for " <> jsonFile <> ": " <> error
pure Nothing
Right result -> pure result
Right result -> pure $ Just result

else do
liftEffect $ do
Expand All @@ -190,10 +193,6 @@ decodeDocsJsons cfg@{ docsFiles } = do

pure docsJsons

where
decodeDocModule :: Json -> Either JsonCodec.DecodeError (Maybe DocModule)
decodeDocModule = JsonCodec.toNullNothingOrJust Docs.toDocModule

-- | This function accepts an array of globs pointing to project sources
-- | and returns a list of module names extracted from these files.
-- | Unfortunately, we can't get all module names from `docs.json`s, because
Expand Down Expand Up @@ -236,9 +235,9 @@ decodeBowerJsons { bowerFiles } = do
for paths \jsonFileName ->
join <$> withExisting jsonFileName
\contents ->
either (logError jsonFileName) pure
either (logError jsonFileName) (pure <<< Just)
( jsonParser contents >>=
CA.decode (CA.maybe PackageIndex.packageMetaCodec) >>>
CA.decode (PackageIndex.packageMetaCodec) >>>
left CA.printJsonDecodeError
)

Expand All @@ -249,7 +248,7 @@ decodeBowerJsons { bowerFiles } = do

logError fileName error = do
liftEffect $ log $
"\"bower.json\" decoding failed failed for " <> fileName <> ": " <> error
"\"bower.json\" decoding failed for " <> fileName <> ": " <> error
pure Nothing

-- | Write type index parts to files.
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"glob": "^7.1.6",
"markdown-it": "^12.0.4",
"open": "^9.1.0",
"punycode": "^2.3.0",
"semver": "^7.3.5",
"spdx-expression-parse": "^3.0.1",
"ssh2": "^1.14.0",
Expand Down
4 changes: 2 additions & 2 deletions spago.lock
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ workspace:
- unicode
- versions
git: https://github.com/JordanMartinez/purescript-language-purescript.git
ref: v0.1.1
ref: db4377dea03ba9c5273a93a8368a53f1d87882c1
CharlesTaylor7 marked this conversation as resolved.
Show resolved Hide resolved
markdown-it:
dependencies:
- effect
Expand Down Expand Up @@ -1206,7 +1206,7 @@ packages:
language-purescript:
type: git
url: https://github.com/JordanMartinez/purescript-language-purescript.git
rev: b141a41333226af8702d67eb290470bba599b42a
rev: db4377dea03ba9c5273a93a8368a53f1d87882c1
dependencies:
- argonaut-core
- arrays
Expand Down
2 changes: 1 addition & 1 deletion spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ workspace:
git: https://github.com/nonbili/purescript-jest.git
ref: caf2032f2e5828337e897a99f5359c00e91cb0ee
language-purescript:
ref: v0.1.1
ref: db4377dea03ba9c5273a93a8368a53f1d87882c1
git: https://github.com/JordanMartinez/purescript-language-purescript.git
dependencies:
- argonaut-core
Expand Down
11 changes: 11 additions & 0 deletions src/Spago/Command/Docs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Spago.Prelude

import Control.Promise (Promise)
import Control.Promise as Promise
import Docs.Search.IndexBuilder as IndexBuilder
import Docs.Search.Config as DocConfig
import Effect.Uncurried (EffectFn1, runEffectFn1)
import Node.Process as Process
import Spago.Command.Build as Build
Expand Down Expand Up @@ -44,6 +46,15 @@ run = do
Right _ -> pure unit

when (docsFormat == Html) $ do
liftAff $ IndexBuilder.run'
{ docsFiles: DocConfig.defaultDocsFiles
, bowerFiles: DocConfig.defaultBowerFiles
, generatedDocs: "./generated-docs/"
, noPatch: false
, packageName: DocConfig.defaultPackageName
, sourceFiles: DocConfig.defaultSourceFiles
}

currentDir <- liftEffect Process.cwd
let link = "file://" <> currentDir <> "/generated-docs/html/index.html"
logInfo $ "Link: " <> link
Expand Down