elm-pages 3.0.0-beta.3 → 3.0.0-beta.31
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 +10 -1
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2864 -2589
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +16458 -13724
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/dead-code-review/elm.json +9 -7
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +24542 -21748
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/review/elm.json +10 -10
- package/generator/src/RouteBuilder.elm +113 -107
- package/generator/src/SharedTemplate.elm +3 -2
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +125 -88
- package/generator/src/cli.js +273 -88
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +43 -26
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +150 -133
- package/generator/src/dir-helpers.js +9 -26
- package/generator/src/elm-codegen.js +5 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +12 -11
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +23 -22
- package/generator/src/init.js +9 -8
- package/generator/src/pre-render-html.js +39 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +25 -28
- package/generator/src/render.js +320 -142
- package/generator/src/request-cache.js +252 -163
- package/generator/src/resolve-elm-module.js +63 -0
- package/generator/src/rewrite-client-elm-json.js +6 -5
- package/generator/src/rewrite-elm-json-help.js +56 -0
- package/generator/src/rewrite-elm-json.js +17 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +12 -7
- package/generator/src/vite-utils.js +77 -0
- package/generator/static-code/hmr.js +79 -13
- package/generator/template/app/Api.elm +6 -5
- package/generator/template/app/Effect.elm +123 -0
- package/generator/template/app/ErrorPage.elm +37 -6
- package/generator/template/app/Route/Index.elm +17 -10
- package/generator/template/app/Shared.elm +24 -47
- package/generator/template/app/Site.elm +19 -6
- package/generator/template/app/View.elm +1 -8
- package/generator/template/elm-tooling.json +0 -3
- package/generator/template/elm.json +32 -24
- package/generator/template/package.json +10 -4
- package/package.json +29 -27
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +325 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +128 -43
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +673 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +28 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +537 -0
- package/src/FatalError.elm +89 -0
- package/src/Form/Field.elm +21 -9
- package/src/Form/FieldView.elm +94 -14
- package/src/Form.elm +275 -400
- package/src/Head.elm +237 -7
- package/src/HtmlPrinter.elm +7 -3
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/FormState.elm +6 -5
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Form.elm +21 -1
- package/src/Pages/{Msg.elm → Internal/Msg.elm} +26 -16
- package/src/Pages/Internal/Platform/Cli.elm +598 -763
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +373 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Internal/Platform.elm +216 -102
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +29 -4
- package/src/Pages/PageUrl.elm +23 -9
- package/src/Pages/ProgramConfig.elm +14 -10
- package/src/Pages/Script.elm +109 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -98
- package/src/PagesMsg.elm +92 -0
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +21 -172
- package/src/RequestsAndPending.elm +8 -19
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +560 -0
- package/src/Scaffold/Route.elm +1388 -0
- package/src/Server/Request.elm +43 -37
- package/src/Server/Session.elm +62 -42
- package/src/Server/SetCookie.elm +12 -4
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/DataSource/Env.elm +0 -38
- package/src/DataSource/Http.elm +0 -446
- package/src/DataSource/Internal/Request.elm +0 -20
- package/src/DataSource/Port.elm +0 -90
- package/src/DataSource.elm +0 -538
- package/src/Pages/Generate.elm +0 -800
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
module
|
|
1
|
+
module BackendTask.File exposing
|
|
2
2
|
( bodyWithFrontmatter, bodyWithoutFrontmatter, onlyFrontmatter
|
|
3
3
|
, jsonFile, rawFile
|
|
4
|
+
, FileReadError(..)
|
|
4
5
|
)
|
|
5
6
|
|
|
6
|
-
{-| This module lets you read files from the local filesystem as a [`
|
|
7
|
+
{-| This module lets you read files from the local filesystem as a [`BackendTask`](BackendTask#BackendTask).
|
|
7
8
|
File paths are relative to the root of your `elm-pages` project (next to the `elm.json` file and `src/` directory).
|
|
8
9
|
|
|
9
10
|
|
|
@@ -40,12 +41,19 @@ plain old JSON in Elm.
|
|
|
40
41
|
|
|
41
42
|
@docs jsonFile, rawFile
|
|
42
43
|
|
|
44
|
+
|
|
45
|
+
## FatalErrors
|
|
46
|
+
|
|
47
|
+
@docs FileReadError
|
|
48
|
+
|
|
43
49
|
-}
|
|
44
50
|
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import
|
|
51
|
+
import BackendTask exposing (BackendTask)
|
|
52
|
+
import BackendTask.Http
|
|
53
|
+
import BackendTask.Internal.Request
|
|
54
|
+
import FatalError exposing (FatalError)
|
|
48
55
|
import Json.Decode as Decode exposing (Decoder)
|
|
56
|
+
import TerminalText
|
|
49
57
|
|
|
50
58
|
|
|
51
59
|
frontmatter : Decoder frontmatter -> Decoder frontmatter
|
|
@@ -55,11 +63,11 @@ frontmatter frontmatterDecoder =
|
|
|
55
63
|
|
|
56
64
|
{-|
|
|
57
65
|
|
|
58
|
-
import
|
|
59
|
-
import
|
|
66
|
+
import BackendTask exposing (BackendTask)
|
|
67
|
+
import BackendTask.File as File
|
|
60
68
|
import Decode as Decode exposing (Decoder)
|
|
61
69
|
|
|
62
|
-
blogPost :
|
|
70
|
+
blogPost : BackendTask BlogPostMetadata
|
|
63
71
|
blogPost =
|
|
64
72
|
File.bodyWithFrontmatter blogPostDecoder
|
|
65
73
|
"blog/hello-world.md"
|
|
@@ -81,7 +89,7 @@ frontmatter frontmatterDecoder =
|
|
|
81
89
|
Decode.map (String.split " ")
|
|
82
90
|
Decode.string
|
|
83
91
|
|
|
84
|
-
This will give us a
|
|
92
|
+
This will give us a BackendTask that results in the following value:
|
|
85
93
|
|
|
86
94
|
value =
|
|
87
95
|
{ body = "Hey there! This is my first post :)"
|
|
@@ -91,13 +99,13 @@ This will give us a DataSource that results in the following value:
|
|
|
91
99
|
|
|
92
100
|
It's common to parse the body with a markdown parser or other format.
|
|
93
101
|
|
|
94
|
-
import
|
|
95
|
-
import
|
|
102
|
+
import BackendTask exposing (BackendTask)
|
|
103
|
+
import BackendTask.File as File
|
|
96
104
|
import Decode as Decode exposing (Decoder)
|
|
97
105
|
import Html exposing (Html)
|
|
98
106
|
|
|
99
107
|
example :
|
|
100
|
-
|
|
108
|
+
BackendTask
|
|
101
109
|
{ title : String
|
|
102
110
|
, body : List (Html msg)
|
|
103
111
|
}
|
|
@@ -133,7 +141,15 @@ It's common to parse the body with a markdown parser or other format.
|
|
|
133
141
|
)
|
|
134
142
|
|
|
135
143
|
-}
|
|
136
|
-
bodyWithFrontmatter :
|
|
144
|
+
bodyWithFrontmatter :
|
|
145
|
+
(String -> Decoder frontmatter)
|
|
146
|
+
-> String
|
|
147
|
+
->
|
|
148
|
+
BackendTask
|
|
149
|
+
{ fatal : FatalError
|
|
150
|
+
, recoverable : FileReadError Decode.Error
|
|
151
|
+
}
|
|
152
|
+
frontmatter
|
|
137
153
|
bodyWithFrontmatter frontmatterDecoder filePath =
|
|
138
154
|
read filePath
|
|
139
155
|
(body
|
|
@@ -144,16 +160,23 @@ bodyWithFrontmatter frontmatterDecoder filePath =
|
|
|
144
160
|
)
|
|
145
161
|
|
|
146
162
|
|
|
163
|
+
{-| -}
|
|
164
|
+
type FileReadError decoding
|
|
165
|
+
= FileDoesntExist
|
|
166
|
+
| FileReadError String
|
|
167
|
+
| DecodingError decoding
|
|
168
|
+
|
|
169
|
+
|
|
147
170
|
{-| Same as `bodyWithFrontmatter` except it doesn't include the body.
|
|
148
171
|
|
|
149
172
|
This is often useful when you're aggregating data, for example getting a listing of blog posts and need to extract
|
|
150
173
|
just the metadata.
|
|
151
174
|
|
|
152
|
-
import
|
|
153
|
-
import
|
|
175
|
+
import BackendTask exposing (BackendTask)
|
|
176
|
+
import BackendTask.File as File
|
|
154
177
|
import Decode as Decode exposing (Decoder)
|
|
155
178
|
|
|
156
|
-
blogPost :
|
|
179
|
+
blogPost : BackendTask BlogPostMetadata
|
|
157
180
|
blogPost =
|
|
158
181
|
File.onlyFrontmatter
|
|
159
182
|
blogPostDecoder
|
|
@@ -171,34 +194,42 @@ just the metadata.
|
|
|
171
194
|
(Decode.field "tags" (Decode.list Decode.string))
|
|
172
195
|
|
|
173
196
|
If you wanted to use this to get this metadata for all blog posts in a folder, you could use
|
|
174
|
-
the [`
|
|
197
|
+
the [`BackendTask`](BackendTask) API along with [`BackendTask.Glob`](BackendTask-Glob).
|
|
175
198
|
|
|
176
|
-
import
|
|
177
|
-
import
|
|
199
|
+
import BackendTask exposing (BackendTask)
|
|
200
|
+
import BackendTask.File as File
|
|
178
201
|
import Decode as Decode exposing (Decoder)
|
|
179
202
|
|
|
180
|
-
blogPostFiles :
|
|
203
|
+
blogPostFiles : BackendTask (List String)
|
|
181
204
|
blogPostFiles =
|
|
182
205
|
Glob.succeed identity
|
|
183
206
|
|> Glob.captureFilePath
|
|
184
207
|
|> Glob.match (Glob.literal "content/blog/")
|
|
185
208
|
|> Glob.match Glob.wildcard
|
|
186
209
|
|> Glob.match (Glob.literal ".md")
|
|
187
|
-
|> Glob.
|
|
210
|
+
|> Glob.toBackendTask
|
|
188
211
|
|
|
189
|
-
allMetadata :
|
|
212
|
+
allMetadata : BackendTask (List BlogPostMetadata)
|
|
190
213
|
allMetadata =
|
|
191
214
|
blogPostFiles
|
|
192
|
-
|>
|
|
215
|
+
|> BackendTask.map
|
|
193
216
|
(List.map
|
|
194
217
|
(File.onlyFrontmatter
|
|
195
218
|
blogPostDecoder
|
|
196
219
|
)
|
|
197
220
|
)
|
|
198
|
-
|>
|
|
221
|
+
|> BackendTask.resolve
|
|
199
222
|
|
|
200
223
|
-}
|
|
201
|
-
onlyFrontmatter :
|
|
224
|
+
onlyFrontmatter :
|
|
225
|
+
Decoder frontmatter
|
|
226
|
+
-> String
|
|
227
|
+
->
|
|
228
|
+
BackendTask
|
|
229
|
+
{ fatal : FatalError
|
|
230
|
+
, recoverable : FileReadError Decode.Error
|
|
231
|
+
}
|
|
232
|
+
frontmatter
|
|
202
233
|
onlyFrontmatter frontmatterDecoder filePath =
|
|
203
234
|
read filePath
|
|
204
235
|
(frontmatter frontmatterDecoder)
|
|
@@ -216,16 +247,23 @@ tags: elm
|
|
|
216
247
|
Hey there! This is my first post :)
|
|
217
248
|
```
|
|
218
249
|
|
|
219
|
-
import
|
|
250
|
+
import BackendTask exposing (BackendTask)
|
|
220
251
|
|
|
221
|
-
data :
|
|
252
|
+
data : BackendTask String
|
|
222
253
|
data =
|
|
223
254
|
bodyWithoutFrontmatter "blog/hello-world.md"
|
|
224
255
|
|
|
225
256
|
Then data will yield the value `"Hey there! This is my first post :)"`.
|
|
226
257
|
|
|
227
258
|
-}
|
|
228
|
-
bodyWithoutFrontmatter :
|
|
259
|
+
bodyWithoutFrontmatter :
|
|
260
|
+
String
|
|
261
|
+
->
|
|
262
|
+
BackendTask
|
|
263
|
+
{ fatal : FatalError
|
|
264
|
+
, recoverable : FileReadError decoderError
|
|
265
|
+
}
|
|
266
|
+
String
|
|
229
267
|
bodyWithoutFrontmatter filePath =
|
|
230
268
|
read filePath
|
|
231
269
|
body
|
|
@@ -241,15 +279,15 @@ use `jsonFile` to get the benefits of the `Decode` here.
|
|
|
241
279
|
|
|
242
280
|
You could read a file called `hello.txt` in your root project directory like this:
|
|
243
281
|
|
|
244
|
-
import
|
|
245
|
-
import
|
|
282
|
+
import BackendTask exposing (BackendTask)
|
|
283
|
+
import BackendTask.File as File
|
|
246
284
|
|
|
247
|
-
elmJsonFile :
|
|
285
|
+
elmJsonFile : BackendTask String
|
|
248
286
|
elmJsonFile =
|
|
249
287
|
File.rawFile "hello.txt"
|
|
250
288
|
|
|
251
289
|
-}
|
|
252
|
-
rawFile : String ->
|
|
290
|
+
rawFile : String -> BackendTask { fatal : FatalError, recoverable : FileReadError decoderError } String
|
|
253
291
|
rawFile filePath =
|
|
254
292
|
read filePath (Decode.field "rawFile" Decode.string)
|
|
255
293
|
|
|
@@ -258,10 +296,10 @@ rawFile filePath =
|
|
|
258
296
|
|
|
259
297
|
The Decode will strip off any unused JSON data.
|
|
260
298
|
|
|
261
|
-
import
|
|
262
|
-
import
|
|
299
|
+
import BackendTask exposing (BackendTask)
|
|
300
|
+
import BackendTask.File as File
|
|
263
301
|
|
|
264
|
-
sourceDirectories :
|
|
302
|
+
sourceDirectories : BackendTask (List String)
|
|
265
303
|
sourceDirectories =
|
|
266
304
|
File.jsonFile
|
|
267
305
|
(Decode.field
|
|
@@ -271,15 +309,33 @@ The Decode will strip off any unused JSON data.
|
|
|
271
309
|
"elm.json"
|
|
272
310
|
|
|
273
311
|
-}
|
|
274
|
-
jsonFile :
|
|
312
|
+
jsonFile :
|
|
313
|
+
Decoder a
|
|
314
|
+
-> String
|
|
315
|
+
->
|
|
316
|
+
BackendTask
|
|
317
|
+
{ fatal : FatalError
|
|
318
|
+
, recoverable : FileReadError Decode.Error
|
|
319
|
+
}
|
|
320
|
+
a
|
|
275
321
|
jsonFile jsonFileDecoder filePath =
|
|
276
322
|
rawFile filePath
|
|
277
|
-
|>
|
|
323
|
+
|> BackendTask.andThen
|
|
278
324
|
(\jsonString ->
|
|
279
325
|
jsonString
|
|
280
326
|
|> Decode.decodeString jsonFileDecoder
|
|
281
|
-
|> Result.mapError
|
|
282
|
-
|
|
327
|
+
|> Result.mapError
|
|
328
|
+
(\jsonDecodeError ->
|
|
329
|
+
FatalError.recoverable
|
|
330
|
+
{ title = "JSON Decoding Error"
|
|
331
|
+
, body =
|
|
332
|
+
[ TerminalText.text (Decode.errorToString jsonDecodeError)
|
|
333
|
+
]
|
|
334
|
+
|> TerminalText.toString
|
|
335
|
+
}
|
|
336
|
+
(DecodingError jsonDecodeError)
|
|
337
|
+
)
|
|
338
|
+
|> BackendTask.fromResult
|
|
283
339
|
)
|
|
284
340
|
|
|
285
341
|
|
|
@@ -290,10 +346,39 @@ body =
|
|
|
290
346
|
Decode.field "withoutFrontmatter" Decode.string
|
|
291
347
|
|
|
292
348
|
|
|
293
|
-
read : String -> Decoder a ->
|
|
349
|
+
read : String -> Decoder a -> BackendTask { fatal : FatalError, recoverable : FileReadError error } a
|
|
294
350
|
read filePath decoder =
|
|
295
|
-
|
|
351
|
+
BackendTask.Internal.Request.request
|
|
296
352
|
{ name = "read-file"
|
|
297
|
-
, body =
|
|
298
|
-
, expect =
|
|
353
|
+
, body = BackendTask.Http.stringBody "" filePath
|
|
354
|
+
, expect =
|
|
355
|
+
Decode.oneOf
|
|
356
|
+
[ Decode.field "errorCode"
|
|
357
|
+
(Decode.map Err (errorDecoder filePath))
|
|
358
|
+
, decoder |> Decode.map Ok
|
|
359
|
+
]
|
|
360
|
+
|> BackendTask.Http.expectJson
|
|
299
361
|
}
|
|
362
|
+
|> BackendTask.andThen BackendTask.fromResult
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
errorDecoder :
|
|
366
|
+
String
|
|
367
|
+
->
|
|
368
|
+
Decoder
|
|
369
|
+
{ fatal : FatalError
|
|
370
|
+
, recoverable : FileReadError decoding
|
|
371
|
+
}
|
|
372
|
+
errorDecoder filePath =
|
|
373
|
+
Decode.succeed
|
|
374
|
+
(FatalError.recoverable
|
|
375
|
+
{ title = "File Doesn't Exist"
|
|
376
|
+
, body =
|
|
377
|
+
[ TerminalText.text "Couldn't find file at path `"
|
|
378
|
+
, TerminalText.yellow filePath
|
|
379
|
+
, TerminalText.text "`"
|
|
380
|
+
]
|
|
381
|
+
|> TerminalText.toString
|
|
382
|
+
}
|
|
383
|
+
FileDoesntExist
|
|
384
|
+
)
|