Skip to content

Commit eee753a

Browse files
committed
Add shake build script
1 parent e40eb58 commit eee753a

File tree

7 files changed

+83
-18
lines changed

7 files changed

+83
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*~
33
Hoogle.alfredworkflow
44
workflow_skeleton/alfred-hoogle
5+
.shake/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
0.1.1
4+
=====
5+
6+
* Add shake build system.
7+
38
0.1.0
49
=====
510

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ Some settings are available as workflow variables in Alfred:
4747

4848
### Building
4949
1. Ensure `stack` is installed
50-
2. Run `./buildworkflow.sh` this makes `Hoggle.alfredworkflow`
50+
2. Run `./build.hs` script, this makes `Hoggle.alfredworkflow`
5151
3. Open it with Alfred

alfred-hoogle.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.24
22
name: alfred-hoogle
3-
version: 0.1.0
3+
version: 0.1.1
44
description: Hoogle from Alfred
55
synopsis: Hoogle from Alfred
66

@@ -44,6 +44,7 @@ executable alfred-hoogle
4444
, binary
4545
, silently
4646
, directory
47+
, shake
4748

4849

4950
default-language: Haskell2010

build.hs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env stack
2+
{- stack
3+
--resolver nightly-2019-02-04
4+
--install-ghc
5+
runghc
6+
--package shake
7+
--package text
8+
-}
9+
10+
{-# LANGUAGE OverloadedStrings #-}
11+
12+
import Data.Char (isSpace)
13+
import Data.List (dropWhileEnd)
14+
import Data.Maybe (catMaybes)
15+
import Data.Text (Text)
16+
import qualified Data.Text as T
17+
import qualified Data.Text.IO as TIO
18+
import Development.Shake
19+
import Development.Shake.FilePath
20+
21+
workflowFile :: FilePath
22+
workflowFile = "Hoogle.alfredworkflow"
23+
24+
executableFile :: FilePath
25+
executableFile = "alfred-hoogle"
26+
27+
main :: IO ()
28+
main =
29+
shakeArgs shakeOptions
30+
$ action
31+
$ withTempDir
32+
$ \tempDir -> do
33+
34+
-- Build the executable and copy to temp directory
35+
stackBuild
36+
binaryFp <- binaryPath
37+
copyFile' binaryFp $ tempDir </> executableFile
38+
39+
-- Copy the plist to temp dir and set the version number
40+
copyFile' ("workflow_skeleton" </> "info.plist")
41+
(tempDir </> "info.plist")
42+
ver <- cabalVer
43+
liftIO $ setPlistVersion ver $ tempDir </> "info.plist"
44+
45+
-- Compress the skeleton directory
46+
command_ []
47+
"zip"
48+
["-r", "-X", "-j", workflowFile, "workflow_skeleton"]
49+
50+
-- Add the executable and updated plist file to the archive
51+
command_ [] "zip" ["-r", "-X", "-j", workflowFile, tempDir]
52+
53+
54+
stackBuild :: Action ()
55+
stackBuild = command_ [] "stack" ["build"]
56+
57+
binaryPath :: Action FilePath
58+
binaryPath = do
59+
Stdout localbin <- command [] "stack" ["path", "--local-install-root"]
60+
return $ dropWhileEnd isSpace localbin </> "bin" </> executableFile
61+
62+
cabalVer :: Action Text
63+
cabalVer = do
64+
Stdout ver <- command [] "stack" ["ls", "dependencies"]
65+
return $ defVer $ catMaybes $ T.stripPrefix "alfred-hoogle " <$> T.lines (T.pack ver)
66+
where defVer [] = "0.0.0"
67+
defVer (x:_) = x
68+
69+
setPlistVersion :: Text -> FilePath -> IO ()
70+
setPlistVersion ver fp = do
71+
f <- TIO.readFile fp
72+
TIO.writeFile fp $ T.replace "VERSIONPLACEHOLDER" ver f

buildworkflow.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

workflow_skeleton/info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ Keyword is editable</string>
528528
<string>15</string>
529529
</dict>
530530
<key>version</key>
531-
<string>0.1.0</string>
531+
<string>VERSIONPLACEHOLDER</string>
532532
<key>webaddress</key>
533-
<string></string>
533+
<string>https://github.com/meck/alfred-hoogle</string>
534534
</dict>
535535
</plist>

0 commit comments

Comments
 (0)