on master help sign in
Merge remote-tracking branch 'origin/aa/static-filepath' into aa/static-responsiveness
commitf2ca4b3c8166eb2eb6da2962088d1221a98318a5 authorAli Abrar <aliabrar@gmail.com> dateWed 30 Dec 2020, 15:28 (6 years ago) parent22bef48a5bbc16
5 files changed+24−5
ChangeLog.md+1 lib/asset/manifest/src-bin/static-th.hs+4−2 lib/asset/manifest/src/Obelisk/Asset/TH.hs+9 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 it 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 = staticAssetFilePathRaw \"static.out\""
3637 , "#else"
3738 , "static = staticAssetHashed " <> show root
39+ , "staticFilePath = staticAssetFilePathRaw " <> show root
3840 , "#endif"
3941 ]
4042 }
lib/asset/manifest/src/Obelisk/Asset/TH.hs+9
@@ -6,6 +6,8 @@ module Obelisk.Asset.TH
66 ( assetPath
77 , staticAssetRaw
88 , staticAssetHashed
9+ , staticAssetFilePath
10+ , staticAssetFilePathRaw
911 ) where
1012
1113import Obelisk.Asset.Gather
@@ -34,3 +36,10 @@ staticAssetRaw fp = returnQ $ LitE $ StringL $ staticPrefix </> fp
3436staticAssetHashed :: FilePath -> FilePath -> Q Exp
3537staticAssetHashed root fp = do
3638 LitE . StringL . (staticPrefix </>) <$> hashedAssetFilePath root fp
39+
40+staticAssetFilePathRaw :: FilePath -> FilePath -> Q Exp
41+staticAssetFilePathRaw root fp = returnQ $ LitE $ StringL $ root </> fp
42+
43+staticAssetFilePath :: FilePath -> FilePath -> Q Exp
44+staticAssetFilePath root fp = do
45+ LitE . StringL . (root </>) <$> hashedAssetFilePath root fp
lib/command/src/Obelisk/Command/Project.hs+7−3
@@ -70,7 +70,7 @@ import Obelisk.App (MonadObelisk, runObelisk, getObelisk)
7070import Obelisk.CliApp
7171import Obelisk.Command.Nix
7272import Obelisk.Command.Thunk
73−import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath, cp, nixShellPath)
73+import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath, cp, nixShellPath, lnPath)
7474
7575--TODO: Make this module resilient to random exceptions
7676
@@ -384,8 +384,12 @@ findProjectAssets root = do
384384 (readProcessAndLogStderr Debug)
385385 root
386386 pure (AssetSource_Derivation, T.pack $ root </> "static.out")
387− else fmap (AssetSource_Files,) $ readProcessAndLogStderr Debug $ setCwd (Just root) $
388− proc nixExePath ["eval", "-f", ".", "passthru.staticFilesImpure", "--raw"]
387+ else fmap (AssetSource_Files,) $ do
388+ path <- readProcessAndLogStderr Debug $ setCwd (Just root) $
389+ proc nixExePath ["eval", "-f", ".", "passthru.staticFilesImpure", "--raw"]
390+ _ <- readProcessAndLogStderr Debug $ setCwd (Just root) $
391+ proc lnPath ["-s", "-f", T.unpack path, "static.out"]
392+ pure path
389393
390394-- | Get the nix store path to the generated static asset manifest module (e.g., "obelisk-generated-static")
391395getHaskellManifestProjectPath :: 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