Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate without full build #123

Merged
merged 2 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 62 additions & 13 deletions generator/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,7 +151,7 @@ generateMarkdownPage markdown =

type CliOptions
= Develop DevelopOptions
| Build
| Build BuildOptions


type alias DevelopOptions =
Expand All @@ -164,6 +160,11 @@ type alias DevelopOptions =
}


type alias BuildOptions =
{ skipDist : Bool
}


application : Program.Config CliOptions
application =
Program.config
Expand All @@ -178,7 +179,10 @@ application =
|> OptionsParser.map Develop
)
|> Program.add
(OptionsParser.buildSubCommand "build" Build)
(OptionsParser.buildSubCommand "build" BuildOptions
|> with (Option.flag "skip-dist")
|> OptionsParser.map Build
)


type alias Flags =
Expand All @@ -197,24 +201,69 @@ 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 )
Build options ->
( buildDevelopMode options, False, Nothing )
in
{ watch = watch
{ develop = develop
, debug = debug
, customPort = customPort
}
|> encodeWriteFile
|> writeFile


buildDevelopMode : BuildOptions -> DevelopMode
buildDevelopMode { skipDist } =
if skipDist then
None

else
Run


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
Expand Down
8 changes: 4 additions & 4 deletions generator/src/elm-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ 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,
staticRoutes,
markdownContent
)
).then((payload) => {
if (cliOptions.watch) {
if (cliOptions.develop === 'start') {
develop.start({
routes,
debug: cliOptions.debug,
customPort: cliOptions.customPort,
manifestConfig: payload.manifest,

});
} else {
} else if (cliOptions.develop === 'run') {
develop.run({
routes,
debug: cliOptions.debug,
Expand All @@ -107,7 +107,7 @@ function run() {
}

}).catch(function (errorPayload) {
if (cliOptions.watch) {
if (cliOptions.develop === 'start') {
develop.start({
routes,
debug: cliOptions.debug,
Expand Down