elm-pages 3.0.12 → 3.0.14

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.
Files changed (75) hide show
  1. package/README.md +2 -26
  2. package/codegen/elm-pages-codegen.cjs +10741 -10302
  3. package/generator/src/build.js +15 -5
  4. package/generator/src/cli.js +3 -5
  5. package/generator/src/compatibility-key.js +2 -2
  6. package/generator/src/dev-server.js +3 -0
  7. package/generator/src/render.js +681 -50
  8. package/generator/src/request-cache.js +13 -6
  9. package/generator/src/spinnies/index.js +200 -0
  10. package/generator/src/spinnies/utils.js +123 -0
  11. package/generator/src/validate-stream.js +25 -0
  12. package/generator/template/elm.json +4 -4
  13. package/generator/template/package.json +6 -6
  14. package/generator/template/script/elm.json +7 -8
  15. package/package.json +4 -3
  16. package/src/BackendTask/Custom.elm +38 -0
  17. package/src/BackendTask/Do.elm +233 -0
  18. package/src/BackendTask/File.elm +24 -9
  19. package/src/BackendTask/Glob.elm +208 -25
  20. package/src/BackendTask/Http.elm +32 -21
  21. package/src/BackendTask/Internal/Glob.elm +16 -4
  22. package/src/BackendTask/Stream.elm +1179 -0
  23. package/src/BackendTask.elm +214 -7
  24. package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
  25. package/src/Pages/Internal/Platform.elm +11 -2
  26. package/src/Pages/Script/Spinner.elm +505 -0
  27. package/src/Pages/Script.elm +199 -2
  28. package/src/Pages/StaticHttp/Request.elm +7 -0
  29. package/src/RequestsAndPending.elm +1 -1
  30. package/src/Scaffold/Form.elm +2 -3
  31. package/src/TerminalText.elm +8 -0
  32. package/src/Vendored/Result/Extra.elm +75 -0
  33. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  34. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  35. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmi +0 -0
  36. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  37. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
  38. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
  39. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
  40. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
  41. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  42. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  43. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
  44. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  45. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +0 -1
  46. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
  47. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -28657
  48. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
  49. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
  50. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/package.json +0 -1
  51. package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
  52. package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
  53. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  54. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  55. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  56. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  57. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmi +0 -0
  58. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
  59. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
  60. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
  61. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
  62. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
  63. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  64. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  65. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
  66. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  67. package/generator/review/elm-stuff/tests-0.19.1/elm.json +0 -1
  68. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
  69. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -30511
  70. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
  71. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
  72. package/generator/review/elm-stuff/tests-0.19.1/js/package.json +0 -1
  73. package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
  74. package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
  75. package/src/Result/Extra.elm +0 -26
@@ -0,0 +1,233 @@
1
+ module BackendTask.Do exposing
2
+ ( do
3
+ , allowFatal
4
+ , noop
5
+ , exec, command
6
+ , glob, log, env
7
+ , each, failIf
8
+ )
9
+
10
+ {-|
11
+
12
+
13
+ ## **This is an optional and experimental module.** It is for doing a continuation style with your [`BackendTask`s](BackendTask).
14
+
15
+ Note that in order for this style to be usable, you'll need to use a special formatting script that allows you to use
16
+ continuation style syntax without indenting each level in the continuation.
17
+
18
+
19
+ ## Custom Formatting Script
20
+
21
+ It is a bit advanced and cumbersome, so beware before committing to this style. That said, here is a script you can use to
22
+ apply continuation-style formatting to your Elm code:
23
+
24
+ <https://gist.github.com/xarvh/1b65cb00e7240f1ccfa0bdbf30f97c62>
25
+
26
+ You can see more discussion of continuation style in Elm in this Discourse post: <https://discourse.elm-lang.org/t/experimental-json-decoding-api/2121>.
27
+
28
+ @docs do
29
+ @docs allowFatal
30
+
31
+
32
+ ## Defining Your Own Continuation Utilities
33
+
34
+ `do` is also helpful for building your own continuation-style utilities. For example, here is how [`glob`](#glob) is defined:
35
+
36
+ glob : String -> (List String -> BackendTask FatalError a) -> BackendTask FatalError a
37
+ glob pattern =
38
+ do <| Glob.fromString pattern
39
+
40
+ To define helpers that have no resulting value, it is still useful to have an argument of `()` to allow the code formatter to
41
+ recognize it as a continuation chain.
42
+
43
+ sh :
44
+ String
45
+ -> List String
46
+ -> (() -> BackendTask FatalError b)
47
+ -> BackendTask FatalError b
48
+ sh command args =
49
+ do <| Shell.sh command args
50
+
51
+ @docs noop
52
+
53
+
54
+ ## Shell Commands
55
+
56
+ @docs exec, command
57
+
58
+
59
+ ## Common Utilities
60
+
61
+ @docs glob, log, env
62
+
63
+ @docs each, failIf
64
+
65
+ -}
66
+
67
+ import BackendTask exposing (BackendTask)
68
+ import BackendTask.Env as Env
69
+ import BackendTask.Glob as Glob
70
+ import FatalError exposing (FatalError)
71
+ import Pages.Script as Script
72
+
73
+
74
+ {-| A do-style helper for [`Script.log`](Pages-Script#log).
75
+
76
+ example : BackendTask FatalError ()
77
+ example =
78
+ log "Starting script..." <|
79
+ \() ->
80
+ -- ...
81
+ log "Done!" <|
82
+ \() ->
83
+ noop
84
+
85
+ -}
86
+ log : String -> (() -> BackendTask error b) -> BackendTask error b
87
+ log string then_ =
88
+ do (Script.log string) then_
89
+
90
+
91
+ {-| Use any `BackendTask` into a continuation-style task.
92
+
93
+ example : BackendTask FatalError ()
94
+ example =
95
+ do
96
+ (Script.question "What is your name? ")
97
+ <|
98
+ \name ->
99
+ \() ->
100
+ Script.log ("Hello " ++ name ++ "!")
101
+
102
+ -}
103
+ do : BackendTask error a -> (a -> BackendTask error b) -> BackendTask error b
104
+ do fn requestInfo =
105
+ BackendTask.andThen requestInfo fn
106
+
107
+
108
+ {-| A `BackendTask` that does nothing. Defined as `BackendTask.succeed ()`.
109
+
110
+ It's a useful shorthand for when you want to end a continuation chain.
111
+
112
+ example : BackendTask FatalError ()
113
+ example =
114
+ exec "ls" [ "-l" ] <|
115
+ \() ->
116
+ log "Hello, world!" <|
117
+ \() ->
118
+ noop
119
+
120
+ -}
121
+ noop : BackendTask error ()
122
+ noop =
123
+ BackendTask.succeed ()
124
+
125
+
126
+ {-| Same as [`do`](#do), but with a shorthand to call `BackendTask.allowFatal` on it.
127
+
128
+ import BackendTask exposing (BackendTask)
129
+ import FatalError exposing (FatalError)
130
+ import BackendTask.File as BackendTask.File
131
+ import BackendTask.Do exposing (allowFatal, do)
132
+
133
+ example : BackendTask FatalError ()
134
+ example =
135
+ do (BackendTask.File.rawFile "post-1.md" |> BackendTask.allowFatal) <|
136
+ \post1 ->
137
+ allowFatal (BackendTask.File.rawFile "post-2.md") <|
138
+ \post2 ->
139
+ Script.log (post1 ++ "\n\n" ++ post2)
140
+
141
+ -}
142
+ allowFatal : BackendTask { error | fatal : FatalError } data -> (data -> BackendTask FatalError b) -> BackendTask FatalError b
143
+ allowFatal =
144
+ do << BackendTask.allowFatal
145
+
146
+
147
+ {-| A continuation-style helper for [`Glob.fromString`](BackendTask-Glob#fromString).
148
+
149
+ In a shell script, you can think of this as a stand-in for globbing files directly within a command. The [`BackendTask.Stream.command`](BackendTask-Stream#command)
150
+ which lets you run shell commands sanitizes and escapes all arguments passed, and does not do glob expansion, so this is helpful for translating
151
+ a shell script to Elm.
152
+
153
+ This example passes a list of matching file paths along to an `rm -f` command.
154
+
155
+ example : BackendTask FatalError ()
156
+ example =
157
+ glob "src/**/*.elm" <|
158
+ \elmFiles ->
159
+ log ("Going to delete " ++ String.fromInt (List.length elmFiles) ++ " Elm files") <|
160
+ \() ->
161
+ exec "rm" ("-f" :: elmFiles) <|
162
+ \() ->
163
+ noop
164
+
165
+ -}
166
+ glob : String -> (List String -> BackendTask FatalError a) -> BackendTask FatalError a
167
+ glob pattern =
168
+ do <| Glob.fromString pattern
169
+
170
+
171
+ {-|
172
+
173
+ checkCompilationInDir : String -> BackendTask FatalError ()
174
+ checkCompilationInDir dir =
175
+ glob (dir ++ "/**/*.elm") <|
176
+ \elmFiles ->
177
+ each elmFiles
178
+ (\elmFile ->
179
+ Shell.sh "elm" [ "make", elmFile, "--output", "/dev/null" ]
180
+ |> BackendTask.quiet
181
+ )
182
+ <|
183
+ \_ ->
184
+ noop
185
+
186
+ -}
187
+ each : List a -> (a -> BackendTask error b) -> (List b -> BackendTask error c) -> BackendTask error c
188
+ each list fn then_ =
189
+ do
190
+ (list
191
+ |> List.map fn
192
+ |> BackendTask.sequence
193
+ )
194
+ <|
195
+ then_
196
+
197
+
198
+ {-| A do-style helper for [`BackendTask.failIf`](BackendTask#failIf).
199
+ -}
200
+ failIf : Bool -> FatalError -> (() -> BackendTask FatalError b) -> BackendTask FatalError b
201
+ failIf condition error =
202
+ do <| BackendTask.failIf condition error
203
+
204
+
205
+ {-| A do-style helper for [`Script.exec`](Pages-Script#exec).
206
+ -}
207
+ exec : String -> List String -> (() -> BackendTask FatalError b) -> BackendTask FatalError b
208
+ exec command_ args_ =
209
+ do <| Script.exec command_ args_
210
+
211
+
212
+ {-| A do-style helper for [`Script.command`](Pages-Script#command).
213
+ -}
214
+ command : String -> List String -> (String -> BackendTask FatalError b) -> BackendTask FatalError b
215
+ command command_ args_ function =
216
+ Script.command command_ args_
217
+ |> BackendTask.andThen function
218
+
219
+
220
+ {-| A do-style helper for [`Env.expect`](BackendTask-Env#expect).
221
+
222
+ example : BackendTask FatalError ()
223
+ example =
224
+ env "API_KEY" <|
225
+ \apiKey ->
226
+ allowFatal (apiRequest apiKey) <|
227
+ \() ->
228
+ noop
229
+
230
+ -}
231
+ env : String -> (String -> BackendTask FatalError b) -> BackendTask FatalError b
232
+ env name then_ =
233
+ do (Env.expect name |> BackendTask.allowFatal) <| then_
@@ -66,12 +66,14 @@ frontmatter frontmatterDecoder =
66
66
 
67
67
  import BackendTask exposing (BackendTask)
68
68
  import BackendTask.File as File
69
- import Decode exposing (Decoder)
69
+ import FatalError exposing (FatalError)
70
+ import Json.Decode as Decode exposing (Decoder)
70
71
 
71
- blogPost : BackendTask BlogPostMetadata
72
+ blogPost : BackendTask FatalError BlogPostMetadata
72
73
  blogPost =
73
74
  File.bodyWithFrontmatter blogPostDecoder
74
75
  "blog/hello-world.md"
76
+ |> BackendTask.allowFatal
75
77
 
76
78
  type alias BlogPostMetadata =
77
79
  { body : String
@@ -102,11 +104,13 @@ It's common to parse the body with a markdown parser or other format.
102
104
 
103
105
  import BackendTask exposing (BackendTask)
104
106
  import BackendTask.File as File
105
- import Decode exposing (Decoder)
107
+ import FatalError exposing (FatalError)
106
108
  import Html exposing (Html)
109
+ import Json.Decode as Decode
107
110
 
108
111
  example :
109
112
  BackendTask
113
+ FatalError
110
114
  { title : String
111
115
  , body : List (Html msg)
112
116
  }
@@ -126,6 +130,7 @@ It's common to parse the body with a markdown parser or other format.
126
130
  )
127
131
  )
128
132
  "foo.md"
133
+ |> BackendTask.allowFatal
129
134
 
130
135
  markdownToView :
131
136
  String
@@ -191,13 +196,15 @@ just the metadata.
191
196
 
192
197
  import BackendTask exposing (BackendTask)
193
198
  import BackendTask.File as File
194
- import Decode exposing (Decoder)
199
+ import FatalError exposing (FatalError)
200
+ import Json.Decode as Decode exposing (Decoder)
195
201
 
196
- blogPost : BackendTask BlogPostMetadata
202
+ blogPost : BackendTask FatalError BlogPostMetadata
197
203
  blogPost =
198
204
  File.onlyFrontmatter
199
205
  blogPostDecoder
200
206
  "blog/hello-world.md"
207
+ |> BackendTask.allowFatal
201
208
 
202
209
  type alias BlogPostMetadata =
203
210
  { title : String
@@ -281,10 +288,13 @@ Hey there! This is my first post :)
281
288
  ```
282
289
 
283
290
  import BackendTask exposing (BackendTask)
291
+ import BackendTask.File as File
292
+ import FatalError exposing (FatalError)
284
293
 
285
- data : BackendTask String
294
+ data : BackendTask FatalError String
286
295
  data =
287
- bodyWithoutFrontmatter "blog/hello-world.md"
296
+ File.bodyWithoutFrontmatter "blog/hello-world.md"
297
+ |> BackendTask.allowFatal
288
298
 
289
299
  Then data will yield the value `"Hey there! This is my first post :)"`.
290
300
 
@@ -314,10 +324,12 @@ You could read a file called `hello.txt` in your root project directory like thi
314
324
 
315
325
  import BackendTask exposing (BackendTask)
316
326
  import BackendTask.File as File
327
+ import FatalError exposing (FatalError)
317
328
 
318
- elmJsonFile : BackendTask String
329
+ elmJsonFile : BackendTask FatalError String
319
330
  elmJsonFile =
320
331
  File.rawFile "hello.txt"
332
+ |> BackendTask.allowFatal
321
333
 
322
334
  -}
323
335
  rawFile : String -> BackendTask { fatal : FatalError, recoverable : FileReadError decoderError } String
@@ -331,8 +343,10 @@ The Decode will strip off any unused JSON data.
331
343
 
332
344
  import BackendTask exposing (BackendTask)
333
345
  import BackendTask.File as File
346
+ import FatalError exposing (FatalError)
347
+ import Json.Decode as Decode
334
348
 
335
- sourceDirectories : BackendTask (List String)
349
+ sourceDirectories : BackendTask FatalError (List String)
336
350
  sourceDirectories =
337
351
  File.jsonFile
338
352
  (Decode.field
@@ -340,6 +354,7 @@ The Decode will strip off any unused JSON data.
340
354
  (Decode.list Decode.string)
341
355
  )
342
356
  "elm.json"
357
+ |> BackendTask.allowFatal
343
358
 
344
359
  -}
345
360
  jsonFile :