hayley williams, youve done it again 👏

This commit is contained in:
Ryan Haskell-Glatz 2019-12-24 18:13:19 -06:00
parent 1802c2e1b1
commit 0800060abc
9 changed files with 1274 additions and 45 deletions

View File

@ -9,7 +9,8 @@
"elm/browser": "1.0.2",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/json": "1.1.3"
"elm/json": "1.1.3",
"elm-community/list-extra": "8.2.2"
},
"indirect": {
"elm/time": "1.0.0",
@ -18,7 +19,11 @@
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
"direct": {
"elm-explorations/test": "1.2.2"
},
"indirect": {
"elm/random": "1.0.0"
}
}
}

View File

@ -6,7 +6,7 @@
"start": "npm install && npm run dev",
"dev": "npm run elm:spa:build && npm run build:watch",
"build": "npm run elm:spa:build && npm run elm:compile",
"build:watch": "concurrently --kill-others \"npm run elm:spa:watch\" \"npm run elm:live\"",
"build:watch": "concurrently --raw --kill-others \"npm run elm:spa:watch\" \"npm run elm:live\"",
"elm:compile": "elm make src/Main.elm --output=public/dist/elm.compiled.js --optimize",
"elm:live": "elm-live src/Main.elm --dir=public --start-page=index.html --open --pushstate --port=1234 -- --output=public/dist/elm.compiled.js --debug",
"elm:spa:build": "elm-spa build .",
@ -21,6 +21,6 @@
"concurrently": "5.0.0",
"elm": "0.19.1-3",
"elm-live": "4.0.1",
"elm-spa":"3.0.0"
"elm-spa":"3.0.2"
}
}

View File

@ -6,7 +6,7 @@
"start": "npm install && npm run dev",
"dev": "npm run elm:spa:build && npm run build:watch",
"build": "npm run elm:spa:build && npm run elm:compile",
"build:watch": "concurrently --kill-others \"npm run elm:spa:watch\" \"npm run elm:live\"",
"build:watch": "concurrently --raw --kill-others \"npm run elm:spa:watch\" \"npm run elm:live\"",
"elm:compile": "elm make src/Main.elm --output=public/dist/elm.compiled.js --optimize",
"elm:live": "elm-live src/Main.elm --dir=public --start-page=index.html --open --pushstate --port=1234 -- --output=public/dist/elm.compiled.js --debug",
"elm:spa:build": "elm-spa build .",
@ -21,6 +21,6 @@
"concurrently": "5.0.0",
"elm": "0.19.1-3",
"elm-live": "4.0.1",
"elm-spa":"3.0.0"
"elm-spa":"3.0.2"
}
}

1106
cli/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
{
"name": "elm-spa",
"version": "3.0.0",
"version": "3.0.2",
"description": "the cli companion tool for ryannhg/elm-spa",
"main": "src/index.js",
"bin": "src/index.js",
"scripts": {
"start": "npm run build && node src/index.js",
"build": "npm run elm:compile",
"test": "elm-test",
"test:watch": "elm-test --watch",
"elm:compile": "elm make src/elm/Main.elm --output=dist/elm.compiled.js --optimize"
},
"repository": {
@ -24,5 +26,9 @@
"bugs": {
"url": "https://github.com/ryannhg/elm-spa/issues"
},
"homepage": "https://github.com/ryannhg/elm-spa#readme"
"homepage": "https://github.com/ryannhg/elm-spa#readme",
"devDependencies": {
"elm": "0.19.1-3",
"elm-test": "0.19.1-revision2"
}
}

View File

@ -8,6 +8,7 @@ import Json.Encode as Json
import Ports
import Set exposing (Set)
import Templates.Layout
import Utils
type alias Flags =
@ -97,14 +98,14 @@ build { paths } =
List.concat
[ [ File [ "Routes" ]
(File.routes
{ paths = paths ++ [ [ "Authors", "Dynamic" ], [ "Authors", "Dynamic", "Posts" ] ]
{ paths = Utils.allSubsets paths
, pathsWithFiles = paths
}
)
]
, paths
|> List.foldl groupByFolder Dict.empty
|> Debug.log "grouped"
|> Utils.addInMissingFolders
|> toDetails
|> (\items ->
let
@ -173,14 +174,6 @@ layoutsToCreate { path, existingLayouts } =
|> List.filter (\list -> not (List.member list existingLayouts))
generate : List (a -> Maybe b) -> List a -> List b
generate fns value =
List.map
(\fn -> List.filterMap fn value)
fns
|> List.concat
dropLast : List a -> List a
dropLast =
List.reverse
@ -240,27 +233,7 @@ toDetails :
Dict String Items
-> List File.Details
toDetails dict =
[ ( ""
, { files = Set.fromList [ [ "NotFound" ], [ "Top" ] ]
, folders = Set.fromList [ [ "Authors" ] ]
}
)
, ( "Authors"
, { files = Set.fromList []
, folders = Set.fromList [ [ "Authors", "Dynamic" ] ]
}
)
, ( "Authors.Dynamic"
, { files = Set.fromList []
, folders = Set.fromList [ [ "Authors", "Dynamic", "Posts" ] ]
}
)
, ( "Authors.Dynamic.Posts"
, { files = Set.fromList [ [ "Authors", "Dynamic", "Posts", "Dynamic" ] ]
, folders = Set.fromList []
}
)
]
Dict.toList dict
|> List.map
(\( moduleName, { files, folders } ) ->
{ moduleName = moduleName

62
cli/src/elm/Utils.elm Normal file
View File

@ -0,0 +1,62 @@
module Utils exposing
( Items
, addInMissingFolders
, allSubsets
)
import Dict exposing (Dict)
import List.Extra
import Set exposing (Set)
type alias Filepath =
List String
type alias Items =
{ files : Set Filepath
, folders : Set Filepath
}
allSubsets : List (List comparable) -> List (List comparable)
allSubsets =
List.concatMap
(\list -> List.indexedMap (\i _ -> List.take (i + 1) list) list)
>> List.Extra.unique
addInMissingFolders : Dict String Items -> Dict String Items
addInMissingFolders dict =
let
keys : List String
keys =
Dict.keys dict
|> List.map (String.split ".")
|> allSubsets
|> List.map (String.join ".")
splitOnDot : String -> Filepath
splitOnDot str =
if String.isEmpty str then
[]
else
String.split "." str
oneLongerThan : Filepath -> Set Filepath
oneLongerThan filepath =
keys
|> List.map splitOnDot
|> List.filter (\dictFilepath -> List.length dictFilepath == List.length filepath + 1)
|> Set.fromList
in
keys
|> List.map
(\key ->
Dict.get key dict
|> Maybe.withDefault (Items Set.empty Set.empty)
|> (\items -> { items | folders = Set.union items.folders (oneLongerThan (splitOnDot key)) })
|> Tuple.pair key
)
|> Dict.fromList

View File

@ -4,8 +4,6 @@ const path = require('path')
const cwd = process.cwd()
const { File, Elm, bold } = require('./utils.js')
const debug = (a) => console.log(a) || a
const main = ([ command, ...args ] = []) =>
commands[command]
? commands[command](args)
@ -79,7 +77,6 @@ const build = ([ relative = '.' ]) => {
return Elm.checkForElmSpaJson(dir)
.then(json =>
File.paths(path.join(dir, 'src', 'Pages'))
.then(debug)
.then(Elm.run('build', { relative }, json['elm-spa']))
.then(Elm.formatOutput)
)

84
cli/tests/UtilsTest.elm Normal file
View File

@ -0,0 +1,84 @@
module UtilsTest exposing (expected, input, suite)
import Dict exposing (Dict)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Set exposing (Set)
import Test exposing (..)
import Utils exposing (Items)
suite : Test
suite =
describe "Utils"
[ describe "allSubsets"
[ test "works with authors posts example" <|
\_ ->
Utils.allSubsets
[ [ "Top" ]
, [ "NotFound" ]
, [ "Authors", "Dynamic", "Posts", "Dynamic" ]
]
|> Expect.equalLists
[ [ "Top" ]
, [ "NotFound" ]
, [ "Authors" ]
, [ "Authors", "Dynamic" ]
, [ "Authors", "Dynamic", "Posts" ]
, [ "Authors", "Dynamic", "Posts", "Dynamic" ]
]
]
, describe "addInMissingFolders"
[ test "works with authors post example" <|
\_ ->
Utils.addInMissingFolders input
|> Expect.equalDicts expected
]
]
input : Dict String Items
input =
Dict.fromList
[ ( ""
, { files = Set.fromList [ [ "NotFound" ], [ "Top" ] ]
, folders = Set.fromList []
}
)
, ( "Authors.Dynamic"
, { files = Set.fromList []
, folders = Set.fromList [ [ "Authors", "Dynamic", "Posts" ] ]
}
)
, ( "Authors.Dynamic.Posts"
, { files = Set.fromList [ [ "Authors", "Dynamic", "Posts", "Dynamic" ] ]
, folders = Set.fromList []
}
)
]
expected : Dict String Items
expected =
Dict.fromList
[ ( ""
, { files = Set.fromList [ [ "NotFound" ], [ "Top" ] ]
, folders = Set.fromList [ [ "Authors" ] ]
}
)
, ( "Authors"
, { files = Set.fromList []
, folders = Set.fromList [ [ "Authors", "Dynamic" ] ]
}
)
, ( "Authors.Dynamic"
, { files = Set.fromList []
, folders = Set.fromList [ [ "Authors", "Dynamic", "Posts" ] ]
}
)
, ( "Authors.Dynamic.Posts"
, { files = Set.fromList [ [ "Authors", "Dynamic", "Posts", "Dynamic" ] ]
, folders = Set.fromList []
}
)
]