Skip to content

Commit f5d1fdc

Browse files
authored
Update docs-search to the latest version, simplify including it in the build (#775)
1 parent 456be94 commit f5d1fdc

File tree

13 files changed

+64
-69
lines changed

13 files changed

+64
-69
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ jobs:
7979
shell: bash
8080

8181
- name: Build
82-
run: stack build --pedantic
82+
run: |
83+
make
84+
stack build --pedantic
8385
shell: bash
8486

8587
- name: Install

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
if: runner.os != 'Windows'
6565
shell: bash
6666
run: |
67+
make
6768
stack install --dependencies-only
6869
mkdir artifacts
6970
stack build --copy-bins --local-bin-path ./artifacts
@@ -75,6 +76,7 @@ jobs:
7576
if: runner.os == 'Windows'
7677
shell: bash
7778
run: |
79+
make
7880
stack install --dependencies-only
7981
stack build --copy-bins --local-bin-path ./artifacts
8082
cp artifacts/spago.exe spago.exe

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ test/spago-test
33
.stack-work/
44
*~
55
**/__pycache__
6-
templates/docs-search-app.js
7-
templates/purescript-docs-search
6+
templates/docs-search-app*
7+
templates/purescript-docs-search*
88
.envrc
99
curator.log
1010
.DS_Store

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ If you'd like to develop spago locally, the recommended tool to use is [stack][s
3939
To compile the project from source you can do
4040

4141
```bash
42+
$ make
4243
$ stack build --fast
4344
```
4445

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all: fetch-templates
2+
3+
fetch-templates:
4+
@curl https://github.com/purescript/purescript-docs-search/releases/download/v0.0.10/docs-search-app.js -o templates/docs-search-app-0.0.10.js
5+
@curl https://github.com/purescript/purescript-docs-search/releases/download/v0.0.10/purescript-docs-search -o templates/purescript-docs-search-0.0.10
6+
@chmod +x templates/purescript-docs-search-0.0.10
7+
@curl https://github.com/purescript/purescript-docs-search/releases/download/v0.0.11/docs-search-app.js -o templates/docs-search-app-0.0.11.js
8+
@curl https://github.com/purescript/purescript-docs-search/releases/download/v0.0.11/purescript-docs-search -o templates/purescript-docs-search-0.0.11
9+
@chmod +x templates/purescript-docs-search-0.0.11
10+

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cache:
1616
- '.stack-work -> %STACK_YAML%, appveyor.yml'
1717

1818
install:
19+
- choco install -y make
1920
# http://help.appveyor.com/discussions/problems/6312-curl-command-not-found
2021
- set PATH=C:\Program Files\Git\mingw64\bin;%PATH%
2122
- curl --silent --show-error --output stack.zip --location "https://github.com/commercialhaskell/stack/releases/download/v%STACK_VERSION%/stack-%STACK_VERSION%-windows-x86_64.zip"
@@ -31,6 +32,7 @@ install:
3132
- chmod a+x purescript
3233

3334
build_script:
35+
- make
3436
- stack build
3537
- stack install --local-bin-path bin
3638

spago.cabal

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 77b5d785b2feb191ce5732a72494d5d950758a3c9dd77a3c98827bf19c3bafa3
7+
-- hash: 64b3d7194bb34705b51fef4eaafd1841f1900b6826a9cda155ba8d6572b9bd46
88

99
name: spago
1010
version: 0.20.0
@@ -21,10 +21,12 @@ extra-source-files:
2121
README.md
2222
CHANGELOG.md
2323
templates/bower.json
24-
templates/docs-search-app.js
24+
templates/docs-search-app-0.0.10.js
25+
templates/docs-search-app-0.0.11.js
2526
templates/gitignore
2627
templates/packages.dhall
27-
templates/purescript-docs-search
28+
templates/purescript-docs-search-0.0.10
29+
templates/purescript-docs-search-0.0.11
2830
templates/purs-repl
2931
templates/spago.dhall
3032
templates/srcMain.purs

src/Spago/Build.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ bundleModule maybeModuleName maybeTargetPath noBuild buildOpts usePsa = do
405405
DoBuild -> Run.withBuildEnv usePsa buildOpts $ build (Just bundleAction)
406406
NoBuild -> Run.getEnv >>= (flip runRIO) bundleAction
407407

408+
docsSearchTemplate :: (HasType LogFunc env, HasType PursCmd env) => RIO env Text
409+
docsSearchTemplate = ifM (Purs.hasMinPursVersion "0.14.0")
410+
(pure Templates.docsSearch0011)
411+
(pure Templates.docsSearch0010)
412+
413+
docsSearchAppTemplate :: (HasType LogFunc env, HasType PursCmd env) => RIO env Text
414+
docsSearchAppTemplate = ifM (Purs.hasMinPursVersion "0.14.0")
415+
(pure Templates.docsSearchApp0011)
416+
(pure Templates.docsSearchApp0010)
408417

409418
-- | Generate docs for the `sourcePaths` and run `purescript-docs-search build-index` to patch them.
410419
docs
@@ -424,8 +433,8 @@ docs format noSearch open = do
424433
when isHTMLFormat $ do
425434
when (noSearch == AddSearch) $ do
426435
logInfo "Making the documentation searchable..."
427-
writeTextFile ".spago/purescript-docs-search" Templates.docsSearch
428-
writeTextFile ".spago/docs-search-app.js" Templates.docsSearchApp
436+
writeTextFile ".spago/purescript-docs-search" =<< docsSearchTemplate
437+
writeTextFile ".spago/docs-search-app.js" =<< docsSearchAppTemplate
429438
let cmd = "node .spago/purescript-docs-search build-index --package-name " <> surroundQuote name
430439
logDebug $ "Running `" <> display cmd <> "`"
431440
shell cmd empty >>= \case
@@ -463,7 +472,7 @@ search = do
463472
, PursArg "docs"
464473
]
465474

466-
writeTextFile ".spago/purescript-docs-search" Templates.docsSearch
475+
writeTextFile ".spago/purescript-docs-search" =<< docsSearchTemplate
467476
let cmd = "node .spago/purescript-docs-search search --package-name " <> surroundQuote name
468477
logDebug $ "Running `" <> display cmd <> "`"
469478
viewShell $ callCommand $ Text.unpack cmd

src/Spago/Prelude.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Spago.Prelude
1212
, headMay
1313
, lastMay
1414
, empty
15+
, ifM
1516

1617
-- * Logging, errors, printing, etc
1718
, Pretty
@@ -70,7 +71,6 @@ module Spago.Prelude
7071
, repr
7172
, with
7273
, appendonly
73-
, docsSearchVersion
7474
, githubTokenEnvVar
7575
) where
7676

@@ -142,6 +142,9 @@ die reasons = do
142142
traverse_ logError reasons
143143
exitFailure
144144

145+
ifM :: Monad m => m Bool -> m a -> m a -> m a
146+
ifM p x y = p >>= \b -> if b then x else y
147+
145148
-- | Suppress the 'Left' value of an 'Either'
146149
hush :: Either a b -> Maybe b
147150
hush = either (const Nothing) Just
@@ -218,11 +221,6 @@ assertDirectory directory = do
218221
Directory.setPermissions directory private
219222

220223

221-
-- | Release tag for the `purescript-docs-search` app.
222-
docsSearchVersion :: Text
223-
docsSearchVersion = "v0.0.10"
224-
225-
226224
githubTokenEnvVar :: IsString t => t
227225
githubTokenEnvVar = "SPAGO_GITHUB_TOKEN"
228226

src/Spago/Purs.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Spago.Purs
55
, bundle
66
, docs
77
, pursVersion
8+
, hasMinPursVersion
89
, parseDocsFormat
910
, findFlag
1011
, DocsFormat(..)
@@ -144,6 +145,13 @@ pursVersion = Turtle.Bytes.shellStrictWithErr (purs <> " --version") empty >>= \
144145
where
145146
purs = "purs"
146147

148+
hasMinPursVersion :: (HasLogFunc env, HasPurs env) => Text -> RIO env Bool
149+
hasMinPursVersion maybeMinVersion = do
150+
PursCmd { compilerVersion } <- view (the @PursCmd)
151+
minVersion <- case Version.semver maybeMinVersion of
152+
Left _ -> die [ "Unable to parse min version: " <> displayShow maybeMinVersion ]
153+
Right minVersion -> pure minVersion
154+
pure $ compilerVersion >= minVersion
147155

148156
runWithOutput :: HasLogFunc env => Text -> Text -> Text -> RIO env ()
149157
runWithOutput command success failure = do

0 commit comments

Comments
 (0)