Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maketile v2 #99

Closed
24 of 30 tasks
edemaine opened this issue Oct 5, 2022 · 1 comment
Closed
24 of 30 tasks

Maketile v2 #99

edemaine opened this issue Oct 5, 2022 · 1 comment

Comments

@edemaine
Copy link
Owner

edemaine commented Oct 5, 2022

Instead of inventing a language as in #84, let's use JavaScript/CoffeeScript! This let us use for loops and compilated switch/if...else if...else logic. For example (based on #96):

export switched = ->
  for filename in svgtiler.glob '*.asc'
    switch
      when svgtiler.match filename, 'simple_*'
        svgtiler 'mapping1.coffee', filename
      else
        svgtiler 'mapping2.coffee', filename

export simple = ->
  svgtiler '''
    ( mapping1.coffee *.asc )
    ( mapping2.coffee *.xlsx )
  '''

export default both = ->
  simple()
  switched()

export {default as figures} from './figures/Maketile'

import figures1 from './figures1/Maketile'
import figures2 from './figures1/Maketile'
exports figures = ->
  figures1()
  figures2()
  • Maketile.js/Maketile.coffee run automatically by svgtiler without filename on command line
    • svgtiler directory-name does the same for directory-name/Maketile.*
    • Some options change default settings for svgtiler and still trigger Maketile. This allows tweaking the options via e.g. svgtiler -f or svgtiler -w. Perhaps Maketile executed if no filenames on command like (but note that some options that look like filenames might be rule names, and should be interpreted as such instead).
  • svgtiler(['map1.js', 'drawing.asc']) — array arguments treated as already parsed (nice for arbitrary filenames)
    • This is very close to existing svgtiler.main (perhaps better named svgtiler.run)
    • Also allow passing in a Mapping or Drawing directly (via svgtiler.require, for example).
    • Perhaps allow nested arrays too, for for loops, or else use ...
    • Maybe also builders like svgtiler.group(...) for parenthesis-like behavior.
  • svgtiler('map1.js drawing.asc') — string argument(s) parsed like shell (nice for more like Makefile usage)
    • Maybe also explicit calls like svgtiler.shell(...) vs svgtiler.run(...) for when e.g. you want to call on one directory name. Or maybe just use template literal idea below. String vs. array argument seems like a better distinguisher.
    • Allow comments via # and multiple lines
    • We'll need shell-like quote and backslash parsing, to handle filenames with spaces or other special characters (e.g. *).
    • Glob support
    • Allow multiple arguments, including Mapping objects or arrays, to mix with previous type.
  • svgtiler`map1.js ${new Mapping(...)}` in JS or svgtiler"map1.js #{new Mapping(...)}" in CS (template literal) is a possibility if we want a hybrid between the two. We can detect this via the raw field in the first argument.
  • Maketile.args Maketile without extension could still be the simpler command-line arguments only (essentially wrapped by svgtiler '''...''' in CoffeeScript), as in Maketiles: Config files like Makefiles #84 (but without rules)
  • Glob helpers that wrap our glob library, e.g. to loop over *.{asc,xls*} and check which type of processing you want to do.
    • svgtiler.glob(pattern) to find all files matching given pattern (synchronously, ideally)
    • svgtiler.match(filename, pattern) to test whether a file matches a given pattern.
    • Maybe also want a glob filter, so we can do something like svgtiler.filter(svgtiler.glob('*.asc'), '!simple_*') to implement set operations as in Filename patterns #96. (Sadly JavaScript Sets don't have union/intersection...)
    • Maybe allow glob array to be passed into svgtiler. Else need ...glob, which is maybe hard to do in template literal.
    • Should be relative to Maketile (or mapping?) directory, not current directory
    • Maybe also allow RegExp arguments to svgtiler.glob and svgtiler
  • Optimize: Check whether mappings are same as last invocation of svgtiler and don't reinitialize in this case.
    • Hmm, but this would break the contract that onInit gets called every time the mapping file is listed on the command line. So maybe not a good optimization.
    • Parens are less important in this view because we can just run svgtiler multiple times. Typically we imagine clustering among drawings in terms of how to process them.
  • Tasks/rules, perhaps via named exported functions (as opposed to Cakefile's task function)
  • Use export default for main task, also so can call it from another (parent) Maketile
  • Implementation similar to Mapping, maybe a shared parent: Want JS/CS/JSX/require parsing similarly, but don't want onInit/preprocess/postprocess.
  • --maketile alternative-maketile.coffee, in particular to enable running rules from another Maketile
    • We can already recurse in a directory via svgtiler('dirName') or via require('dirName/Maketile.js')().
    • Sadly -m is taken by --margin
  • Potentially still compatible with watch mode -w (Watch mode #74), with svgtiler(...) accumulating jobs into a list. Perhaps use of svgtiler.glob('*.asc') also causes rerun when new .asc file created.
  • Could implement svgtiler --clean by changing effect of svgtiler function to delete files that would be generated. (Maketiles: Config files like Makefiles #84)
  • svgtiler.needVersion('^3.1.0') could allow specifying what version of SVG Tiler this is designed for (also in mapping files). (Maketiles: Config files like Makefiles #84)
  • new InlineMapping -> ... to simulate the code of a mapping file without a separate file? ... could schedule callbacks via svgtiler.preprocess etc. Mappings specified by classes or objects #95 Export redesign #100 provides an alternative for inline mappings without separate files.
@edemaine edemaine changed the title Maketile alternative Maketile v2 Oct 5, 2022
edemaine added a commit that referenced this issue Oct 14, 2022
* `filename.args` adds arguments to command line, parsed like a shell
* `Maketile.args` loaded automatically if no other files
* Rudamentary `Maketile.coffee` and `Maketile.js` autoloading
  (but no API support yet)
edemaine added a commit that referenced this issue Oct 14, 2022
edemaine added a commit that referenced this issue Oct 14, 2022
More glob helpers via minimatch
edemaine added a commit that referenced this issue Oct 15, 2022
Existing files or matching globs still take priority over rules,
to avoid loading Maketile when possible.
edemaine added a commit that referenced this issue Oct 15, 2022
Existing files or matching globs still take priority over rules,
to avoid loading Maketile when possible.
edemaine added a commit that referenced this issue Oct 15, 2022
* `main` and `run` (which is the main `svgtiler` function) now run
  within a `Driver` class that keeps track of that driver's settings.
* `getDriver` and `runWithDriver` keep track of currently running
  Driver, and enable new Driver to inherit settings from parent.
* Array of `formats` pushed into settings for proper inheritance.
* `getSettings` now returns `defaultSettings` instead of `null`.
edemaine added a commit that referenced this issue Oct 15, 2022
* Specifying a directory on the command line recurses into that directory.
* All example Makefiles now replaced by Maketiles
edemaine added a commit that referenced this issue Oct 16, 2022
Also fix glob spec to match first Maketile, not last
edemaine added a commit that referenced this issue Oct 16, 2022
Also fix glob spec to match first Maketile, not last
edemaine added a commit that referenced this issue Oct 18, 2022
edemaine added a commit that referenced this issue Oct 18, 2022
edemaine added a commit that referenced this issue Oct 29, 2022
@edemaine
Copy link
Owner Author

This is basically done; remaining ideas are speculative, or left to #74.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant