Generate without full build

Adds `elm-pages generate` command which only builds `gen/Pages.elm`.

Fixes #112
This commit is contained in:
Phill Sparks 2020-06-23 21:57:26 +01:00
parent a125919f1d
commit 4da355b17e
No known key found for this signature in database
GPG Key ID: DA53DF9BB8928B10
2 changed files with 52 additions and 14 deletions

View File

@ -3,16 +3,12 @@ port module Main exposing (main)
import Cli.Option as Option
import Cli.OptionsParser as OptionsParser exposing (with)
import Cli.Program as Program
import Json.Encode as Encode
import List.Extra
import String.Interpolate exposing (interpolate)
port writeFile :
{ watch : Bool
, debug : Bool
, customPort : Maybe Int
}
-> Cmd msg
port writeFile : Encode.Value -> Cmd msg
port printAndExitSuccess : String -> Cmd msg
@ -156,6 +152,7 @@ generateMarkdownPage markdown =
type CliOptions
= Develop DevelopOptions
| Build
| Generate
type alias DevelopOptions =
@ -179,6 +176,8 @@ application =
)
|> Program.add
(OptionsParser.buildSubCommand "build" Build)
|> Program.add
(OptionsParser.buildSubCommand "generate" Generate)
type alias Flags =
@ -197,24 +196,63 @@ type alias MarkdownContent =
{ path : String, metadata : String, body : String }
type DevelopMode
= None
| Run
| Start
init : Flags -> CliOptions -> Cmd Never
init flags cliOptions =
let
( watch, debug, customPort ) =
( develop, debug, customPort ) =
case cliOptions of
Develop options ->
( True, options.debugger, options.customPort )
( Start, options.debugger, options.customPort )
Build ->
( False, False, Nothing )
( Run, False, Nothing )
Generate ->
( None, False, Nothing )
in
{ watch = watch
{ develop = develop
, debug = debug
, customPort = customPort
}
|> encodeWriteFile
|> writeFile
encodeWriteFile : { develop : DevelopMode, debug : Bool, customPort : Maybe Int } -> Encode.Value
encodeWriteFile { develop, debug, customPort } =
Encode.object
[ ( "develop", encodeDevelop develop )
, ( "debug", Encode.bool debug )
, ( "customPort", encodeCustomPort customPort )
]
encodeDevelop : DevelopMode -> Encode.Value
encodeDevelop develop =
case develop of
None ->
Encode.string "none"
Run ->
Encode.string "run"
Start ->
Encode.string "start"
encodeCustomPort : Maybe Int -> Encode.Value
encodeCustomPort maybePort =
maybePort
|> Maybe.map Encode.int
|> Maybe.withDefault Encode.null
generateFileContents : List MarkdownContent -> List ( String, String )
generateFileContents =
List.map

View File

@ -81,7 +81,7 @@ function run() {
});
const routes = toRoutes(markdownContent);
global.mode = cliOptions.watch ? "dev" : "prod"
global.mode = cliOptions.develop === 'start' ? "dev" : "prod"
generateRecords().then((staticRoutes) =>
doCliStuff(
global.mode,
@ -89,7 +89,7 @@ function run() {
markdownContent
)
).then((payload) => {
if (cliOptions.watch) {
if (cliOptions.develop === 'start') {
develop.start({
routes,
debug: cliOptions.debug,
@ -97,7 +97,7 @@ function run() {
manifestConfig: payload.manifest,
});
} else {
} else if (cliOptions.develop === 'run') {
develop.run({
routes,
debug: cliOptions.debug,
@ -107,7 +107,7 @@ function run() {
}
}).catch(function (errorPayload) {
if (cliOptions.watch) {
if (cliOptions.develop === 'start') {
develop.start({
routes,
debug: cliOptions.debug,