Skip to content

Commit

Permalink
Directory recursion support (#99)
Browse files Browse the repository at this point in the history
* Specifying a directory on the command line recurses into that directory.
* All example Makefiles now replaced by Maketiles
  • Loading branch information
edemaine committed Oct 15, 2022
1 parent 59513d6 commit 08b05c9
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 85 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ build:
#npm run prepare

examples:
for example in examples/*; do \
make -C $$example ; \
done
svgtiler examples

test:
java -Xss1024k -jar node_modules/vnu-jar/build/dist/vnu.jar \
Expand Down
3 changes: 3 additions & 0 deletions examples/Maketile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default ->
for example in svgtiler.glob '*/' # match directories only
svgtiler [example]
6 changes: 0 additions & 6 deletions examples/anim/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions examples/auto/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions examples/chess/Makefile

This file was deleted.

3 changes: 0 additions & 3 deletions examples/grid-graph/Makefile

This file was deleted.

18 changes: 0 additions & 18 deletions examples/mario/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions examples/polyomino/Makefile

This file was deleted.

12 changes: 0 additions & 12 deletions examples/test/Makefile

This file was deleted.

5 changes: 0 additions & 5 deletions examples/tetris/Makefile

This file was deleted.

5 changes: 0 additions & 5 deletions examples/tilt/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions examples/unicode/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions examples/witness/Makefile

This file was deleted.

42 changes: 31 additions & 11 deletions src/svgtiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ class Driver extends HasSettings
else
null
main: (args = process.argv[2..]) -> runWithDriver @, =>
showHelp = 'No filename arguments and no Maketile to run; showing --help'
showHelp = 'No filename arguments and no Maketile to run. Try `svgtiler --help`'
ranMaketile = false
numFileArgs = 0
inits = [] # array of objects to call doInit() on
Expand Down Expand Up @@ -2567,18 +2567,38 @@ class Driver extends HasSettings
append = i+1 # where to append Args
for file in files
if typeof file == 'string'
cached = inputCache.has file
console.log '*', file, if cached then '(cached)' else ''
if cached
## Check for input already in cache (e.g. already loaded Mapping)
if inputCache.has file
console.log '*', file, '(cached)'
input = inputCache.get file
input.settings = @settings
else
input = Input.recognize file, undefined, @settings
## Cache Mapping files, as we only capture `onInit` etc. callbacks on
## the first load (top-level code run only during first `require`).
## Don't cache drawing files, as we might have changed options like
## `keepMargins` and `keepUneven` which affect parsing.
inputCache.set file, input if input instanceof Mapping
## Check for directory
if exists instanceof fs.Stats
stat = exists
else
try
stat = fs.statSync file
if stat?.isDirectory()
## Recursively run svgtiler within directory
console.log '**', file, '(directory)'
oldDir = process.cwd()
process.chdir file
(new Driver @).main []
process.chdir oldDir
console.log '..', file, '(end of directory)'
continue
else
## Regular file
input = inputRequire file, @settings
###
Cache Mapping files, as we only capture `onInit` etc.
callbacks on the first load (top-level code run only
during first `require`). Don't cache drawing files,
as we might have changed options like `keepMargins` and
`keepUneven` which affect parsing.
###
inputCache.set file, input if input instanceof Mapping
else if file? and typeof file == 'object'
console.log '*', file.constructor?.name, file.filename
else
Expand Down Expand Up @@ -2609,7 +2629,7 @@ class Driver extends HasSettings
i++
if showHelp
console.log showHelp
help()
#help()

run: (...protoArgs) ->
args = []
Expand Down

0 comments on commit 08b05c9

Please sign in to comment.