Skip to content

Commit

Permalink
Merge pull request #73 from mdibaiee/package-script
Browse files Browse the repository at this point in the history
(72): package and build script
  • Loading branch information
Nikita Tchayka committed Jun 9, 2017
2 parents a9ff673 + 3140d9f commit cfcd181
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

.build-dist
release.zip
# Created by https://www.gitignore.io/api/haskell

### Haskell ###
Expand Down
22 changes: 18 additions & 4 deletions Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ import Data.Text (Text)
import System.Info (os)
import qualified Control.Foldl as Foldl
import Filesystem.Path.CurrentOS
import Filesystem

clientStackYaml = "client-stack.yaml"
serverStackYaml = "stack.yaml"

main = do
projectDirectory <- pwdAsText
BuildCommand all gui core orchestrator run <- options "Haskell.do build file" buildSwitches
BuildCommand all gui core orchestrator run pkg <- options "Haskell.do build file" buildSwitches
if all
then buildAll projectDirectory
else do
when gui $ buildGUI projectDirectory
when core $ buildCore projectDirectory
when orchestrator $ buildOrchestrator projectDirectory
when run $ runHaskellDo projectDirectory
when pkg $ buildAndPackage projectDirectory


buildSwitches :: Parser BuildCommand
Expand All @@ -33,6 +35,7 @@ buildSwitches = BuildCommand
<*> switch "core" 'c' "Build processing/compilation core"
<*> switch "orchestrator" 'o' "Build orchestrator"
<*> switch "run" 'r' "Run Haskell.do"
<*> switch "package" 'p' "Package Haskell.do for release (caution: removes .stack-work before re-building)"

buildAll projectDirectory = do
buildCore projectDirectory
Expand Down Expand Up @@ -65,6 +68,19 @@ buildGUI pdir =
shell ("cp -R static " <> lineToText coreBinDirectory <> "/bin") ""
return ()

buildAndPackage projectDirectory = do
removeTree ".stack-work"
removeTree ".build-dist"
buildAll projectDirectory

createDirectory True ".build-dist"
rename "static" (".build-dist" </> "static")
(_, binPath) <- shellStrict "stack exec which haskell-do" ""
case textToLine binPath of
Just path -> copyFile (fromText . lineToText $ path) (".build-dist" </> "haskell-do")
Nothing -> return ()
shell "cd .build-dist; zip -r ../release.zip *" ""
rename (".build-dist" </> "static") "static"

buildOrchestrator pdir =
echo ""
Expand All @@ -75,9 +91,6 @@ runHaskellDo pdir = do
shell ("stack exec haskell-do --stack-yaml=" <> serverStackYaml <> " -- 8080") ""
return ()




-- Helpers
isWindows operatingSystem = "mingw" `T.isPrefixOf` T.pack operatingSystem
isOSX operatingSystem = "darwin" `T.isPrefixOf` T.pack operatingSystem
Expand All @@ -93,4 +106,5 @@ data BuildCommand = BuildCommand
, buildCommandCore :: Bool
, buildCommandOrchestrator :: Bool
, buildCommandRun :: Bool
, buildCommandPackage :: Bool
}
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- process
- directory
- filepath
- system-fileio

ghc-options:
- -Wall
Expand Down

0 comments on commit cfcd181

Please sign in to comment.