on master help sign in
static: add staticFilePath
commit6f8d3175bcf8a4efda2c802448363d47d9eda6d1 authorAli Abrar <aliabrar@gmail.com> dateMon 28 Dec 2020, 23:56 (6 years ago) parentba1763c
5 files changed+19−5
ChangeLog.md+1 lib/asset/manifest/src-bin/static-th.hs+4−2 lib/asset/manifest/src/Obelisk/Asset/TH.hs+4 lib/command/src/Obelisk/Command/Project.hs+7−3 lib/command/src/Obelisk/Command/Utils.hs+3
ChangeLog.md+1
@@ -10,6 +10,7 @@ This project's release branch is `master`. This log is written from the perspect
1010 * Feature: Files added to the static directory while `ob run` is active no longer require `ob run` to be restarted
1111* Feature: When `staticFiles` is a derivation, as opposed to a regular directory, produce a symlink to the result of that derivation at `static.out` and have `ob run` serve static assets from that symlink. This makes is possible for the static asset derivation to be rebuilt and the new results served without restarting `ob run`.
1212* Feature: Rebuild static asset derivations while `ob run` is active as long as the change to the derivation is within the project folder. `ob run` now displays a message ("Static assets rebuilt and symlinked to static.out") whenever static assets have been rebuilt and the new static assets are being served.
13+* Feature: Add `staticFilePath` to `Obelisk.Generated.Static`. Like `static`, this uses TH to generate a reference to a file. Unlike `static`, this `staticFilePath` generates a path on the filesystem instead of URL path.
1314
1415## v0.9.1.0
1516
lib/asset/manifest/src-bin/static-th.hs+4−2
@@ -25,16 +25,18 @@ main = do
2525 , " Automatically generated module that provides the 'static' TH function"
2626 , " to generate paths to static assets."
2727 , "-}"
28− , "module " <> moduleName <> " ( static ) where"
28+ , "module " <> moduleName <> " ( static, staticFilePath ) where"
2929 , ""
3030 , "import Obelisk.Asset.TH"
3131 , "import Language.Haskell.TH"
3232 , ""
33− , "static :: FilePath -> Q Exp"
33+ , "static, staticFilePath :: FilePath -> Q Exp"
3434 , "#ifdef OBELISK_ASSET_PASSTHRU"
3535 , "static = staticAssetRaw"
36+ , "staticFilePath = assetPathRaw \"static.out\""
3637 , "#else"
3738 , "static = staticAssetHashed " <> show root
39+ , "staticFilePath = assetPath " <> show root
3840 , "#endif"
3941 ]
4042 }
lib/asset/manifest/src/Obelisk/Asset/TH.hs+4
@@ -4,6 +4,7 @@ Description:
44-}
55module Obelisk.Asset.TH
66 ( assetPath
7+ , assetPathRaw
78 , staticAssetRaw
89 , staticAssetHashed
910 ) where
@@ -34,3 +35,6 @@ staticAssetRaw fp = returnQ $ LitE $ StringL $ staticPrefix </> fp
3435staticAssetHashed :: FilePath -> FilePath -> Q Exp
3536staticAssetHashed root fp = do
3637 LitE . StringL . (staticPrefix </>) <$> hashedAssetFilePath root fp
38+
39+assetPathRaw :: FilePath -> FilePath -> Q Exp
40+assetPathRaw root fp = returnQ $ LitE $ StringL $ root </> fp
lib/command/src/Obelisk/Command/Project.hs+7−3
@@ -67,7 +67,7 @@ import Obelisk.App (MonadObelisk, runObelisk, getObelisk)
6767import Obelisk.CliApp
6868import Obelisk.Command.Nix
6969import Obelisk.Command.Thunk
70−import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath, cp, nixShellPath)
70+import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath, cp, nixShellPath, lnPath)
7171
7272--TODO: Make this module resilient to random exceptions
7373
@@ -381,8 +381,12 @@ findProjectAssets root = do
381381 (readProcessAndLogStderr Debug)
382382 root
383383 pure (AssetSource_Derivation, T.pack $ root </> "static.out")
384− else fmap (AssetSource_Files,) $ readProcessAndLogStderr Debug $ setCwd (Just root) $
385− proc nixExePath ["eval", "-f", ".", "passthru.staticFilesImpure", "--raw"]
384+ else fmap (AssetSource_Files,) $ do
385+ path <- readProcessAndLogStderr Debug $ setCwd (Just root) $
386+ proc nixExePath ["eval", "-f", ".", "passthru.staticFilesImpure", "--raw"]
387+ _ <- readProcessAndLogStderr Debug $ setCwd (Just root) $
388+ proc lnPath ["-s", "-f", T.unpack path, "static.out"]
389+ pure path
386390
387391-- | Get the nix store path to the generated static asset manifest module (e.g., "obelisk-generated-static")
388392getHaskellManifestProjectPath :: MonadObelisk m => FilePath -> m Text
lib/command/src/Obelisk/Command/Utils.hs+3
@@ -75,6 +75,9 @@ gitPath = $(staticWhich "git")
7575whichPath :: FilePath
7676whichPath = $(staticWhich "which")
7777
78+lnPath :: FilePath
79+lnPath = $(staticWhich "ln")
80+
7881sshKeygenPath :: FilePath
7982sshKeygenPath = $(staticWhich "ssh-keygen")
8083