diff --git a/common/web/gesture-recognizer/src/tools/host-fixture/extract-fixture.sh b/common/web/gesture-recognizer/src/tools/host-fixture/extract-fixture.sh index 075fadc358..49943fb97b 100755 --- a/common/web/gesture-recognizer/src/tools/host-fixture/extract-fixture.sh +++ b/common/web/gesture-recognizer/src/tools/host-fixture/extract-fixture.sh @@ -9,7 +9,6 @@ set -eu THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")" cd $(dirname "$THIS_SCRIPT") -FIXTURE_START=" " -FIXTURE_END=" " - -sed -n "/$FIXTURE_START/, /$FIXTURE_END/{ /$FIXTURE_START/! { /$FIXTURE_END/! p } }" host-fixture.html \ No newline at end of file +# On Windows, `node extractor.js` cannot be directly piped; that requires `node.exe`. +# But that doesn't make sense on other platforms, so... wrapper script. +node extractor.js \ No newline at end of file diff --git a/common/web/gesture-recognizer/src/tools/host-fixture/extractor.js b/common/web/gesture-recognizer/src/tools/host-fixture/extractor.js new file mode 100644 index 0000000000..5573ac8e0b --- /dev/null +++ b/common/web/gesture-recognizer/src/tools/host-fixture/extractor.js @@ -0,0 +1,26 @@ +var fs = require('fs'); +var os = require('os'); + +const args = process.argv.slice(2); + +// args[0] - destination file path. If not provided, the text will be dumped to the console. + +fs.readFile('host-fixture.html', 'utf8', function(err, text) { + if(err) { + throw err; + } + + let FIXTURE_START = " " + os.EOL; + let FIXTURE_END = " " + os.EOL; + + let startIndex = text.indexOf(FIXTURE_START); + let endIndex = text.indexOf(FIXTURE_END) + FIXTURE_END.length; + + let desiredText = text.substring(startIndex, endIndex); + + if(args[0]) { + fs.writeFileSync(args[0], desiredText); + } else { + console.log(desiredText); + } +}); \ No newline at end of file diff --git a/common/web/gesture-recognizer/src/tools/recorder/build.sh b/common/web/gesture-recognizer/src/tools/recorder/build.sh index bfb2d3cbce..407fad41f6 100755 --- a/common/web/gesture-recognizer/src/tools/recorder/build.sh +++ b/common/web/gesture-recognizer/src/tools/recorder/build.sh @@ -34,12 +34,9 @@ build_recorder_page ( ) { cp ../host-fixture/gestureHost.css build/gestureHost.css - FIXTURE=`$FIXTURE_SCRIPT` - FIXTURE_TARGET="" - # Thanks to https://stackoverflow.com/a/10107668 for this tidbit. # Searches for FIXTURE_TARGET above and replaces it with the actual fixture! - awk -v r="$FIXTURE" "{gsub(/$FIXTURE_TARGET/,r)}1" src/index.html > build/index.html + node update-index.js build/index.html } FIXTURE_SCRIPT=../host-fixture/extract-fixture.sh diff --git a/common/web/gesture-recognizer/src/tools/recorder/update-index.js b/common/web/gesture-recognizer/src/tools/recorder/update-index.js new file mode 100644 index 0000000000..97f530d6ee --- /dev/null +++ b/common/web/gesture-recognizer/src/tools/recorder/update-index.js @@ -0,0 +1,21 @@ +var fs = require('fs'); +var os = require('os'); +var child_process = require('child_process'); + +const args = process.argv.slice(2); + +// args[0] - destination file path. If not provided, the text will be dumped to the console. + +fs.readFile('src/index.html', 'utf8', function(err, text) { + if(err) { + throw err; + } + + // Runs the fixture-extractor script, receives the fixture's raw HTML. + let buf = child_process.execSync("node extractor.js", {cwd: "../host-fixture", windowsHide: true, shell: true}).toString(); + + let INSERTION_POINT = " " + os.EOL; + text = text.replace(INSERTION_POINT, buf); + + fs.writeFileSync(args[0], text); +}); \ No newline at end of file