snaplet-purescript 0.5.2.3 → 0.6.0.0
raw patch · 4 files changed
+47/−49 lines, 4 files
Files
- snaplet-purescript.cabal +1/−3
- src/Snap/Snaplet/PureScript.hs +20/−20
- src/Snap/Snaplet/PureScript/Hooks.hs +1/−1
- src/Snap/Snaplet/PureScript/Internal.hs +25/−25
snaplet-purescript.cabal view
@@ -1,5 +1,5 @@ name: snaplet-purescript-version: 0.5.2.3+version: 0.6.0.0 synopsis: Automatic (re)compilation of purescript projects description: Automatic (re)compilation of purescript projects license: MIT@@ -33,6 +33,4 @@ shelly >= 0.4.1 hs-source-dirs: src- ghc-options:- -Wall default-language: Haskell2010
src/Snap/Snaplet/PureScript.hs view
@@ -51,22 +51,22 @@ verbosity <- liftIO (lookupDefault Verbose config "verbosity") bndl <- liftIO (lookupDefault True config "bundle") bundleName <- liftIO (lookupDefault "app.js" config "bundleName")- bundleExe <- liftIO (lookupDefault "psc-bundle" config "bundleExe")+ bundleExe <- liftIO (lookupDefault "purs" config "bundleExe") bundleOpts <- liftIO (lookupDefault mempty config "bundleOpts") modules <- liftIO (lookupDefault ["Main"] config "modules") psPath <- liftIO (lookupDefault mempty config "pureScriptPath")- pulpPath <- findOrInstallPulp psPath =<< liftIO (Cfg.lookup config "pulpPath")+ spagoPath <- findOrInstallSpago psPath =<< liftIO (Cfg.lookup config "spagoPath") psaOpts <- liftIO (lookupDefault mempty config "psaOpts") permissive <- liftIO (lookupDefault False config "permissiveInit") cm <- getCompilationFlavour- bowerfile <- fromText <$> getBowerFile+ spagofile <- fromText <$> getSpagoFile -- If they do not exist, create the required directories purs <- shelly $ verbosely $ chdir (fromText destDir) $ do mkdir_p (fromText outDir)- bowerFileExists <- test_f bowerfile- echo $ "Checking existance of " <> toTextIgnore bowerfile- unless bowerFileExists $ do- run_ (fromString $ getPulpPath pulpPath) ["init"]+ spagofileExists <- test_f spagofile+ echo $ "Checking existance of " <> toTextIgnore spagofile+ unless spagofileExists $ do+ run_ (fromString $ getSpagoPath spagoPath) ["init"] return PureScript { pursCompilationMode = cm@@ -75,7 +75,7 @@ , pursBundleName = bundleName , pursBundleExe = bundleExe , pursBundleOpts = bundleOpts- , pursPulpPath = pulpPath+ , pursSpagoPath = spagoPath , pursPsPath = psPath , pursPsaOpts = psaOpts , pursPermissiveInit = permissive@@ -93,7 +93,7 @@ res <- build purs _ <- bundle purs case res of- CompilationFailed reason -> unless permissive (fail (T.unpack reason))+ CompilationFailed reason -> unless permissive (error (T.unpack reason)) CompilationSucceeded -> return () shelly $ verbosely $ chdir (fromText destDir) $ postInitHook hooks@@ -136,8 +136,8 @@ chdir (fromText pursPwdDir) $ do I.prependToPath (fromText pursPsPath) preBuildHook pursHooks- let args = ["build", "-o", pursPwdDir <> "/" <> pursOutputDir] <> pursPsaOpts- run_ (fromString . getPulpPath $ pursPulpPath) args+ let args = ["build"] <> pursPsaOpts+ run_ (fromString . getSpagoPath $ pursSpagoPath) args eC <- lastExitCode preBuildHook pursHooks case (eC == 0) of@@ -157,15 +157,15 @@ rm_rf (fromText bundlePath) echo $ "Bundling everything in " <> bundlePath res <- case (pursBundleExe, pursBundleOpts) of- ("psc-bundle", []) ->+ ("purs", []) -> let modules = T.intercalate " -m " pursModules- pscBundlExe = maybeM "psc-bundle" (\x -> x <> "/" <> "psc-bundle") pursPsPath- in run (fromText pscBundlExe) (["js/**/*.js", "-m"]+ pursBundlExe = maybeM "purs" (\x -> x <> "/" <> "purs") pursPsPath+ in run (fromText pursBundlExe) (["bundle", "output/*/**/*.js", "-m"] <> (T.words modules) <> ["-o", bundlePath, "-n", "PS"])- ("pulp", []) ->+ ("spago", []) -> let modules = T.intercalate "," pursModules- in run (fromString $ getPulpPath pursPulpPath) (["build", "-I", "src", "--modules"]+ in run (fromString $ getSpagoPath pursSpagoPath) (["build", "-I", "src", "--modules"] <> (T.words modules) <> ["-t", bundlePath]) (exe, args) -> run (fromText exe) args@@ -232,7 +232,7 @@ # # Override the bundle command executable #-bundleExe = "pulp"+bundleExe = "purs" # # Override the bundle command arguments #@@ -244,11 +244,11 @@ # # pureScriptPath = "" #-# The path to a specific, user-provided version of Pulp.+# The path to a specific, user-provided version of Spago. # Leave it uncommented if you plan to use the globally-installed one or you # are OK with snaplet-purescript installing it for you. #-# pulpPath = ""+# spagoPath = "" # # Extra options to pass to https://github.com/natefaubion/purescript-psa, # if available.@@ -260,7 +260,7 @@ # to not start at all when you are debugging your PS. # # The name of the output bundle-bundleName = "app.js"+bundleName = "index.js" # # The list of modules you want to compile under the PS namespace (bundle only) # Adding 'Main' will make sure you will have something like PS.Main.main in
src/Snap/Snaplet/PureScript/Hooks.hs view
@@ -35,7 +35,7 @@ mkHook "" = noOpHook mkHook t = case T.words t of [] -> noOpHook- (x:args) -> run_ (fromText x) args+ (x:args) -> escaping False $ run_ (fromText x) args -------------------------------------------------------------------------------- getHooks :: Config -> IO Hooks
src/Snap/Snaplet/PureScript/Internal.hs view
@@ -6,15 +6,15 @@ CompilationMode(..) , CompilationOutput(..) , Verbosity(..)- , PulpPath(getPulpPath)+ , SpagoPath(getSpagoPath) , PureScript(..) , devFlagEnabled , getCompilationFlavour , getDestDir- , getBowerFile+ , getSpagoFile , getAbsoluteOutputDir , prependToPath- , findOrInstallPulp+ , findOrInstallSpago , shV , shS ) where@@ -47,11 +47,11 @@ convert _ = Nothing ---------------------------------------------------------------------------------newtype PulpPath = PulpPath { getPulpPath :: FilePath } deriving (Show, Read)+newtype SpagoPath = SpagoPath { getSpagoPath :: FilePath } deriving (Show, Read) -instance Configured PulpPath where+instance Configured SpagoPath where convert (String "") = Nothing- convert (String t) = Just . PulpPath . toS $ t+ convert (String t) = Just . SpagoPath . toS $ t convert _ = Nothing --------------------------------------------------------------------------------@@ -77,11 +77,11 @@ , pursBundleName :: !T.Text -- ^ The name for your bundled output. , pursBundleExe :: !T.Text- -- ^ The name for the program used to bundle your app. (e.g. "pulp", "psc-bundle", etc)+ -- ^ The name for the program used to bundle your app. (e.g. "spago", "psc-bundle", etc) , pursBundleOpts :: ![T.Text] -- ^ Override the arguments passed to the bundle executable.- , pursPulpPath :: !PulpPath- -- ^ The absolute path to a `pulp` executable. This can be user-provided+ , pursSpagoPath :: !SpagoPath+ -- ^ The absolute path to a `spago` executable. This can be user-provided -- or inferred automatically by this snaplet. , pursPsPath :: !T.Text -- ^ The absolute path to the directory containing the PureScript toolchain.@@ -120,22 +120,22 @@ shV = liftIO . shelly . verbosely . escaping False ---------------------------------------------------------------------------------findOrInstallPulp :: T.Text- -> Maybe PulpPath+findOrInstallSpago :: T.Text+ -> Maybe SpagoPath -> (Monad (m b v), MonadIO (m b v), MonadSnaplet m)- => m b v PulpPath-findOrInstallPulp psPath mbP = do- let p = fromMaybe (PulpPath "pulp") mbP- installed <- shS (pulpInstalled psPath p)+ => m b v SpagoPath+findOrInstallSpago psPath mbP = do+ let p = fromMaybe (SpagoPath "spago") mbP+ installed <- shS (spagoInstalled psPath p) case installed of True -> return p False -> shS $ do- echo "Pulp not found, installing it locally for you..."- installPulp >> whichPulp+ echo "Spago not found, installing it locally for you..."+ installSpago >> whichSpago ---------------------------------------------------------------------------------whichPulp :: MonadIO m => m PulpPath-whichPulp = PulpPath . toS . T.strip <$> shS (run "which" ["pulp"])+whichSpago :: MonadIO m => m SpagoPath+whichSpago = SpagoPath . toS . T.strip <$> shS (run "which" ["spago"]) -------------------------------------------------------------------------------- -- | add the filepath onto the PATH env variable@@ -146,12 +146,12 @@ setenv "PATH" $ tp <> T.singleton ':' <> pe ---------------------------------------------------------------------------------installPulp :: MonadIO m => m ()-installPulp = shS $ run_ "npm" ["install", "pulp"]+installSpago :: MonadIO m => m ()+installSpago = shS $ run_ "npm" ["install", "spago"] ---------------------------------------------------------------------------------pulpInstalled :: T.Text -> PulpPath -> Sh Bool-pulpInstalled psPath (PulpPath pp) = errExit False $ verbosely $ do+spagoInstalled :: T.Text -> SpagoPath -> Sh Bool+spagoInstalled psPath (SpagoPath pp) = errExit False $ verbosely $ do check `catchany_sh` \(e :: SomeException) -> do echo (toS . show $ e) return False@@ -192,8 +192,8 @@ return $ T.pack fp ---------------------------------------------------------------------------------getBowerFile :: (Monad (m b v), MonadIO (m b v), MonadSnaplet m) => m b v T.Text-getBowerFile = (`mappend` "/bower.json") <$> getDestDir+getSpagoFile :: (Monad (m b v), MonadIO (m b v), MonadSnaplet m) => m b v T.Text+getSpagoFile = (`mappend` "/spago.dhall") <$> getDestDir -------------------------------------------------------------------------------- getAbsoluteOutputDir :: Handler b PureScript T.Text