File tree Expand file tree Collapse file tree 2 files changed +59
-7
lines changed Expand file tree Collapse file tree 2 files changed +59
-7
lines changed Original file line number Diff line number Diff line change 1+ { lib } :
2+ # root is the absolute path to the directory with .lbf files.
3+ # Example
4+ # ~~~~~~
5+ # ```nix
6+ # let
7+ # lbfListModules = pkgs.callPackage (import ./lbf-list-modules.nix) {};
8+ # in lbfListModules ./src
9+ # ```
10+ # evaluates to
11+ # ```
12+ # MySchema
13+ # Directory.MySchema
14+ # ```
15+ # where
16+ # ```text
17+ # $ tree src/
18+ # src/
19+ # ├── Directory
20+ # │ └── MySchema.lbf
21+ # └── MySchema.lbf
22+ # ```
23+
24+ root :
25+ # INVARIANT:
26+ # - dir == dotPrefix except dotPrefix doesn't contain the prefix root, and
27+ # dotPrefix has all `/`s replaced with a singular `.`
28+ # - `dotPrefix` always contains the dot at the end if it needs to be there
29+ let
30+ matchLbfFile = name :
31+ let matches = builtins . match ''(.*)\.lbf$'' name ;
32+ in if matches == null
33+ then null
34+ else builtins . elemAt matches 0 ;
35+
36+ go = dir : dotPrefix :
37+ builtins . concatLists
38+ ( lib . mapAttrsToList
39+ ( name : value :
40+ if value == "directory"
41+ then go "${ dir } /${ name } " "${ dotPrefix } ${ name } ."
42+
43+ else if value == "regular"
44+ then
45+ # Is this an lbf file?
46+ let lbfFileMatch = matchLbfFile name ;
47+ in if lbfFileMatch != null
48+ then [ "${ dotPrefix } ${ lbfFileMatch } " ]
49+ else [ ]
50+ else
51+ builtins . trace ''warning: `${ name } ` has file type `${ value } ` which is not a regular file nor directory''
52+ [ ]
53+ )
54+ ( builtins . readDir dir )
55+ ) ;
56+ in
57+ go root ""
Original file line number Diff line number Diff line change 8585
8686 # TODO(jaredponn): this was (essentially) stolen from the Rust side. This
8787 # should be made a common function.
88- findModules = root : builtins . map
89- ( path : builtins . replaceStrings [ "/" ] [ "." ]
90- ( pkgs . lib . strings . removePrefix "./" ( pkgs . lib . strings . removeSuffix ".lbf"
91- ( pkgs . lib . strings . removePrefix root path ) ) ) )
92- ( builtins . filter ( pkgs . lib . hasSuffix ".lbf" )
93- ( pkgs . lib . filesystem . listFilesRecursive root ) ) ;
88+ lbfListModules = pkgs . callPackage ./lbf-list-modules.nix { } ;
9489
9590 packageSet =
9691 pkgs . writeTextFile {
9792 name = "lb-typescript-packages" ;
9893 text =
9994 builtins . toJSON
100- ( builtins . mapAttrs ( _name : findModules ) imports ) ;
95+ ( builtins . mapAttrs ( _name : lbfListModules ) imports ) ;
10196 } ;
10297
10398 lbfBuilt = with lbfTypescriptOpts ;
You can’t perform that action at this time.
0 commit comments