Skip to content

Commit

Permalink
vocabs.metadata.resources: new error resource-missing, if a resources…
Browse files Browse the repository at this point in the history
….txt line doesnt match something

So then if files declared in resources.txt are missing, that will
hopefully be caught by the deploy process.
  • Loading branch information
bjourne committed Sep 13, 2016
1 parent c23dbf0 commit b40e6cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 6 additions & 2 deletions basis/vocabs/metadata/resources/resources-tests.factor
Expand Up @@ -2,11 +2,15 @@
USING: arrays globs sorting tools.test vocabs.metadata.resources ;
IN: vocabs.metadata.resources.tests

! filter-resources
! match-pattern
{ { "hello.txt" } } [
"*.txt" <glob> 1array { "hello.txt" } filter-resources
"*.txt" { "hello.txt" } match-pattern
] unit-test

[
"*.txt" { "foo.bar" "foo.factor" } match-pattern
] [ resource-missing? ] must-fail-with

! vocab-resource-files
{ { "bar" "bas" "foo" } }
[ "vocabs.metadata.resources.test.1" vocab-resource-files natural-sort ] unit-test
Expand Down
19 changes: 13 additions & 6 deletions basis/vocabs/metadata/resources/resources.factor
@@ -1,6 +1,7 @@
! (c)2010 Joe Groff bsd license
USING: globs io.directories io.directories.hierarchy io.files.info
io.pathnames kernel regexp sequences vocabs.loader vocabs.metadata ;
USING: fry globs io.directories io.directories.hierarchy io.files.info
io.pathnames kernel regexp sequences sets vocabs.loader
vocabs.metadata ;
IN: vocabs.metadata.resources

<PRIVATE
Expand All @@ -21,13 +22,19 @@ PRIVATE>
dup directory-tree-files [ append-path ] with map
] [ drop { } ] if swap prefix ;

: filter-resources ( resource-globs vocab-files -- vocab-files' )
[ swap [ matches? ] with any? ] with filter ;
ERROR: resource-missing pattern ;

: match-pattern ( pattern files -- files' )
over <glob> '[ _ matches? ] filter
[ resource-missing ] [ nip ] if-empty ;

: match-patterns ( patterns files -- files' )
'[ _ match-pattern ] map concat members ;

: vocab-resource-files ( vocab -- filenames )
[ vocab-resources [ <glob> ] map ] [ vocab-dir-in-root ] bi
[ vocab-resources ] [ vocab-dir-in-root ] bi
[
filter-resources [ expand-resource ] map concat
match-patterns [ expand-resource ] map concat
] with-directory-files ;

: copy-vocab-resources ( dir vocab -- )
Expand Down

0 comments on commit b40e6cb

Please sign in to comment.