snaplet-purescript 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+58/−16 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- snaplet-purescript.cabal +6/−1
- src/Snap/Snaplet/PureScript.hs +35/−7
- src/Snap/Snaplet/PureScript/Internal.hs +17/−8
snaplet-purescript.cabal view
@@ -1,6 +1,7 @@ name: snaplet-purescript-version: 0.1.0.0+version: 0.2.0.0 synopsis: Automatic (re)compilation of purescript projects+description: Automatic (re)compilation of purescript projects license: MIT license-file: LICENSE author: Alfredo Di Napoli@@ -8,6 +9,10 @@ category: Web build-type: Simple cabal-version: >=1.10++source-repository head+ type: git+ location: https://github.com/adinapoli/snaplet-purescript library exposed-modules:
src/Snap/Snaplet/PureScript.hs view
@@ -39,11 +39,18 @@ let envCfg = fromText $ destDir <> T.pack ("/" <> env <> ".cfg") -- If they do not exist, create the required directories shelly $ silently $ do+ srcDirExisted <- test_f srcDir mapM_ mkdir_p [jsDir, srcDir] gruntFileExists <- test_f gruntfile envCfgExists <- test_f envCfg unless gruntFileExists $ writefile gruntfile (gruntTemplate buildDir)- unless envCfgExists $ touchfile envCfg+ unless envCfgExists $ do+ touchfile envCfg+ writefile envCfg (envCfgTemplate verbosity cm)+ unless srcDirExisted $ do+ let mainFile = srcDir </> (fromText "Main.purs")+ touchfile mainFile+ writefile mainFile mainTemplate -- compile at least once, regardless of the CompilationMode compileAll srcDir@@ -66,12 +73,14 @@ get >>= compileWithMode . pursCompilationMode -- Now get the requested file and try to serve it -- This returns something like /purs/Hello/index.js- -- TODO: Temporary: Strip "purs"- requestedJs <- T.drop 5 . TE.decodeUtf8 . rqURI <$> getRequest- pursLog $ "Serving " <> T.unpack requestedJs- jsDir <- getJsDir- let fulljsPath = jsDir <> requestedJs- (shelly $ silently $ readfile (fromText fulljsPath)) >>= writeText + (_, requestedJs) <- T.breakOn "/" . T.drop 1 . TE.decodeUtf8 . rqURI <$> getRequest+ case requestedJs of+ "" -> fail "The path you asked me to serve doesn't point anywhere!"+ _ -> do+ pursLog $ "Serving " <> T.unpack requestedJs+ jsDir <- getJsDir+ let fulljsPath = jsDir <> requestedJs+ (shelly $ silently $ readfile (fromText fulljsPath)) >>= writeText -------------------------------------------------------------------------------- compileAll :: MonadIO m => FilePath -> m ()@@ -107,4 +116,23 @@ grunt.loadNpmTasks("grunt-purescript"); grunt.registerTask("default", ["pscMake:lib"]); };+|]++--------------------------------------------------------------------------------+envCfgTemplate :: Verbosity -> CompilationMode -> T.Text+envCfgTemplate ver cm = T.pack $ printf [r|+ # Choose one between 'Verbose' and 'Quiet'+ verbosity = "%s"+ # Choose one between 'CompileOnce' and 'CompileAlways'+ compilationMode = "%s"+|] (show ver) (show cm)++--------------------------------------------------------------------------------+mainTemplate :: T.Text+mainTemplate = T.pack [r|+ module Main where++ import Debug.Trace++ main = trace "Hello PS world!" |]
src/Snap/Snaplet/PureScript/Internal.hs view
@@ -4,6 +4,7 @@ import Snap import Data.Monoid+import Data.Configurator as Cfg import Data.Configurator.Types import Text.Read hiding (String) import qualified Data.Text as T@@ -12,8 +13,12 @@ data CompilationMode = CompileOnce | CompileAlways- deriving Show+ deriving (Show, Read) +instance Configured CompilationMode where+ convert (String t) = readMaybe . T.unpack $ t+ convert _ = Nothing+ data Verbosity = Verbose | Quiet deriving (Show, Read, Eq) instance Configured Verbosity where@@ -27,11 +32,9 @@ } ----------------------------------------------------------------------------------- | TODO: This doesn't seem to work, but I do not want to --- spend all my time on this now. devFlagEnabled :: Bool devFlagEnabled =-#if defined(DEVELOPMENT)+#ifdef DEVELOPMENT True #else False@@ -43,10 +46,16 @@ -- -fdevelopment or the environment is "devel", 'CompileOnce' otherwise. getCompilationFlavour :: Initializer b v CompilationMode getCompilationFlavour = do- inDevelMode <- ("devel" ==) <$> getEnvironment- return $ if or [inDevelMode, devFlagEnabled]- then CompileAlways- else CompileOnce+ -- Any input for the user have highest priority+ cfg <- getSnapletUserConfig+ cm <- liftIO (Cfg.lookup cfg "compilationMode")+ case cm of+ Just c -> return c+ Nothing -> do+ inDevelMode <- ("devel" ==) <$> getEnvironment+ return $ if or [inDevelMode, devFlagEnabled]+ then CompileAlways+ else CompileOnce -------------------------------------------------------------------------------- getDestDir :: (Monad (m b v), MonadIO (m b v), MonadSnaplet m) => m b v T.Text