elm-pages 3.0.0-beta.34 → 3.0.0-beta.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -81,7 +81,7 @@ https://github.com/dillonkearns/elm-pages/projects
81
81
  You will see an error if the NPM and Elm package do not have a matching Compatibility Key. Usually it's best to upgrade to the latest version of both the Elm and NPM
82
82
  packages when you upgrade. However, in case you want to install versions that are behind the latest, the Compatibility Key is included here for reference.
83
83
 
84
- Current Compatibility Key: 14.
84
+ Current Compatibility Key: 15.
85
85
 
86
86
  ## Contributors ✨
87
87
 
@@ -25043,6 +25043,41 @@ var $author$project$Elm$Extra$topLevelValue = F2(
25043
25043
  }
25044
25044
  };
25045
25045
  });
25046
+ var $elm$core$String$isEmpty = function (string) {
25047
+ return string === '';
25048
+ };
25049
+ var $author$project$Internal$Compiler$documentation = F2(
25050
+ function (rawDoc, decl) {
25051
+ var doc = $elm$core$String$trim(rawDoc);
25052
+ if ($elm$core$String$isEmpty(doc)) {
25053
+ return decl;
25054
+ } else {
25055
+ switch (decl.$) {
25056
+ case 'Comment':
25057
+ return decl;
25058
+ case 'Block':
25059
+ var source = decl.a;
25060
+ return decl;
25061
+ default:
25062
+ var details = decl.a;
25063
+ return $author$project$Internal$Compiler$Declaration(
25064
+ _Utils_update(
25065
+ details,
25066
+ {
25067
+ docs: function () {
25068
+ var _v1 = details.docs;
25069
+ if (_v1.$ === 'Nothing') {
25070
+ return $elm$core$Maybe$Just(doc);
25071
+ } else {
25072
+ var existing = _v1.a;
25073
+ return $elm$core$Maybe$Just(doc + ('\n\n' + existing));
25074
+ }
25075
+ }()
25076
+ }));
25077
+ }
25078
+ }
25079
+ });
25080
+ var $author$project$Elm$withDocumentation = $author$project$Internal$Compiler$documentation;
25046
25081
  var $author$project$Generate$file = F2(
25047
25082
  function (templates, basePath) {
25048
25083
  var routes = A2($elm$core$List$filterMap, $author$project$Pages$Internal$RoutePattern$fromModuleName, templates);
@@ -25124,8 +25159,11 @@ var $author$project$Generate$file = F2(
25124
25159
  $elm$core$Maybe$Just(
25125
25160
  A2($author$project$Elm$Annotation$named, _List_Nil, 'Route'))),
25126
25161
  function (route) {
25127
- return $author$project$Gen$Path$toAbsolute(
25128
- toPath.call(route));
25162
+ return A2(
25163
+ $author$project$Elm$withType,
25164
+ $author$project$Elm$Annotation$string,
25165
+ $author$project$Gen$Path$toAbsolute(
25166
+ toPath.call(route)));
25129
25167
  });
25130
25168
  var redirectTo = A2(
25131
25169
  $author$project$Elm$declaration,
@@ -25155,7 +25193,25 @@ var $author$project$Generate$file = F2(
25155
25193
  var toLink = A4(
25156
25194
  $author$project$Elm$Declare$fn2,
25157
25195
  'toLink',
25158
- _Utils_Tuple2('toAnchorTag', $elm$core$Maybe$Nothing),
25196
+ _Utils_Tuple2(
25197
+ 'toAnchorTag',
25198
+ $elm$core$Maybe$Just(
25199
+ A2(
25200
+ $author$project$Elm$Annotation$function,
25201
+ _List_fromArray(
25202
+ [
25203
+ $author$project$Elm$Annotation$list(
25204
+ A3(
25205
+ $author$project$Elm$Annotation$namedWith,
25206
+ _List_fromArray(
25207
+ ['Html']),
25208
+ 'Attribute',
25209
+ _List_fromArray(
25210
+ [
25211
+ $author$project$Elm$Annotation$var('msg')
25212
+ ])))
25213
+ ]),
25214
+ $author$project$Elm$Annotation$var('a')))),
25159
25215
  _Utils_Tuple2(
25160
25216
  'route',
25161
25217
  $elm$core$Maybe$Just(
@@ -25163,45 +25219,85 @@ var $author$project$Generate$file = F2(
25163
25219
  F2(
25164
25220
  function (toAnchorTag, route) {
25165
25221
  return A2(
25166
- $author$project$Elm$apply,
25167
- toAnchorTag,
25168
- _List_fromArray(
25169
- [
25170
- $author$project$Elm$list(
25171
- _List_fromArray(
25172
- [
25173
- $author$project$Gen$Html$Attributes$call_.href(
25174
- toString.call(route)),
25175
- A2($author$project$Gen$Html$Attributes$attribute, 'elm-pages:prefetch', '')
25176
- ]))
25177
- ]));
25222
+ $author$project$Elm$withType,
25223
+ $author$project$Elm$Annotation$var('a'),
25224
+ A2(
25225
+ $author$project$Elm$apply,
25226
+ toAnchorTag,
25227
+ _List_fromArray(
25228
+ [
25229
+ $author$project$Elm$list(
25230
+ _List_fromArray(
25231
+ [
25232
+ $author$project$Gen$Html$Attributes$call_.href(
25233
+ toString.call(route)),
25234
+ A2($author$project$Gen$Html$Attributes$attribute, 'elm-pages:prefetch', '')
25235
+ ]))
25236
+ ])));
25178
25237
  }));
25179
25238
  var link = A2(
25180
25239
  $author$project$Elm$declaration,
25181
25240
  'link',
25182
- A4(
25183
- $author$project$Elm$fn3,
25184
- _Utils_Tuple2('attributes', $elm$core$Maybe$Nothing),
25185
- _Utils_Tuple2('children', $elm$core$Maybe$Nothing),
25186
- _Utils_Tuple2(
25187
- 'route',
25188
- $elm$core$Maybe$Just(
25189
- A2($author$project$Elm$Annotation$named, _List_Nil, 'Route'))),
25190
- F3(
25191
- function (attributes, children, route) {
25192
- return A2(
25193
- toLink.call,
25194
- A2(
25195
- $author$project$Elm$fn,
25196
- _Utils_Tuple2('anchorAttrs', $elm$core$Maybe$Nothing),
25197
- function (anchorAttrs) {
25198
- return A2(
25199
- $author$project$Gen$Html$call_.a,
25200
- A2($author$project$Elm$Op$append, anchorAttrs, attributes),
25201
- children);
25202
- }),
25203
- route);
25204
- })));
25241
+ A2(
25242
+ $author$project$Elm$withType,
25243
+ A2(
25244
+ $author$project$Elm$Annotation$function,
25245
+ _List_fromArray(
25246
+ [
25247
+ $author$project$Elm$Annotation$list(
25248
+ A3(
25249
+ $author$project$Elm$Annotation$namedWith,
25250
+ _List_fromArray(
25251
+ ['Html']),
25252
+ 'Attribute',
25253
+ _List_fromArray(
25254
+ [
25255
+ $author$project$Elm$Annotation$var('msg')
25256
+ ]))),
25257
+ $author$project$Elm$Annotation$list(
25258
+ A3(
25259
+ $author$project$Elm$Annotation$namedWith,
25260
+ _List_fromArray(
25261
+ ['Html']),
25262
+ 'Html',
25263
+ _List_fromArray(
25264
+ [
25265
+ $author$project$Elm$Annotation$var('msg')
25266
+ ]))),
25267
+ A2($author$project$Elm$Annotation$named, _List_Nil, 'Route')
25268
+ ]),
25269
+ A3(
25270
+ $author$project$Elm$Annotation$namedWith,
25271
+ _List_fromArray(
25272
+ ['Html']),
25273
+ 'Html',
25274
+ _List_fromArray(
25275
+ [
25276
+ $author$project$Elm$Annotation$var('msg')
25277
+ ]))),
25278
+ A4(
25279
+ $author$project$Elm$fn3,
25280
+ _Utils_Tuple2('attributes', $elm$core$Maybe$Nothing),
25281
+ _Utils_Tuple2('children', $elm$core$Maybe$Nothing),
25282
+ _Utils_Tuple2(
25283
+ 'route',
25284
+ $elm$core$Maybe$Just(
25285
+ A2($author$project$Elm$Annotation$named, _List_Nil, 'Route'))),
25286
+ F3(
25287
+ function (attributes, children, route) {
25288
+ return A2(
25289
+ toLink.call,
25290
+ A2(
25291
+ $author$project$Elm$fn,
25292
+ _Utils_Tuple2('anchorAttrs', $elm$core$Maybe$Nothing),
25293
+ function (anchorAttrs) {
25294
+ return A2(
25295
+ $author$project$Gen$Html$call_.a,
25296
+ A2($author$project$Elm$Op$append, anchorAttrs, attributes),
25297
+ children);
25298
+ }),
25299
+ route);
25300
+ }))));
25205
25301
  var withoutBaseUrl = A2(
25206
25302
  $author$project$Elm$declaration,
25207
25303
  'withoutBaseUrl',
@@ -25230,24 +25326,27 @@ var $author$project$Generate$file = F2(
25230
25326
  A2(
25231
25327
  $elm$core$List$map,
25232
25328
  $author$project$Generate$expose,
25233
- _List_fromArray(
25234
- [
25235
- A2(
25236
- $author$project$Elm$customType,
25237
- 'Route',
25238
- A2($elm$core$List$map, $author$project$Pages$Internal$RoutePattern$toVariant, routes)),
25239
- segmentsToRouteFn.declaration,
25240
- urlToRoute,
25241
- baseUrl.declaration,
25242
- routeToPathFn.declaration,
25243
- baseUrlAsPath.declaration,
25244
- toPath.declaration,
25245
- toString.declaration,
25246
- redirectTo,
25247
- toLink.declaration,
25248
- link,
25249
- withoutBaseUrl
25250
- ])),
25329
+ A2(
25330
+ $elm$core$List$map,
25331
+ $author$project$Elm$withDocumentation('.'),
25332
+ _List_fromArray(
25333
+ [
25334
+ A2(
25335
+ $author$project$Elm$customType,
25336
+ 'Route',
25337
+ A2($elm$core$List$map, $author$project$Pages$Internal$RoutePattern$toVariant, routes)),
25338
+ segmentsToRouteFn.declaration,
25339
+ urlToRoute,
25340
+ baseUrl.declaration,
25341
+ routeToPathFn.declaration,
25342
+ baseUrlAsPath.declaration,
25343
+ toPath.declaration,
25344
+ toString.declaration,
25345
+ redirectTo,
25346
+ toLink.declaration,
25347
+ link,
25348
+ withoutBaseUrl
25349
+ ]))),
25251
25350
  _List_fromArray(
25252
25351
  [$author$project$Generate$splitPath.declaration, $author$project$Generate$maybeToList.declaration])
25253
25352
  ])));
@@ -90,6 +90,7 @@ async function main() {
90
90
  .description("run an elm-pages script")
91
91
  .allowUnknownOption()
92
92
  .allowExcessArguments()
93
+ .helpOption(false) // allow --help to propogate to the Script to show usage
93
94
  .action(async (elmModulePath, options, options2) => {
94
95
  const unprocessedCliOptions = options2.args.splice(
95
96
  options2.processedArgs.length,
@@ -325,16 +326,11 @@ async function requireElm(compiledElmPath) {
325
326
  function generatorWrapperFile(moduleName) {
326
327
  return `port module Main exposing (main)
327
328
 
328
- import BackendTask exposing (BackendTask)
329
- import FatalError
330
- import Cli.Program as Program
331
- import Json.Decode as Decode
332
- import Json.Encode as Encode
333
329
  import Pages.Internal.Platform.GeneratorApplication
334
330
  import ${moduleName}
335
331
 
336
332
 
337
- main : Program.StatefulProgram Pages.Internal.Platform.GeneratorApplication.Model Pages.Internal.Platform.GeneratorApplication.Msg (BackendTask FatalError.FatalError ()) Pages.Internal.Platform.GeneratorApplication.Flags
333
+ main : Pages.Internal.Platform.GeneratorApplication.Program
338
334
  main =
339
335
  Pages.Internal.Platform.GeneratorApplication.app
340
336
  { data = ${moduleName}.run
@@ -345,13 +341,13 @@ main =
345
341
  }
346
342
 
347
343
 
348
- port toJsPort : Encode.Value -> Cmd msg
344
+ port toJsPort : Pages.Internal.Platform.GeneratorApplication.JsonValue -> Cmd msg
349
345
 
350
346
 
351
- port fromJsPort : (Decode.Value -> msg) -> Sub msg
347
+ port fromJsPort : (Pages.Internal.Platform.GeneratorApplication.JsonValue -> msg) -> Sub msg
352
348
 
353
349
 
354
- port gotBatchSub : (Decode.Value -> msg) -> Sub msg
350
+ port gotBatchSub : (Pages.Internal.Platform.GeneratorApplication.JsonValue -> msg) -> Sub msg
355
351
  `;
356
352
  }
357
353
  function collect(value, previous) {
@@ -1,3 +1,3 @@
1
- export const compatibilityKey = 14;
1
+ export const compatibilityKey = 15;
2
2
 
3
- export const packageVersion = "3.0.0-beta.34";
3
+ export const packageVersion = "3.0.0-beta.35";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elm-pages",
3
3
  "type": "module",
4
- "version": "3.0.0-beta.34",
4
+ "version": "3.0.0-beta.35",
5
5
  "homepage": "https://elm-pages.com",
6
6
  "moduleResolution": "node",
7
7
  "description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
@@ -65,7 +65,7 @@ frontmatter frontmatterDecoder =
65
65
 
66
66
  import BackendTask exposing (BackendTask)
67
67
  import BackendTask.File as File
68
- import Decode as Decode exposing (Decoder)
68
+ import Decode exposing (Decoder)
69
69
 
70
70
  blogPost : BackendTask BlogPostMetadata
71
71
  blogPost =
@@ -101,7 +101,7 @@ It's common to parse the body with a markdown parser or other format.
101
101
 
102
102
  import BackendTask exposing (BackendTask)
103
103
  import BackendTask.File as File
104
- import Decode as Decode exposing (Decoder)
104
+ import Decode exposing (Decoder)
105
105
  import Html exposing (Html)
106
106
 
107
107
  example :
@@ -151,13 +151,28 @@ bodyWithFrontmatter :
151
151
  }
152
152
  frontmatter
153
153
  bodyWithFrontmatter frontmatterDecoder filePath =
154
- read filePath
155
- (body
156
- |> Decode.andThen
157
- (\bodyString ->
158
- frontmatter (frontmatterDecoder bodyString)
159
- )
160
- )
154
+ BackendTask.Internal.Request.request2
155
+ { name = "read-file"
156
+ , body = BackendTask.Http.stringBody "" filePath
157
+ , expect =
158
+ body
159
+ |> Decode.andThen
160
+ (\bodyString ->
161
+ frontmatter (frontmatterDecoder bodyString)
162
+ )
163
+ , errorDecoder = Decode.field "errorCode" (errorDecoder filePath)
164
+ , onError =
165
+ \frontmatterDecodeError ->
166
+ { fatal =
167
+ { title = "BackendTask.File Decoder Error"
168
+ , body =
169
+ "I encountered a Json Decoder error from a call to BackendTask.File.bodyWithFrontmatter.\n\n"
170
+ ++ Decode.errorToString frontmatterDecodeError
171
+ }
172
+ |> FatalError.build
173
+ , recoverable = DecodingError frontmatterDecodeError
174
+ }
175
+ }
161
176
 
162
177
 
163
178
  {-| -}
@@ -174,7 +189,7 @@ just the metadata.
174
189
 
175
190
  import BackendTask exposing (BackendTask)
176
191
  import BackendTask.File as File
177
- import Decode as Decode exposing (Decoder)
192
+ import Decode exposing (Decoder)
178
193
 
179
194
  blogPost : BackendTask BlogPostMetadata
180
195
  blogPost =
@@ -198,7 +213,7 @@ the [`BackendTask`](BackendTask) API along with [`BackendTask.Glob`](BackendTask
198
213
 
199
214
  import BackendTask exposing (BackendTask)
200
215
  import BackendTask.File as File
201
- import Decode as Decode exposing (Decoder)
216
+ import Decode exposing (Decoder)
202
217
 
203
218
  blogPostFiles : BackendTask (List String)
204
219
  blogPostFiles =
@@ -231,8 +246,23 @@ onlyFrontmatter :
231
246
  }
232
247
  frontmatter
233
248
  onlyFrontmatter frontmatterDecoder filePath =
234
- read filePath
235
- (frontmatter frontmatterDecoder)
249
+ BackendTask.Internal.Request.request2
250
+ { name = "read-file"
251
+ , body = BackendTask.Http.stringBody "" filePath
252
+ , expect = frontmatter frontmatterDecoder
253
+ , errorDecoder = Decode.field "errorCode" (errorDecoder filePath)
254
+ , onError =
255
+ \frontmatterDecodeError ->
256
+ { fatal =
257
+ { title = "BackendTask.File Decoder Error"
258
+ , body =
259
+ "I encountered a Json Decoder error from a call to BackendTask.File.onlyFrontmatter.\n\n"
260
+ ++ Decode.errorToString frontmatterDecodeError
261
+ }
262
+ |> FatalError.build
263
+ , recoverable = DecodingError frontmatterDecodeError
264
+ }
265
+ }
236
266
 
237
267
 
238
268
  {-| Same as `bodyWithFrontmatter` except it doesn't include the frontmatter.
@@ -1,7 +1,9 @@
1
- module BackendTask.Internal.Request exposing (request)
1
+ module BackendTask.Internal.Request exposing (request, request2)
2
2
 
3
3
  import BackendTask exposing (BackendTask)
4
- import BackendTask.Http exposing (Body, Expect)
4
+ import BackendTask.Http exposing (Body, Error(..), Expect)
5
+ import Json.Decode exposing (Decoder)
6
+ import Json.Encode as Encode
5
7
 
6
8
 
7
9
  request :
@@ -22,7 +24,50 @@ request ({ name, body, expect } as params) =
22
24
  }
23
25
  expect
24
26
  |> BackendTask.onError
25
- (\_ ->
27
+ (\error ->
28
+ let
29
+ _ =
30
+ Debug.log "BackendTask.Internal.Request" error
31
+ in
26
32
  -- TODO avoid crash here, this should be handled as an internal error
27
33
  request params
28
34
  )
35
+
36
+
37
+ request2 :
38
+ { name : String
39
+ , body : Body
40
+ , expect : Decoder a
41
+ , errorDecoder : Decoder error
42
+ , onError : Json.Decode.Error -> error
43
+ }
44
+ -> BackendTask error a
45
+ request2 ({ name, body, expect, onError, errorDecoder } as params) =
46
+ -- elm-review: known-unoptimized-recursion
47
+ BackendTask.Http.request
48
+ { url = "elm-pages-internal://" ++ name
49
+ , method = "GET"
50
+ , headers = []
51
+ , body = body
52
+ , timeoutInMs = Nothing
53
+ , retries = Nothing
54
+ }
55
+ (BackendTask.Http.expectJson Json.Decode.value)
56
+ |> BackendTask.onError
57
+ (\error ->
58
+ BackendTask.succeed Encode.null
59
+ )
60
+ |> BackendTask.andThen
61
+ (\decodeValue ->
62
+ case Json.Decode.decodeValue errorDecoder decodeValue of
63
+ Ok a ->
64
+ BackendTask.fail a
65
+
66
+ Err _ ->
67
+ case Json.Decode.decodeValue expect decodeValue of
68
+ Ok a ->
69
+ BackendTask.succeed a
70
+
71
+ Err e ->
72
+ BackendTask.fail (onError e)
73
+ )
@@ -1,4 +1,4 @@
1
- module FatalError exposing (FatalError, fromString, recoverable)
1
+ module FatalError exposing (FatalError, build, fromString, recoverable)
2
2
 
3
3
  {-| The Elm language doesn't have the concept of exceptions or special control flow for errors. It just has
4
4
  Custom Types, and by convention types like `Result` and the `Err` variant are used to represent possible failure states
@@ -54,7 +54,7 @@ issue.
54
54
  In the case of server-rendered Routes (`RouteBuilder.serverRender`), `elm-pages` will show your 500 error page
55
55
  when these errors occur.
56
56
 
57
- @docs FatalError, fromString, recoverable
57
+ @docs FatalError, build, fromString, recoverable
58
58
 
59
59
  -}
60
60
 
@@ -66,7 +66,8 @@ type alias FatalError =
66
66
  Pages.Internal.FatalError.FatalError
67
67
 
68
68
 
69
- {-| -}
69
+ {-| Create a FatalError with a title and body.
70
+ -}
70
71
  build : { title : String, body : String } -> FatalError
71
72
  build info =
72
73
  Pages.Internal.FatalError.FatalError info
@@ -3,4 +3,4 @@ module Pages.Internal.Platform.CompatibilityKey exposing (currentCompatibilityKe
3
3
 
4
4
  currentCompatibilityKey : Int
5
5
  currentCompatibilityKey =
6
- 14
6
+ 15
@@ -1,8 +1,8 @@
1
- module Pages.Internal.Platform.GeneratorApplication exposing (Flags, Model, Msg(..), init, requestDecoder, update, app)
1
+ module Pages.Internal.Platform.GeneratorApplication exposing (Program, Flags, Model, Msg(..), init, requestDecoder, update, app, JsonValue)
2
2
 
3
3
  {-| Exposed for internal use only (used in generated code).
4
4
 
5
- @docs Flags, Model, Msg, init, requestDecoder, update, app
5
+ @docs Program, Flags, Model, Msg, init, requestDecoder, update, app, JsonValue
6
6
 
7
7
  -}
8
8
 
@@ -25,6 +25,16 @@ import Pages.StaticHttp.Request
25
25
  import TerminalText as Terminal
26
26
 
27
27
 
28
+ {-| -}
29
+ type alias JsonValue =
30
+ Decode.Value
31
+
32
+
33
+ {-| -}
34
+ type alias Program =
35
+ Program.StatefulProgram Model Msg (BackendTask FatalError.FatalError ()) Flags
36
+
37
+
28
38
  {-| -}
29
39
  type alias Flags =
30
40
  { compatibilityKey : Int
@@ -47,7 +57,7 @@ type Msg
47
57
  {-| -}
48
58
  app :
49
59
  GeneratorProgramConfig
50
- -> Program.StatefulProgram Model Msg (BackendTask FatalError ()) Flags
60
+ -> Program
51
61
  app config =
52
62
  let
53
63
  cliConfig : Program.Config (BackendTask FatalError ())
@@ -68,13 +68,7 @@ nextStep allRawResponses staticResponses { errors } =
68
68
  )
69
69
  in
70
70
  if pendingRequests then
71
- let
72
- newThing : List HashRequest.Request
73
- newThing =
74
- urlsToPerform
75
- |> List.Extra.uniqueBy HashRequest.hash
76
- in
77
- Continue newThing progressedBackendTask
71
+ Continue urlsToPerform progressedBackendTask
78
72
 
79
73
  else
80
74
  let