mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-29 14:56:36 +03:00
Remove more webpack-related files.
This commit is contained in:
parent
238554457d
commit
ca9765b62a
@ -1,12 +0,0 @@
|
||||
import "elm-oembed";
|
||||
import "./style.css";
|
||||
import "./syntax.css";
|
||||
import "./lib/native-shim.js";
|
||||
|
||||
// @ts-ignore
|
||||
const { Elm } = require("./src/Main.elm");
|
||||
const pagesInit = require("../../index.js");
|
||||
|
||||
pagesInit({
|
||||
mainElmModule: Elm.Main
|
||||
});
|
@ -1,284 +0,0 @@
|
||||
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 : Encode.Value -> Cmd msg
|
||||
|
||||
|
||||
port printAndExitSuccess : String -> Cmd msg
|
||||
|
||||
|
||||
port printAndExitFailure : String -> Cmd msg
|
||||
|
||||
|
||||
generatePage : Page -> String
|
||||
generatePage page =
|
||||
interpolate """( {0}
|
||||
, \"\"\"{1}\"\"\"
|
||||
)
|
||||
"""
|
||||
[ pathFor page
|
||||
, page.contents
|
||||
]
|
||||
|
||||
|
||||
prerenderRcFormattedPath : String -> String
|
||||
prerenderRcFormattedPath path =
|
||||
path
|
||||
|> dropExtension
|
||||
|> chopForwardSlashes
|
||||
|> String.split "/"
|
||||
|> dropIndexFromLast
|
||||
|> String.join "/"
|
||||
|
||||
|
||||
dropIndexFromLast : List String -> List String
|
||||
dropIndexFromLast path =
|
||||
path
|
||||
|> List.reverse
|
||||
|> (\reversePath ->
|
||||
case List.head reversePath of
|
||||
Just "index" ->
|
||||
List.drop 1 reversePath
|
||||
|
||||
_ ->
|
||||
reversePath
|
||||
)
|
||||
|> List.reverse
|
||||
|
||||
|
||||
chopForwardSlashes : String -> String
|
||||
chopForwardSlashes =
|
||||
String.split "/" >> List.filter ((/=) "") >> String.join "/"
|
||||
|
||||
|
||||
pathFor : { entry | path : String } -> String
|
||||
pathFor page =
|
||||
page.path
|
||||
|> dropExtension
|
||||
|> chopForwardSlashes
|
||||
|> String.split "/"
|
||||
|> dropIndexFromLast
|
||||
|> List.map (\pathPart -> String.concat [ "\"", pathPart, "\"" ])
|
||||
|> String.join ", "
|
||||
|> (\list -> String.concat [ "[", list, "]" ])
|
||||
|
||||
|
||||
dropExtension : String -> String
|
||||
dropExtension path =
|
||||
if String.endsWith ".emu" path then
|
||||
String.dropRight 4 path
|
||||
|
||||
else if String.endsWith ".md" path then
|
||||
String.dropRight 3 path
|
||||
|
||||
else
|
||||
path
|
||||
|
||||
|
||||
generate : List Page -> List MarkdownContent -> String
|
||||
generate content markdownContent =
|
||||
interpolate """module RawContent exposing (content)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
|
||||
|
||||
content : { markdown : List ( List String, { frontMatter : String, body : Maybe String } ), markup : List ( List String, String ) }
|
||||
content =
|
||||
{ markdown = markdown }
|
||||
|
||||
|
||||
markdown : List ( List String, { frontMatter : String, body : Maybe String } )
|
||||
markdown =
|
||||
[ {1}
|
||||
]
|
||||
"""
|
||||
[ List.map generatePage content |> String.join "\n ,"
|
||||
, List.map generateMarkdownPage markdownContent |> String.join "\n ,"
|
||||
]
|
||||
|
||||
|
||||
isFrontmatterDelimeter : Maybe String -> Bool
|
||||
isFrontmatterDelimeter line =
|
||||
line == Just "---"
|
||||
|
||||
|
||||
splitMarkdown : String -> ( String, String )
|
||||
splitMarkdown contents =
|
||||
let
|
||||
lines =
|
||||
contents
|
||||
|> String.lines
|
||||
in
|
||||
if lines |> List.head |> isFrontmatterDelimeter then
|
||||
splitAtClosingDelimeter (lines |> List.drop 1)
|
||||
|
||||
else
|
||||
( "", lines |> String.join "\n" )
|
||||
|
||||
|
||||
splitAtClosingDelimeter : List String -> ( String, String )
|
||||
splitAtClosingDelimeter lines =
|
||||
List.Extra.splitWhen (\line -> line == "---") lines
|
||||
|> Maybe.map (Tuple.mapSecond (List.drop 1))
|
||||
|> Maybe.withDefault ( [], [] )
|
||||
|> Tuple.mapBoth (String.join "\n") (String.join "\n")
|
||||
|
||||
|
||||
generateMarkdownPage : MarkdownContent -> String
|
||||
generateMarkdownPage markdown =
|
||||
let
|
||||
( frontmatter, body ) =
|
||||
( markdown.metadata, markdown.body )
|
||||
in
|
||||
interpolate """( {0}
|
||||
, { frontMatter = \"\"\" {1}
|
||||
\"\"\"
|
||||
, body = Nothing }
|
||||
)
|
||||
"""
|
||||
[ pathFor markdown
|
||||
, frontmatter
|
||||
, body
|
||||
]
|
||||
|
||||
|
||||
type CliOptions
|
||||
= Develop DevelopOptions
|
||||
| Build BuildOptions
|
||||
|
||||
|
||||
type alias DevelopOptions =
|
||||
{ debugger : Bool
|
||||
, customPort : Maybe Int
|
||||
}
|
||||
|
||||
|
||||
type alias BuildOptions =
|
||||
{ skipDist : Bool
|
||||
}
|
||||
|
||||
|
||||
application : Program.Config CliOptions
|
||||
application =
|
||||
Program.config
|
||||
|> Program.add
|
||||
(OptionsParser.buildSubCommand "develop" DevelopOptions
|
||||
|> OptionsParser.withDoc "you can set the port with --port=3200"
|
||||
|> with (Option.flag "debug")
|
||||
|> with
|
||||
(Option.optionalKeywordArg "port"
|
||||
|> Option.validateMapIfPresent (String.toInt >> Result.fromMaybe "port needs to be an integer")
|
||||
)
|
||||
|> OptionsParser.map Develop
|
||||
)
|
||||
|> Program.add
|
||||
(OptionsParser.buildSubCommand "build" BuildOptions
|
||||
|> with (Option.flag "skip-dist")
|
||||
|> OptionsParser.map Build
|
||||
)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
Program.FlagsIncludingArgv Extras
|
||||
|
||||
|
||||
type alias Extras =
|
||||
{}
|
||||
|
||||
|
||||
type alias Page =
|
||||
{ path : String, contents : String }
|
||||
|
||||
|
||||
type alias MarkdownContent =
|
||||
{ path : String, metadata : String, body : String }
|
||||
|
||||
|
||||
type DevelopMode
|
||||
= None
|
||||
| Run
|
||||
| Start
|
||||
|
||||
|
||||
init : Flags -> CliOptions -> Cmd Never
|
||||
init flags cliOptions =
|
||||
let
|
||||
( develop, debug, customPort ) =
|
||||
case cliOptions of
|
||||
Develop options ->
|
||||
( Start, options.debugger, options.customPort )
|
||||
|
||||
Build options ->
|
||||
( buildDevelopMode options, False, Nothing )
|
||||
in
|
||||
{ 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
|
||||
(\file ->
|
||||
( prerenderRcFormattedPath file.path
|
||||
, file.body
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
main : Program.StatelessProgram Never Extras
|
||||
main =
|
||||
Program.stateless
|
||||
{ printAndExitFailure = printAndExitFailure
|
||||
, printAndExitSuccess = printAndExitSuccess
|
||||
, init = init
|
||||
, config = application
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
const path = require("path");
|
||||
|
||||
module.exports = function (markdown, includeBody) {
|
||||
return `content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
||||
content =
|
||||
[]`;
|
||||
};
|
||||
|
||||
function toEntry(entry, includeBody) {
|
||||
const extension = path.extname(entry.path).replace(/^\./, "");
|
||||
|
||||
let fullPath = entry.path
|
||||
.replace(/(index)?\.[^/.]+$/, "")
|
||||
.split("/")
|
||||
.filter((item) => item !== "")
|
||||
.map((fragment) => `"${fragment}"`);
|
||||
fullPath.splice(0, 1);
|
||||
|
||||
return `
|
||||
( [${fullPath.join(", ")}]
|
||||
, { frontMatter = ${JSON.stringify(entry.metadata)}
|
||||
, body = ${body(entry, includeBody)}
|
||||
, extension = "${extension}"
|
||||
} )
|
||||
`;
|
||||
}
|
||||
|
||||
function multilineElmString(string) {
|
||||
const escapedString = string
|
||||
.replace(/\\/g, "\\\\")
|
||||
.replace(/"""/g, '\\"\\"\\"');
|
||||
return `"""${escapedString}"""`;
|
||||
}
|
||||
|
||||
function body(entry, includeBody) {
|
||||
if (includeBody) {
|
||||
return `Just ${multilineElmString(entry.body)}`;
|
||||
} else {
|
||||
return `Nothing`;
|
||||
}
|
||||
}
|
||||
|
||||
// function staticData(entry, includeBody) {
|
||||
// if (includeBody) {
|
||||
// return `Just """${entry.staticData.replace(/\\/g, "\\\\")}
|
||||
// """
|
||||
// `;
|
||||
// } else {
|
||||
// return `Nothing`;
|
||||
// }
|
||||
// }
|
@ -6,7 +6,6 @@
|
||||
"description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "cd generator && elm make src/Main.elm --output src/Main.js --optimize",
|
||||
"test": "elm-test && jest --rootDir jest-tests",
|
||||
"review": "elm-review"
|
||||
},
|
||||
@ -49,4 +48,4 @@
|
||||
"bin": {
|
||||
"elm-pages": "generator/src/cli.js"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user