fix and improve prepareSourceTree

This commit is contained in:
DavHau 2022-02-25 15:11:15 +07:00
parent 42507e645c
commit 2afaae4f5b

View File

@ -71,7 +71,7 @@ let
if prefix == "" then if prefix == "" then
name name
else else
"${prefix}/name"; "${prefix}/${name}";
directories = directories =
l.mapAttrs l.mapAttrs
@ -85,19 +85,41 @@ let
files = files =
l.mapAttrs l.mapAttrs
(fname: _: l.trace fname rec { (fname: _: rec {
name = fname; name = fname;
fullPath = "${fullPath'}/${fname}"; fullPath = "${fullPath'}/${fname}";
relPath = makeNewPath relPath fname; relPath = makeNewPath relPath' fname;
content = readTextFile fullPath; content = readTextFile fullPath;
jsonContent = l.fromJSON content; jsonContent = l.fromJSON content;
tomlContent = l.fromTOML content; tomlContent = l.fromTOML content;
}) })
fileNames; fileNames;
getNodeFromPath = path:
let
pathSplit = l.splitString "/" path;
dirSplit = l.init pathSplit;
leaf = l.last pathSplit;
dirAttrPath =
l.init
(l.concatMap
(x: [x] ++ ["directories"])
dirSplit);
dir = l.getAttrFromPath dirAttrPath directories;
in
if dir ? directories."${leaf}" then
dir.directories."${leaf}"
else if dir ? files."${leaf}" then
dir.files."${leaf}"
else
throw "could not find file or directory ${path} in ${fullPath'}";
in in
{ {
inherit name files relPath; inherit files getNodeFromPath name relPath;
fullPath = fullPath'; fullPath = fullPath';
} }