#!/bin/bash
# ━━━━━━━━━━
# test-image - Fake a run of the Web imager on my local files
# ━━━━━━━━━━
#
#      test-image  [<additional imaging options>]  <boundary path>
#
#   The <boundary path> and any <additional imaging options> are passed verbatim to `waycast-web-image`.
#
#   The present directory for the run will be `~/work/`.  This will be the effective value,
#   for instance, of any <boundary path> given as `./`.
#
#   N.B. the warning for `-reference-mapping` (2) below that it ‘will break references…
#   proper to my downstream `~/project/` branches’.


    function run {
        /home/mike/_/Web_service/ensure-hard-links

        echo
        echo 'Rebuild the Web imager'
        echo '──────────────────────'
        cd ~/work/
        wayic/Web/imager/build-all || return # Build the Web imager, or refresh the present build.
        echo

        echo 'Fake an imaging run'
        echo '───────────────────'
        wayic/Web/imager/bin/waycast-web-image -co-service-directory='/_/Web_service' \
            -exclude='/\.(?:git|hg)' \
            -fake -force -math $* \
            -reference-mapping=';^http://reluk.ca/project(/Java/editorial_guidelines)(\.brec)$;~/work$1_$2;' \
            -reference-mapping=';^http://reluk.ca/project(/(?:Tapster|way|wayic)/.*\.brec$);~/code/WP3$1;||;^http://reluk.ca/project(/.*\.brec$);~/work$1;' \
            -reference-mapping=';^http://reluk.ca(/.*\.brec$);~$1;' ;}
          # -exclude : Repository guts.
          # -force : Generally redundant (exceptions include a few test directories that contain image
          #     files) but the intent here is to fake an *exhaustive* test image and this enforces it.
          # -reference-mapping (1-3) : Locally remapping Breccian references that target my Web site,
          #     so ensuring (as a workaround for deferral of HTTP fetches) full parsing
          #     of referent clauses and hyperlinking of their referents.
          #     http://reluk.ca/project/Breccia/Web/imager/working_notes.brec.xht#deferral,hTTP,fetches
          # -reference-mapping (1) : Remapping to a symbolic link named with a trailing underscore,
          #     as per `~/work/Java/.git/info/exclude`.
          # -reference-mapping (2) : This will break references to fracta and files proper to my
          #     downstream `~/project/` branches, with consequent warnings from the imager (‘No such
          #     fractum’ or ‘No such file’).  This is because it remaps `http://reluk.ca/project/`
          #     not to `~/project/`, which the `-exclude` above omits from the image, but to the upstream
          #     `~/work/` or equivalent.  The whole purpose of `test-image` is to test working-copy
          #     changes before committing them and publishing them via `flow-downstream` and
          #     `publish-files`, and remapping to `~/work/` enables this.


    run $*
    status=$?
    exit $status


          # -exclude='/home/mike/(_/client|code(?!/WP3)|project|sys/computer/Primeval/(home|opt)|var)' \
          # -exclude='/tmp$' \