elm-pages 3.0.12 → 3.0.13

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 (72) hide show
  1. package/README.md +2 -26
  2. package/codegen/elm-pages-codegen.cjs +13695 -11461
  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/package.json +4 -2
  13. package/src/BackendTask/Custom.elm +38 -0
  14. package/src/BackendTask/Do.elm +233 -0
  15. package/src/BackendTask/File.elm +24 -9
  16. package/src/BackendTask/Glob.elm +208 -25
  17. package/src/BackendTask/Http.elm +32 -21
  18. package/src/BackendTask/Internal/Glob.elm +16 -4
  19. package/src/BackendTask/Stream.elm +1179 -0
  20. package/src/BackendTask.elm +214 -7
  21. package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
  22. package/src/Pages/Internal/Platform.elm +11 -2
  23. package/src/Pages/Script/Spinner.elm +505 -0
  24. package/src/Pages/Script.elm +199 -2
  25. package/src/Pages/StaticHttp/Request.elm +7 -0
  26. package/src/RequestsAndPending.elm +1 -1
  27. package/src/Scaffold/Form.elm +2 -3
  28. package/src/TerminalText.elm +8 -0
  29. package/src/Vendored/Result/Extra.elm +75 -0
  30. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  31. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  32. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmi +0 -0
  33. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  34. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
  35. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
  36. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
  37. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
  38. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  39. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  40. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
  41. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  42. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +0 -1
  43. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
  44. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -28657
  45. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
  46. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
  47. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/package.json +0 -1
  48. package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
  49. package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
  50. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  51. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  52. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  53. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  54. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmi +0 -0
  55. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
  56. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
  57. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
  58. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
  59. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
  60. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  61. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  62. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
  63. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  64. package/generator/review/elm-stuff/tests-0.19.1/elm.json +0 -1
  65. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +0 -7900
  66. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +0 -30511
  67. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +0 -110
  68. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +0 -187
  69. package/generator/review/elm-stuff/tests-0.19.1/js/package.json +0 -1
  70. package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +0 -26
  71. package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +0 -62
  72. package/src/Result/Extra.elm +0 -26
@@ -2,7 +2,8 @@ module Pages.Script exposing
2
2
  ( Script
3
3
  , withCliOptions, withoutCliOptions
4
4
  , writeFile
5
- , log
5
+ , command, exec
6
+ , log, sleep, doThen, which, expectWhich, question
6
7
  , Error(..)
7
8
  )
8
9
 
@@ -23,9 +24,14 @@ Read more about using the `elm-pages` CLI to run (or bundle) scripts, plus a bri
23
24
  @docs writeFile
24
25
 
25
26
 
27
+ ## Shell Commands
28
+
29
+ @docs command, exec
30
+
31
+
26
32
  ## Utilities
27
33
 
28
- @docs log
34
+ @docs log, sleep, doThen, which, expectWhich, question
29
35
 
30
36
 
31
37
  ## Errors
@@ -37,6 +43,7 @@ Read more about using the `elm-pages` CLI to run (or bundle) scripts, plus a bri
37
43
  import BackendTask exposing (BackendTask)
38
44
  import BackendTask.Http
39
45
  import BackendTask.Internal.Request
46
+ import BackendTask.Stream as Stream exposing (defaultCommandOptions)
40
47
  import Cli.OptionsParser as OptionsParser
41
48
  import Cli.Program as Program
42
49
  import FatalError exposing (FatalError)
@@ -61,6 +68,8 @@ type Error
61
68
 
62
69
  {-| Write a file to the file system.
63
70
 
71
+ File paths are relative to the root of your `elm-pages` project (next to the `elm.json` file and `src/` directory), or you can pass in absolute paths beginning with a `/`.
72
+
64
73
  module MyScript exposing (run)
65
74
 
66
75
  import BackendTask
@@ -164,3 +173,191 @@ withCliOptions config execute =
164
173
  config
165
174
  |> Program.mapConfig execute
166
175
  )
176
+
177
+
178
+ {-| Sleep for a number of milliseconds.
179
+
180
+ module MyScript exposing (run)
181
+
182
+ import BackendTask
183
+ import Pages.Script as Script
184
+
185
+ run =
186
+ Script.withoutCliOptions
187
+ (Script.log "Hello..."
188
+ |> Script.doThen
189
+ (Script.sleep 1000)
190
+ |> Script.doThen
191
+ (Script.log "World!")
192
+ )
193
+
194
+ -}
195
+ sleep : Int -> BackendTask error ()
196
+ sleep int =
197
+ BackendTask.Internal.Request.request
198
+ { name = "sleep"
199
+ , body =
200
+ BackendTask.Http.jsonBody
201
+ (Encode.object
202
+ [ ( "milliseconds", Encode.int int )
203
+ ]
204
+ )
205
+ , expect =
206
+ BackendTask.Http.expectJson (Decode.null ())
207
+ }
208
+
209
+
210
+ {-| Run a command with no output, then run another command.
211
+
212
+ module MyScript exposing (run)
213
+
214
+ import BackendTask
215
+ import Pages.Script as Script
216
+
217
+ run =
218
+ Script.withoutCliOptions
219
+ (Script.log "Hello!"
220
+ |> Script.doThen
221
+ (Script.log "World!")
222
+ )
223
+
224
+ -}
225
+ doThen : BackendTask error value -> BackendTask error () -> BackendTask error value
226
+ doThen task1 task2 =
227
+ task2
228
+ |> BackendTask.andThen (\() -> task1)
229
+
230
+
231
+ {-| Same as [`expectWhich`](#expectWhich), but returns `Nothing` if the command is not found instead of failing with a [`FatalError`](FatalError).
232
+ -}
233
+ which : String -> BackendTask error (Maybe String)
234
+ which command_ =
235
+ BackendTask.Internal.Request.request
236
+ { body = BackendTask.Http.jsonBody (Encode.string command_)
237
+ , expect = BackendTask.Http.expectJson (Decode.nullable Decode.string)
238
+ , name = "which"
239
+ }
240
+
241
+
242
+ {-| Check if a command is available on the system. If it is, return the full path to the command, otherwise fail with a [`FatalError`](FatalError).
243
+
244
+ module MyScript exposing (run)
245
+
246
+ import BackendTask
247
+ import Pages.Script as Script
248
+
249
+ run : Script
250
+ run =
251
+ Script.withoutCliOptions
252
+ (Script.expectWhich "elm-review"
253
+ |> BackendTask.andThen
254
+ (\path ->
255
+ Script.log ("The path to `elm-review` is: " ++ path)
256
+ )
257
+ )
258
+
259
+ If you run it with a command that is not available, you will see an error like this:
260
+
261
+ Script.expectWhich "hype-script"
262
+
263
+ ```shell
264
+ -- COMMAND NOT FOUND ---------------
265
+ I expected to find `hype-script`, but it was not on your PATH. Make sure it is installed and included in your PATH.
266
+ ```
267
+
268
+ -}
269
+ expectWhich : String -> BackendTask FatalError String
270
+ expectWhich command_ =
271
+ which command_
272
+ |> BackendTask.andThen
273
+ (\maybePath ->
274
+ case maybePath of
275
+ Just path ->
276
+ BackendTask.succeed path
277
+
278
+ Nothing ->
279
+ BackendTask.fail
280
+ (FatalError.build
281
+ { title = "Command not found"
282
+ , body = "I expected to find `" ++ command_ ++ "`, but it was not on your PATH. Make sure it is installed and included in your PATH."
283
+ }
284
+ )
285
+ )
286
+
287
+
288
+ {-|
289
+
290
+ module QuestionDemo exposing (run)
291
+
292
+ import BackendTask
293
+
294
+ run : Script
295
+ run =
296
+ Script.withoutCliOptions
297
+ (Script.question "What is your name? "
298
+ |> BackendTask.andThen
299
+ (\name ->
300
+ Script.log ("Hello, " ++ name ++ "!")
301
+ )
302
+ )
303
+
304
+ -}
305
+ question : String -> BackendTask error String
306
+ question prompt =
307
+ BackendTask.Internal.Request.request
308
+ { body =
309
+ BackendTask.Http.jsonBody
310
+ (Encode.object [ ( "prompt", Encode.string prompt ) ])
311
+ , expect = BackendTask.Http.expectJson Decode.string
312
+ , name = "question"
313
+ }
314
+
315
+
316
+ {-| Like [`command`](#command), but prints stderr and stdout to the console as the command runs instead of capturing them.
317
+
318
+ module MyScript exposing (run)
319
+
320
+ import BackendTask
321
+ import Pages.Script as Script exposing (Script)
322
+
323
+ run : Script
324
+ run =
325
+ Script.withoutCliOptions
326
+ (Script.exec "ls" [])
327
+
328
+ -}
329
+ exec : String -> List String -> BackendTask FatalError ()
330
+ exec command_ args_ =
331
+ Stream.command command_ args_
332
+ |> Stream.run
333
+
334
+
335
+ {-| Run a single command and return stderr and stdout combined as a single String.
336
+
337
+ If you want to do more advanced things like piping together multiple commands in a pipeline, or piping in a file to a command, etc., see the [`Stream`](BackendTask-Stream) module.
338
+
339
+ module MyScript exposing (run)
340
+
341
+ import BackendTask
342
+ import Pages.Script as Script exposing (Script)
343
+
344
+ run : Script
345
+ run =
346
+ Script.withoutCliOptions
347
+ (Script.command "ls" []
348
+ |> BackendTask.andThen
349
+ (\files ->
350
+ Script.log ("Files: " ++ files)
351
+ )
352
+ )
353
+
354
+ -}
355
+ command : String -> List String -> BackendTask FatalError String
356
+ command command_ args_ =
357
+ Stream.commandWithOptions
358
+ (defaultCommandOptions |> Stream.withOutput Stream.MergeStderrAndStdout)
359
+ command_
360
+ args_
361
+ |> Stream.read
362
+ |> BackendTask.map .body
363
+ |> BackendTask.allowFatal
@@ -1,6 +1,7 @@
1
1
  module Pages.StaticHttp.Request exposing (Request, codec, hash)
2
2
 
3
3
  import Codec exposing (Codec)
4
+ import Dict exposing (Dict)
4
5
  import FNV1a
5
6
  import Json.Encode as Encode
6
7
  import Pages.Internal.StaticHttpBody as StaticHttpBody exposing (Body)
@@ -12,6 +13,9 @@ type alias Request =
12
13
  , headers : List ( String, String )
13
14
  , body : Body
14
15
  , cacheOptions : Maybe Encode.Value
16
+ , env : Dict String String
17
+ , dir : List String
18
+ , quiet : Bool
15
19
  }
16
20
 
17
21
 
@@ -41,4 +45,7 @@ codec =
41
45
  |> Codec.field "headers" .headers (Codec.list (Codec.tuple Codec.string Codec.string))
42
46
  |> Codec.field "body" .body StaticHttpBody.codec
43
47
  |> Codec.nullableField "cacheOptions" .cacheOptions Codec.value
48
+ |> Codec.field "env" .env (Codec.dict Codec.string)
49
+ |> Codec.field "dir" .dir (Codec.list Codec.string)
50
+ |> Codec.field "quiet" .quiet Codec.bool
44
51
  |> Codec.buildObject
@@ -1,4 +1,4 @@
1
- module RequestsAndPending exposing (HttpError(..), RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get)
1
+ module RequestsAndPending exposing (HttpError(..), RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get, responseDecoder)
2
2
 
3
3
  import Base64
4
4
  import Bytes exposing (Bytes)
@@ -31,7 +31,7 @@ import Elm.Annotation as Type
31
31
  import Elm.Declare
32
32
  import Elm.Op
33
33
  import List.Extra
34
- import Result.Extra
34
+ import Vendored.Result.Extra
35
35
 
36
36
 
37
37
  {-| -}
@@ -188,8 +188,7 @@ restArgsParser =
188
188
  |> Cli.Option.validateMap
189
189
  (\items ->
190
190
  items
191
- |> List.map parseField
192
- |> Result.Extra.combine
191
+ |> Vendored.Result.Extra.combineMap parseField
193
192
  )
194
193
 
195
194
 
@@ -11,6 +11,7 @@ module TerminalText exposing
11
11
  , red
12
12
  , resetColors
13
13
  , text
14
+ , toPlainString
14
15
  , toString
15
16
  , toString_
16
17
  , yellow
@@ -109,6 +110,13 @@ toString_ (Style ansiStyle innerText) =
109
110
  ]
110
111
 
111
112
 
113
+ toPlainString : List Text -> String
114
+ toPlainString list =
115
+ list
116
+ |> List.map (\(Style _ inner) -> inner)
117
+ |> String.concat
118
+
119
+
112
120
  fromAnsiString : String -> List Text
113
121
  fromAnsiString ansiString =
114
122
  Ansi.parseInto ( blankStyle, [] ) parseInto ansiString
@@ -0,0 +1,75 @@
1
+ module Vendored.Result.Extra exposing (combine, combineMap, isOk, merge)
2
+
3
+
4
+ isOk : Result x a -> Bool
5
+ isOk result =
6
+ case result of
7
+ Ok _ ->
8
+ True
9
+
10
+ Err _ ->
11
+ False
12
+
13
+
14
+ merge : Result a a -> a
15
+ merge r =
16
+ case r of
17
+ Ok rr ->
18
+ rr
19
+
20
+ Err rr ->
21
+ rr
22
+
23
+
24
+
25
+ -- https://github.com/elmcraft/core-extra/blob/2.0.0/src/Result/Extra.elm
26
+
27
+
28
+ {-| Combine a list of results into a single result (holding a list).
29
+ Also known as `sequence` on lists.
30
+ -}
31
+ combine : List (Result x a) -> Result x (List a)
32
+ combine list =
33
+ combineHelp list []
34
+
35
+
36
+ combineHelp : List (Result x a) -> List a -> Result x (List a)
37
+ combineHelp list acc =
38
+ case list of
39
+ head :: tail ->
40
+ case head of
41
+ Ok a ->
42
+ combineHelp tail (a :: acc)
43
+
44
+ Err x ->
45
+ Err x
46
+
47
+ [] ->
48
+ Ok (List.reverse acc)
49
+
50
+
51
+ {-| Map a function producing results on a list
52
+ and combine those into a single result (holding a list).
53
+ Also known as `traverse` on lists.
54
+
55
+ combineMap f xs == combine (List.map f xs)
56
+
57
+ -}
58
+ combineMap : (a -> Result x b) -> List a -> Result x (List b)
59
+ combineMap f ls =
60
+ combineMapHelp f ls []
61
+
62
+
63
+ combineMapHelp : (a -> Result x b) -> List a -> List b -> Result x (List b)
64
+ combineMapHelp f list acc =
65
+ case list of
66
+ head :: tail ->
67
+ case f head of
68
+ Ok a ->
69
+ combineMapHelp f tail (a :: acc)
70
+
71
+ Err x ->
72
+ Err x
73
+
74
+ [] ->
75
+ Ok (List.reverse acc)
@@ -1 +0,0 @@
1
- {"type":"application","source-directories":["../../src","../../tests","../../../../src","src"],"elm-version":"0.19.1","dependencies":{"direct":{"elm/core":"1.0.5","elm/json":"1.1.3","elm-community/result-extra":"2.4.0","elm-explorations/test":"2.1.1","jfmengels/elm-review":"2.13.1","mpizenberg/elm-test-runner":"6.0.0","stil4m/elm-syntax":"7.3.2"},"indirect":{"elm/bytes":"1.0.8","elm/html":"1.0.0","elm/parser":"1.1.0","elm/project-metadata-utils":"1.0.2","elm/random":"1.0.0","elm/time":"1.0.0","elm/virtual-dom":"1.0.3","miniBill/elm-unicode":"1.1.0","rtfeldman/elm-hex":"1.0.0","stil4m/structured-writer":"1.0.3"}},"test-dependencies":{"direct":{},"indirect":{}}}