From 5add1cfd259063bcc02acae2431915ff933ef4ad Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 27 Dec 2015 00:05:32 -0600 Subject: [PATCH] Add test/remove.js to remove snippets while preserving new lines. --- .travis.yml | 12 ++++++------ test/remove.js | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 test/remove.js diff --git a/.travis.yml b/.travis.yml index d4af58278..d30ae16fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ env: global: - BIN="node" ISTANBUL=false OPTION="" - NPM_VERSION="^2.0.0" SAUCE_LABS=false SAUCE_USERNAME="lodash" - - PATTERN1="s|\s*if\s*\(isHostObject\b[\s\S]+?\}(?=\n)||" - - PATTERN2="s|\s*if\s*\(enumerate\b[\s\S]+?\};\s*\}||" - - PATTERN3="s|\s*while\s*\([^)]+\)\s*\{\s*iteratee\(index\);\s*\}||" + - PATTERN1="|\s*if\s*\(isHostObject\b[\s\S]+?\}(?=\n)|" + - PATTERN2="|\s*if\s*\(enumerate\b[\s\S]+?\};\s*\}|" + - PATTERN3="|\s*while\s*\([^)]+\)\s*\{\s*iteratee\(index\);\s*\}|" - secure: "tg1JFsIFnxzLaTboFPOnm+aJCuMm5+JdhLlESlqg9x3fwro++7KCnwHKLNovhchaPe4otC43ZMB/nfWhDnDm11dKbm/V6HlTkED+dadTsaLxVDg6J+7yK41QhokBPJOxLV78iDaNaAQVYEirAgZ0yn8kFubxmNKV+bpCGQNc9yU=" matrix: - @@ -40,9 +40,9 @@ before_install: - "nvm use $TRAVIS_NODE_VERSION" - "npm config set loglevel error" - "npm i -g npm@\"$NPM_VERSION\"" - - "[ $ISTANBUL == false ] || perl -0pi -e \"$PATTERN1\" ./lodash.js" - - "[ $ISTANBUL == false ] || perl -0pi -e \"$PATTERN2\" ./lodash.js" - - "[ $ISTANBUL == false ] || perl -0pi -e \"$PATTERN3\" ./lodash.js" + - "[ $ISTANBUL == false ] || node ./test/remove.js \"$PATTERN1\" ./lodash.js" + - "[ $ISTANBUL == false ] || node ./test/remove.js \"$PATTERN2\" ./lodash.js" + - "[ $ISTANBUL == false ] || node ./test/remove.js \"$PATTERN3\" ./lodash.js" - "git clone --depth=10 --branch=master git://github.com/lodash/lodash-cli ./node_modules/lodash-cli && mkdir $_/node_modules && cd $_ && ln -s ../../../ ./lodash && cd ../ && npm i && cd ../../" - "node ./node_modules/lodash-cli/bin/lodash -o ./dist/lodash.js" script: diff --git a/test/remove.js b/test/remove.js new file mode 100644 index 000000000..ad7f46621 --- /dev/null +++ b/test/remove.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node +'use strict'; + +/** Load modules. */ +var fs = require('fs'), + path = require('path'); + +/** Resolve program params. */ +var args = process.argv.slice(process.argv[0] === process.execPath ? 2 : 0), + filePath = path.resolve(args[1]); + +var pattern = (function() { + var result = args[0], + delimiter = result.charAt(0), + lastIndex = result.lastIndexOf(delimiter); + + return RegExp(result.slice(1, lastIndex), result.slice(lastIndex + 1)); +}()); + +/** Used to match lines of code. */ +var reLine = /.*/gm; + +/*----------------------------------------------------------------------------*/ + +fs.writeFileSync(filePath, fs.readFileSync(filePath, 'utf-8').replace(pattern, function(match) { + return match.replace(reLine, ''); +}), 'utf-8');