Created
March 28, 2018 16:39
-
-
Save Cynede/55900f1828565b532cdc69b1ce4fbbaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE CPP #-} | |
| {-# LANGUAGE MultiWayIf #-} | |
| {-# LANGUAGE UnicodeSyntax #-} | |
| import Shake.It.Off | |
| import Control.Monad (when) | |
| #if !( defined(mingw32_HOST_OS) || defined(__MINGW32__) ) | |
| import System.Posix.User | |
| #endif | |
| checkForAdminPrivilegies :: IO Bool | |
| checkForAdminPrivilegies = | |
| #if ( defined(mingw32_HOST_OS) || defined(__MINGW32__) ) | |
| return False -- TODO: check for administrator on windows | |
| #else | |
| fmap (== 0) getRealUserID | |
| >>= \isRoot → if isRoot then return True | |
| else return False | |
| #endif | |
| targetPath ∷ String | |
| targetPath = "target" | |
| buildPath ∷ Bool → String | |
| buildPath release = targetPath </> | |
| if release then "release" | |
| else "debug" | |
| buildCloyster ∷ Bool → Bool → Bool → IO () | |
| buildCloyster release backend frontend = do | |
| admin ← checkForAdminPrivilegies | |
| let buildArgsList = | |
| ["build", "--features", "ssl"] | |
| ++ ["--release" | release] | |
| when (not frontend) $ do | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → cargo ["update"] | |
| | otherwise → | |
| if admin then cargo ["update"] else | |
| rawSystem "sudo" ["cargo", "update"] >>= | |
| checkExitCode | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → cargo buildArgsList | |
| | otherwise → | |
| if admin then cargo buildArgsList else | |
| rawSystem "sudo" ("cargo" : buildArgsList) >>= | |
| checkExitCode | |
| cdir ← getCurrentDirectory | |
| let stemplates = cdir </> "templates" | |
| front = stemplates </> "front" | |
| frontdist = front </> "dist" | |
| dstemplates = cdir </> buildPath release </> "templates" | |
| naturalCopy = do removeDirIfExists dstemplates | |
| copyDir stemplates dstemplates | |
| when (not backend) $ do | |
| -- frontend building | |
| setCurrentDirectory front | |
| -- TODO: possibly will need sudo? but I hope not | |
| npm ["run", "build"] | |
| setCurrentDirectory cdir | |
| --- default target directory permisiion will not allow to create dir | |
| -- TODO: do not copy frontend dev files | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → naturalCopy | |
| | otherwise → | |
| if admin then naturalCopy else | |
| rawSystem "sudo" ["cp", "-rf", stemplates, dstemplates] >>= | |
| checkExitCode | |
| main ∷ IO () | |
| main = shake $ do | |
| args ← getArgs | |
| let release = "--release" ∈ args | |
| let backend = "--backend" ∈ args | |
| let frontend = "--frontend" ∈ args | |
| -- TODO: clean frontend! | |
| "clean | clean target with cargo" ∫ do | |
| putStrLn " -> Cleaning..." | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → cargo ["clean"] | |
| | otherwise → do | |
| admin ← checkForAdminPrivilegies | |
| if admin then cargo ["clean"] else | |
| rawSystem "sudo" ["cargo", "clean"] >>= | |
| checkExitCode | |
| "test | runs cargo test" ∫ do | |
| putStrLn " -> Running tests..." | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → cargo ["test"] | |
| | otherwise → do | |
| admin ← checkForAdminPrivilegies | |
| if admin then cargo ["test"] else | |
| rawSystem "sudo" ["cargo", "test"] >>= | |
| checkExitCode | |
| cloysterExecutable release ♯ buildCloyster release backend frontend | |
| "release | clean and build Release version with ssl" ◉ ["clean"] ∰ buildCloyster True backend frontend | |
| "run | run with ssl" ◉ [cloysterExecutable release] ∰ do | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → cargo ["run", "--features", "ssl"] | |
| | otherwise → do | |
| admin ← checkForAdminPrivilegies | |
| let runArgsList = | |
| ["run", "--features", "ssl"] | |
| ++ ["--release" | release] | |
| if admin then cargo runArgsList else | |
| rawSystem "sudo" ("cargo" : runArgsList) >>= | |
| checkExitCode | |
| return () | |
| where cloysterExecutable ∷ Bool → String | |
| cloysterExecutable r = | |
| if | os ∈ ["win32", "mingw32", "cygwin32"] → buildPath r </> "Cloyster.exe" | |
| | otherwise → buildPath r </> "Cloyster" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment