From 20742d0f66c414bbbb419ee16b3c1d3862723e13 Mon Sep 17 00:00:00 2001 From: "clintwood (Office)" Date: Thu, 19 Apr 2018 15:24:27 +0200 Subject: [PATCH 1/3] add -c, --copy-source Copy typed source with .flow extension to output option --- flow-remove-types | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flow-remove-types b/flow-remove-types index 91fb132..24941ca 100755 --- a/flow-remove-types +++ b/flow-remove-types @@ -14,6 +14,8 @@ var usage = 'Usage: flow-remove-types [options] [sources] \n' + ' -x, --extensions File extensions to transform\n' + ' -o, --out-file The file path to write transformed file to\n' + ' -d, --out-dir The directory path to write transformed files within\n' + +' -c, --copy-source Copy typed source with .flow extension to output\n' + +' Only applies when --out-file or --out-dir options are used\n' + ' -a, --all Transform all files, not just those with a @flow comment\n' + ' -p, --pretty Remove flow types without replacing with spaces, \n' + ' producing prettier output but may require using source maps\n' + @@ -71,6 +73,7 @@ var ignore = /node_modules/; var extensions = [ '.js', '.mjs', '.jsx', '.flow', '.es6' ]; var outDir; var outFile; +var copySource; var all; var pretty; var sourceMaps; @@ -94,6 +97,8 @@ while (i < process.argv.length) { outFile = process.argv[i++]; } else if (arg === '-d' || arg === '--out-dir') { outDir = process.argv[i++]; + } else if (arg === '-c' || arg === '--copy-source') { + copySource = true; } else if (arg === '-a' || arg === '--all') { all = true; } else if (arg === '-p' || arg === '--pretty') { @@ -220,6 +225,11 @@ function transformAndOutput(content, outFile, source) { fs.writeFileSync(mapOutFile, JSON.stringify(map) + '\n'); info('\033[2m \u21B3 \033[32m' + mapOutFile + '\033[0m\n'); } + if (copySource) { + var flowSource = outFile + '.flow'; + fs.writeFileSync(flowSource, content); + info('\033[2m \u21B3 \033[32m' + flowSource + '\033[0m\n'); + } } else { process.stdout.write(code); } From ec24a77d28655821a07d6b4244e1bba91922e2cc Mon Sep 17 00:00:00 2001 From: "clintwood (Office)" Date: Thu, 19 Apr 2018 15:34:06 +0200 Subject: [PATCH 2/3] add test for --copy-source option --- test.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 6d8a526..3abd803 100755 --- a/test.sh +++ b/test.sh @@ -10,7 +10,7 @@ echo "Test: flow-remove-types --pretty test/source.js" DIFF=$(./flow-remove-types --pretty test/source.js | diff test/expected-pretty.js -); if [ -n "$DIFF" ]; then echo "$DIFF"; exit 1; fi; -# Test expected source maps with --pretty --sourcemaps +# Test expected source maps with --pretty --sourcemaps --out-dir echo "Test: flow-remove-types --pretty --sourcemaps test/source.js -d test/expected-with-maps" TEST_DIR=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd) DIR=$(mktemp -d) @@ -24,6 +24,23 @@ rm -rf $DIR if [ -n "$DIFF_SOURCE" ]; then echo "$DIFF_SOURCE"; exit 1; fi; if [ -n "$DIFF_MAP" ]; then echo "$DIFF_MAP"; exit 1; fi; +# Test expected source maps with --copy-source --pretty --sourcemaps --out-dir +echo "Test: flow-remove-types --copy-source --pretty --sourcemaps test/source.js -d test/expected-with-maps" +TEST_DIR=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd) +DIR=$(mktemp -d) +cp -r test $DIR +pushd $DIR > /dev/null +$TEST_DIR/flow-remove-types --copy-source --pretty --sourcemaps test/source.js -d test/expected-with-maps; +popd > /dev/null +DIFF_SOURCE=$(diff test/expected-with-maps/test/source.js $DIR/test/expected-with-maps/test/source.js); +DIFF_MAP=$(diff test/expected-with-maps/test/source.js.map $DIR/test/expected-with-maps/test/source.js.map); +DIFF_FLOW=$(diff test/source.js $DIR/test/expected-with-maps/test/source.js.flow); +echo $DIR +rm -rf $DIR +if [ -n "$DIFF_SOURCE" ]; then echo "$DIFF_SOURCE"; exit 1; fi; +if [ -n "$DIFF_MAP" ]; then echo "$DIFF_MAP"; exit 1; fi; +if [ -n "$DIFF_FLOW" ]; then echo "$DIFF_FLOW"; exit 1; fi; + # Test expected source maps with --pretty --sourcemaps inline echo "Test: flow-remove-types --pretty --sourcemaps inline test/source.js" DIFF=$(./flow-remove-types --pretty --sourcemaps inline test/source.js | diff test/expected-pretty-inlinemap.js -); From ee22ebe6a42c172930ac32ce424049e8b410a1b3 Mon Sep 17 00:00:00 2001 From: "clintwood (Office)" Date: Fri, 6 Jul 2018 13:10:27 +0200 Subject: [PATCH 3/3] remove debug code from test.sh --- test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test.sh b/test.sh index 3abd803..2cd5c55 100755 --- a/test.sh +++ b/test.sh @@ -35,7 +35,6 @@ popd > /dev/null DIFF_SOURCE=$(diff test/expected-with-maps/test/source.js $DIR/test/expected-with-maps/test/source.js); DIFF_MAP=$(diff test/expected-with-maps/test/source.js.map $DIR/test/expected-with-maps/test/source.js.map); DIFF_FLOW=$(diff test/source.js $DIR/test/expected-with-maps/test/source.js.flow); -echo $DIR rm -rf $DIR if [ -n "$DIFF_SOURCE" ]; then echo "$DIFF_SOURCE"; exit 1; fi; if [ -n "$DIFF_MAP" ]; then echo "$DIFF_MAP"; exit 1; fi;