diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index b943cf22..e2ce1e39 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -1,4 +1,4 @@ -const version = '0.19.0' +const version = '0.19.1' const sidebar = [ { diff --git a/docs/.vitepress/theme/components/ExampleGallery.vue b/docs/.vitepress/theme/components/ExampleGallery.vue index d351ba17..46cecce9 100644 --- a/docs/.vitepress/theme/components/ExampleGallery.vue +++ b/docs/.vitepress/theme/components/ExampleGallery.vue @@ -20,6 +20,7 @@ export default { { kind: "official", title: "📊 Query Parameters", id: "06-query-parameters", src: "/images/guide/query-parameters.gif" }, { kind: "official", title: "🧱 Working with JS", id: "07-working-with-js", src: "/images/examples/working-with-js.gif" }, { kind: "official", title: "🪆 Nested Layouts", id: "08-nested-layouts", src: "/images/examples/nested-layouts.gif" }, + { kind: "official", title: "🪄 Catch-all Routes", id: "09-catch-all-routes", src: "/images/examples/catch-all-routes.jpg" }, { kind: "official", title: "🧩 TypeScript Interop", id: "10-typescript-interop", src: "/images/examples/typescript.gif" }, { kind: "official", title: "🚨 Error Reporting", id: "11-error-reporting", src: "/images/examples/sentry.gif" }, { kind: "official", title: "🎨 Using Elm UI", id: "12-elm-ui", src: "/images/examples/elm-ui.jpg" }, diff --git a/docs/concepts/cli.md b/docs/concepts/cli.md index 238bad02..fa5c3c99 100644 --- a/docs/concepts/cli.md +++ b/docs/concepts/cli.md @@ -172,7 +172,7 @@ Here's example output of what you'd see if you ran this command in the ["Pages a ```txt - 🌈 Elm Land (v0.19.0) found 5 pages in your application + 🌈 Elm Land (v0.19.1) found 5 pages in your application ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ src/Pages/Home_.elm ............... http://localhost:1234/ src/Pages/SignIn.elm .............. http://localhost:1234/sign-in diff --git a/docs/guide/deploying.md b/docs/guide/deploying.md index 933a241c..9522cb1e 100644 --- a/docs/guide/deploying.md +++ b/docs/guide/deploying.md @@ -16,7 +16,7 @@ elm-land build ```txt -🌈 Elm Land (v0.19.0) build was successful. +🌈 Elm Land (v0.19.1) build was successful. ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ ``` diff --git a/docs/guide/pages-and-routes.md b/docs/guide/pages-and-routes.md index 48fb90c9..ccad9681 100644 --- a/docs/guide/pages-and-routes.md +++ b/docs/guide/pages-and-routes.md @@ -326,7 +326,7 @@ elm-land routes ```txt - 🌈 Elm Land (v0.19.0) found 6 pages in your application + 🌈 Elm Land (v0.19.1) found 6 pages in your application ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ src/Pages/Home_.elm ........................... / src/Pages/SignIn.elm .......................... /sign-in diff --git a/docs/index.md b/docs/index.md index bde8d714..5250c740 100644 --- a/docs/index.md +++ b/docs/index.md @@ -56,6 +56,13 @@ const members = [ { icon: 'github', link: 'https://github.com/ianmackenzie' } ] }, + { + avatar: 'https://www.github.com/alpakaxaxa.png', + name: '@alpakaxaxa', + links: [ + { icon: 'github', link: 'https://github.com/alpakaxaxa' } + ] + }, ] diff --git a/docs/public/images/examples/catch-all-routes.jpg b/docs/public/images/examples/catch-all-routes.jpg new file mode 100644 index 00000000..ad9bcaf7 Binary files /dev/null and b/docs/public/images/examples/catch-all-routes.jpg differ diff --git a/examples/09-catch-all-routes/.gitignore b/examples/09-catch-all-routes/.gitignore new file mode 100644 index 00000000..7295c4fe --- /dev/null +++ b/examples/09-catch-all-routes/.gitignore @@ -0,0 +1,7 @@ +/dist +/.elm-land +/.env +/elm-stuff +/node_modules +.DS_Store +*.pem \ No newline at end of file diff --git a/examples/09-catch-all-routes/elm-land.json b/examples/09-catch-all-routes/elm-land.json new file mode 100644 index 00000000..999fb98a --- /dev/null +++ b/examples/09-catch-all-routes/elm-land.json @@ -0,0 +1,28 @@ +{ + "app": { + "elm": { + "development": { "debugger": true }, + "production": { "debugger": false } + }, + "env": [], + "html": { + "attributes": { + "html": { "lang": "en" }, + "head": {} + }, + "title": "Elm Land", + "meta": [ + { "charset": "UTF-8" }, + { "http-equiv": "X-UA-Compatible", "content": "IE=edge" }, + { "name": "viewport", "content": "width=device-width, initial-scale=1.0" } + ], + "link": [ + { "rel": "stylesheet", "href": "/main.css" } + ], + "script": [] + }, + "router": { + "useHashRouting": false + } + } +} \ No newline at end of file diff --git a/examples/09-catch-all-routes/elm.json b/examples/09-catch-all-routes/elm.json new file mode 100644 index 00000000..5868b5e1 --- /dev/null +++ b/examples/09-catch-all-routes/elm.json @@ -0,0 +1,25 @@ +{ + "type": "application", + "source-directories": [ + "src", + ".elm-land/src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0", + "elm/json": "1.1.3", + "elm/url": "1.0.0" + }, + "indirect": { + "elm/time": "1.0.0", + "elm/virtual-dom": "1.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/examples/09-catch-all-routes/src/Pages/Home_.elm b/examples/09-catch-all-routes/src/Pages/Home_.elm new file mode 100644 index 00000000..8a248089 --- /dev/null +++ b/examples/09-catch-all-routes/src/Pages/Home_.elm @@ -0,0 +1,106 @@ +module Pages.Home_ exposing (page) + +import Html exposing (..) +import Html.Attributes exposing (..) +import Route.Path +import View exposing (View) + + +type alias Link = + { label : String + , path : Route.Path.Path + } + + +page : View msg +page = + { title = "Homepage" + , body = + [ h1 [] [ text "🏡 Homepage" ] + , p [] [ text "Click a link below to learn how URLs work in Elm Land" ] + , section [] + [ h3 [] [ text "🧑\u{200D}💻 Users" ] + , viewLinks + [ { label = "@elm-land" + , path = Route.Path.User_ { user = "elm-land" } + } + , { label = "@ryannhg" + , path = Route.Path.User_ { user = "ryannhg" } + } + , { label = "@elm" + , path = Route.Path.User_ { user = "elm" } + } + ] + ] + , section [] + [ h3 [] [ text "📦 Repos" ] + , viewLinks + [ { label = "@elm-land/vscode" + , path = + Route.Path.User__Repo_ + { user = "elm-land" + , repo = "vscode" + } + } + , { label = "@ryannhg/graphql" + , path = + Route.Path.User__Repo_ + { user = "ryannhg" + , repo = "graphql" + } + } + , { label = "@elm/compiler" + , path = + Route.Path.User__Repo_ + { user = "elm" + , repo = "compiler" + } + } + ] + ] + , section [] + [ h3 [] [ text "🗃 File Explorer" ] + , viewLinks + [ { label = "README from @elm-land/vscode" + , path = + Route.Path.User__Repo__Tree_Branch__ALL_ + { user = "elm-land" + , repo = "vscode" + , branch = "main" + , all_ = [ "README.md" ] + } + } + , { label = "`Decode.elm` from @ryannhg/graphql" + , path = + Route.Path.User__Repo__Tree_Branch__ALL_ + { user = "ryannhg" + , repo = "graphql" + , branch = "main" + , all_ = [ "src", "GraphQL", "Decode.elm" ] + } + } + , { label = "`Compile.hs` from @elm/compiler" + , path = + Route.Path.User__Repo__Tree_Branch__ALL_ + { user = "elm" + , repo = "compiler" + , branch = "master" + , all_ = [ "compiler", "src", "Compile.hs" ] + } + } + ] + ] + ] + } + + +viewLinks : List Link -> Html msg +viewLinks links = + ul [] (List.map viewLink links) + + +viewLink : Link -> Html msg +viewLink link = + li [] + [ a [ Route.Path.href link.path ] [ text link.label ] + ] diff --git a/examples/09-catch-all-routes/src/Pages/User_.elm b/examples/09-catch-all-routes/src/Pages/User_.elm new file mode 100644 index 00000000..e14e3409 --- /dev/null +++ b/examples/09-catch-all-routes/src/Pages/User_.elm @@ -0,0 +1,16 @@ +module Pages.User_ exposing (page) + +import Html exposing (..) +import Route.Path +import View exposing (View) + + +page : { user : String } -> View msg +page params = + { title = "@" ++ params.user ++ " | Users" + , body = + [ h1 [] [ text ("🧑\u{200D}💻 @" ++ params.user) ] + , p [] [ text "Hello from `src/Pages/User_.elm 👋" ] + , a [ Route.Path.href Route.Path.Home_ ] [ text "Back to homepage" ] + ] + } diff --git a/examples/09-catch-all-routes/src/Pages/User_/Repo_.elm b/examples/09-catch-all-routes/src/Pages/User_/Repo_.elm new file mode 100644 index 00000000..ad096c45 --- /dev/null +++ b/examples/09-catch-all-routes/src/Pages/User_/Repo_.elm @@ -0,0 +1,16 @@ +module Pages.User_.Repo_ exposing (page) + +import Html exposing (..) +import Route.Path +import View exposing (View) + + +page : { user : String, repo : String } -> View msg +page params = + { title = "@" ++ params.user ++ "/" ++ params.repo ++ " | Repos" + , body = + [ h1 [] [ text ("📦 @" ++ params.user ++ "/" ++ params.repo) ] + , p [] [ text "Hello from `src/Pages/User_/Repo_.elm 👋" ] + , a [ Route.Path.href Route.Path.Home_ ] [ text "Back to homepage" ] + ] + } diff --git a/examples/09-catch-all-routes/src/Pages/User_/Repo_/Tree/Branch_/ALL_.elm b/examples/09-catch-all-routes/src/Pages/User_/Repo_/Tree/Branch_/ALL_.elm new file mode 100644 index 00000000..f95b5b79 --- /dev/null +++ b/examples/09-catch-all-routes/src/Pages/User_/Repo_/Tree/Branch_/ALL_.elm @@ -0,0 +1,22 @@ +module Pages.User_.Repo_.Tree.Branch_.ALL_ exposing (page) + +import Html exposing (..) +import Route.Path +import View exposing (View) + + +page : + { user : String + , repo : String + , branch : String + , all_ : List String + } + -> View msg +page params = + { title = "@" ++ params.user ++ "/" ++ params.repo ++ " | File Explorer" + , body = + [ h1 [] [ text ("🗃 ~/" ++ String.join "/" params.all_) ] + , p [] [ text "Hello from `src/Pages/User_/Repo_/Tree/Branch_/ALL_.elm 👋" ] + , a [ Route.Path.href Route.Path.Home_ ] [ text "Back to homepage" ] + ] + } diff --git a/examples/09-catch-all-routes/static/main.css b/examples/09-catch-all-routes/static/main.css new file mode 100644 index 00000000..3492af88 --- /dev/null +++ b/examples/09-catch-all-routes/static/main.css @@ -0,0 +1,10 @@ +body { + margin: 2rem auto; + padding: 0 2rem; + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + max-width: 40em; +} + +p { + color: #555; +} \ No newline at end of file diff --git a/projects/cli/README.md b/projects/cli/README.md index 8a455e86..5df08f84 100644 --- a/projects/cli/README.md +++ b/projects/cli/README.md @@ -17,7 +17,7 @@ The `elm-land` CLI comes with everything you need to create your next web applic ``` $ elm-land -🌈 Welcome to Elm Land! (v0.19.0) +🌈 Welcome to Elm Land! (v0.19.1) ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ Here are the available commands: diff --git a/projects/cli/package-lock.json b/projects/cli/package-lock.json index 4e6b66aa..2ae0b9fe 100644 --- a/projects/cli/package-lock.json +++ b/projects/cli/package-lock.json @@ -1,12 +1,12 @@ { "name": "elm-land", - "version": "0.19.0", + "version": "0.19.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "elm-land", - "version": "0.19.0", + "version": "0.19.1", "license": "ISC", "dependencies": { "@lydell/elm": "^0.19.1-12", diff --git a/projects/cli/package.json b/projects/cli/package.json index 3c4bd66c..28680035 100644 --- a/projects/cli/package.json +++ b/projects/cli/package.json @@ -1,6 +1,6 @@ { "name": "elm-land", - "version": "0.19.0", + "version": "0.19.1", "description": "Reliable web apps for everyone", "main": "index.js", "types": "./index.d.ts", diff --git a/projects/cli/src/codegen/src/Commands/Generate.elm b/projects/cli/src/codegen/src/Commands/Generate.elm index 739089c9..113a9076 100644 --- a/projects/cli/src/codegen/src/Commands/Generate.elm +++ b/projects/cli/src/codegen/src/Commands/Generate.elm @@ -2832,13 +2832,17 @@ routePathFromStringExpression { pages } = CodeGen.Expression.caseExpression { value = CodeGen.Argument.new "urlPathSegments" , branches = + let + pageBranches = + pages + |> List.filter (\page -> not (PageFile.isNotFoundPage page)) + |> List.map toBranch + in if List.any PageFile.isTopLevelCatchAllPage pages then - pages - |> List.filter (\page -> not (PageFile.isNotFoundPage page)) - |> List.map toBranch + pageBranches else - List.map toBranch pages ++ [ nothingBranch ] + pageBranches ++ [ nothingBranch ] } } diff --git a/projects/cli/src/effects.js b/projects/cli/src/effects.js index b2466acf..27f584bb 100644 --- a/projects/cli/src/effects.js +++ b/projects/cli/src/effects.js @@ -529,7 +529,7 @@ const generateHtml = async (config) => { ? [toHtmlTag('title', {}, config.app.html.title)] : [] let metaTags = toSelfClosingHtmlTags('meta', [ - { name: 'elm-land', content: '0.19.0' } + { name: 'elm-land', content: '0.19.1' } ].concat(attempt(_ => config.app.html.meta))) let linkTags = toSelfClosingHtmlTags('link', attempt(_ => config.app.html.link)) let scriptTags = toHtmlTags('script', attempt(_ => config.app.html.script)) diff --git a/projects/cli/tests/08-examples.bats b/projects/cli/tests/08-examples.bats index cd7c64fe..b8dbf452 100644 --- a/projects/cli/tests/08-examples.bats +++ b/projects/cli/tests/08-examples.bats @@ -42,6 +42,12 @@ load helpers expectElmExampleBuilds } +@test "'09-catch-all-routes' example builds successfully" { + cd ../../examples/09-catch-all-routes + run npm install + expectElmExampleBuilds +} + @test "'10-typescript-interop' example builds successfully" { cd ../../examples/10-typescript-interop expectElmExampleBuilds diff --git a/projects/cli/tests/09-elm-binary.bats b/projects/cli/tests/09-elm-binary.bats index b9225d92..8d93a9e2 100644 --- a/projects/cli/tests/09-elm-binary.bats +++ b/projects/cli/tests/09-elm-binary.bats @@ -54,7 +54,7 @@ load helpers cp -r ../../examples/01-hello-world ../../examples/01-local-hello cd ../../examples/01-local-hello - echo '{ "dependencies": { "elm-land": "file:../../projects/cli/elm-land-0.19.0.tgz" } }' > package.json + echo '{ "dependencies": { "elm-land": "file:../../projects/cli/elm-land-0.19.1.tgz" } }' > package.json npm install run npx elm-land build @@ -72,7 +72,7 @@ load helpers cp -r ../../examples/01-hello-world ../../examples/01-local-hello cd ../../examples/01-local-hello - echo '{ "dependencies": { "elm-land": "file:../../projects/cli/elm-land-0.19.0.tgz" } }' > package.json + echo '{ "dependencies": { "elm-land": "file:../../projects/cli/elm-land-0.19.1.tgz" } }' > package.json npm install -g yarn yarn @@ -91,7 +91,7 @@ load helpers cp -r ../../examples/01-hello-world ../../examples/01-local-hello cd ../../examples/01-local-hello - echo '{ "dependencies": { "elm-land": "file:../../projects/cli/elm-land-0.19.0.tgz" } }' > package.json + echo '{ "dependencies": { "elm-land": "file:../../projects/cli/elm-land-0.19.1.tgz" } }' > package.json npm install -g pnpm pnpm install diff --git a/projects/graphql/README.md b/projects/graphql/README.md index 46cffaae..2d971d1b 100644 --- a/projects/graphql/README.md +++ b/projects/graphql/README.md @@ -23,7 +23,7 @@ npm install -g elm-land@latest ```txt $ elm-land graphql -🌈 Elm Land (v0.19.0) wants to add a plugin! +🌈 Elm Land (v0.19.1) wants to add a plugin! ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ To use the `@elm-land/graphql` plugin, I'll need to install the NPM package and add a bit of JSON @@ -35,14 +35,14 @@ $ elm-land graphql ```txt $ elm-land graphql build -🌈 Elm Land (v0.19.0) successfully generated Elm files +🌈 Elm Land (v0.19.1) successfully generated Elm files ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ ``` ```txt $ elm-land graphql watch -🌈 Elm Land (v0.19.0) is watching "./graphql/*" for changes... +🌈 Elm Land (v0.19.1) is watching "./graphql/*" for changes... ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ ``` @@ -55,7 +55,7 @@ Here’s what running the CLI looks like when there’s no schema provided: ``` $ elm-land graphql build -🌈 Elm Land (v0.19.0) needs a GraphQL schema +🌈 Elm Land (v0.19.1) needs a GraphQL schema ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ You can provide one by customizing the "elm-land.json" file to include a "graphql.schema" field. diff --git a/projects/graphql/package-lock.json b/projects/graphql/package-lock.json index 389c4384..96f8b97f 100644 --- a/projects/graphql/package-lock.json +++ b/projects/graphql/package-lock.json @@ -1,12 +1,12 @@ { "name": "@elm-land/graphql", - "version": "0.19.0", + "version": "0.19.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@elm-land/graphql", - "version": "0.19.0", + "version": "0.19.1", "license": "ISC", "dependencies": { "graphql": "16.6.0" diff --git a/projects/graphql/package.json b/projects/graphql/package.json index 782a1108..f886fb23 100644 --- a/projects/graphql/package.json +++ b/projects/graphql/package.json @@ -1,6 +1,6 @@ { "name": "@elm-land/graphql", - "version": "0.19.0", + "version": "0.19.1", "description": "Generate Elm code from GraphQL files", "main": "src/index.js", "scripts": {