mirror of
https://github.com/anoma/juvix.git
synced 2024-12-15 10:03:22 +03:00
3d012cc8fb
- Closes #1993 This pr makes it possible to use `~`, `..` and environment variables in the `juvix.yaml` and all flags / input of the cli. In the CLI, the shell will be responsible for replacing environment variables with their value, so the usual syntax can be used. For the `dependencies` field, I have implemented a parser that has some restrictions: 1. Environment variables are given with the makefile-like syntax `$(VAR)` 2. The three characters `$` `(` `)` are reserved for the environment variables syntax. They cannot be part of the path. 3. `~` is reserved for `$(HOME)`. I.e. the prepath `~~` will expand to `$HOME$HOME`. 4. Nested environment variables are not allowed. Thanks @paulcadman for the feedback. I think we are ready to merge this nightmarish pr 👻 --------- Co-authored-by: Paul Cadman <git@paulcadman.dev>
67 lines
2.6 KiB
Haskell
67 lines
2.6 KiB
Haskell
module Commands.Html where
|
|
|
|
import Commands.Base
|
|
import Commands.Html.Options
|
|
import Juvix.Compiler.Backend.Html.Translation.FromTyped (JudocArgs (..))
|
|
import Juvix.Compiler.Backend.Html.Translation.FromTyped qualified as Html
|
|
import Juvix.Compiler.Backend.Html.Translation.FromTyped.Source
|
|
( GenSourceHtmlArgs (..),
|
|
)
|
|
import Juvix.Compiler.Concrete.Pretty qualified as Concrete
|
|
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping qualified as Scoper
|
|
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping.Data.Context
|
|
import Juvix.Extra.Process
|
|
import System.Process qualified as Process
|
|
|
|
runGenOnlySourceHtml :: (Members '[Embed IO, App] r) => HtmlOptions -> Sem r ()
|
|
runGenOnlySourceHtml HtmlOptions {..} = do
|
|
res <- runPipeline _htmlInputFile upToScoping
|
|
let m = head (res ^. Scoper.resultModules)
|
|
outputDir <- fromAppPathDir _htmlOutputDir
|
|
embed $
|
|
Html.genSourceHtml
|
|
GenSourceHtmlArgs
|
|
{ _genSourceHtmlArgsAssetsDir = _htmlAssetsPrefix,
|
|
_genSourceHtmlArgsHtmlKind = Html.HtmlSrc,
|
|
_genSourceHtmlArgsParamBase = "",
|
|
_genSourceHtmlArgsUrlPrefix = _htmlUrlPrefix,
|
|
_genSourceHtmlArgsConcreteOpts = Concrete.defaultOptions,
|
|
_genSourceHtmlArgsModule = m,
|
|
_genSourceHtmlArgsComments = res ^. comments,
|
|
_genSourceHtmlArgsOutputDir = outputDir,
|
|
_genSourceHtmlArgsNoFooter = _htmlNoFooter,
|
|
_genSourceHtmlArgsNonRecursive = _htmlNonRecursive,
|
|
_genSourceHtmlArgsTheme = _htmlTheme
|
|
}
|
|
|
|
runCommand :: (Members '[Embed IO, App] r) => HtmlOptions -> Sem r ()
|
|
runCommand HtmlOptions {..}
|
|
| _htmlOnlySource = runGenOnlySourceHtml HtmlOptions {..}
|
|
| otherwise = do
|
|
ctx <- runPipeline _htmlInputFile upToInternalTyped
|
|
outputDir <- fromAppPathDir _htmlOutputDir
|
|
Html.genJudocHtml
|
|
JudocArgs
|
|
{ _judocArgsAssetsPrefix = _htmlAssetsPrefix,
|
|
_judocArgsBaseName = "proj",
|
|
_judocArgsCtx = ctx,
|
|
_judocArgsOutputDir = outputDir,
|
|
_judocArgsUrlPrefix = _htmlUrlPrefix,
|
|
_judocArgsTheme = _htmlTheme,
|
|
_judocArgsNonRecursive = _htmlNonRecursive,
|
|
_judocArgsNoFooter = _htmlNoFooter
|
|
}
|
|
when _htmlOpen $ case openCmd of
|
|
Nothing -> say "Could not recognize the 'open' command for your OS"
|
|
Just opencmd ->
|
|
embed
|
|
( void
|
|
( Process.spawnProcess
|
|
opencmd
|
|
[ toFilePath
|
|
( outputDir <//> Html.indexFileName
|
|
)
|
|
]
|
|
)
|
|
)
|