mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 04:43:03 +03:00
Generate without full build
Adds `elm-pages generate` command which only builds `gen/Pages.elm`. Fixes #112
This commit is contained in:
parent
a125919f1d
commit
4da355b17e
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user