From d071587251ecfdbafbc10553a7ac4d9465153a7b Mon Sep 17 00:00:00 2001 From: Mantz Date: Thu, 20 Aug 2015 20:56:44 +0300 Subject: [PATCH 1/3] include or exclude file starting with dot, e.g. '.class' or '.project' - option added - test added --- bin/replace.js | 1 + bin/shared-options.js | 4 ++++ replace.js | 6 ++++-- test/sanity.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/bin/replace.js b/bin/replace.js index 2c3e192..a0cb289 100755 --- a/bin/replace.js +++ b/bin/replace.js @@ -44,6 +44,7 @@ var addlOptions = { var opts = {}; for (var opt in sharedOptions) { + console.log(opt); opts[opt] = sharedOptions[opt]; } for (var opt in addlOptions) { diff --git a/bin/shared-options.js b/bin/shared-options.js index 47b58c2..865eaf2 100644 --- a/bin/shared-options.js +++ b/bin/shared-options.js @@ -78,5 +78,9 @@ module.exports = { noColor: { help: 'Disable color output.', flag: true + }, + dot: { + help: "include or exclude file starting with dot, e.g. '.class' or '.project'", + default: false } }; diff --git a/replace.js b/replace.js index 7ce5e0d..5d9ca79 100644 --- a/replace.js +++ b/replace.js @@ -67,16 +67,17 @@ module.exports = function(options) { function canSearch(file, isFile) { var inIncludes = includes && includes.some(function(include) { - return minimatch(file, include, { matchBase: true }); + return minimatch(file, include, { matchBase: true, dot: options.dot }); }) var inExcludes = excludes.some(function(exclude) { - return minimatch(file, exclude, { matchBase: true }); + return minimatch(file, exclude, { matchBase: true, dot: options.dot }); }) return ((!includes || !isFile || inIncludes) && (!excludes || !inExcludes)); } function replacizeFile(file) { + console.log(file,canSearch(file, isFile)); fs.lstat(file, function(err, stats) { if (err) throw err; @@ -118,6 +119,7 @@ module.exports = function(options) { } function replacizeFileSync(file) { + console.log(file,canSearch(file, isFile)); var stats = fs.lstatSync(file); if (stats.isSymbolicLink()) { // don't follow symbolic links for now diff --git a/test/sanity.js b/test/sanity.js index 3948f6d..7e9dd43 100644 --- a/test/sanity.js +++ b/test/sanity.js @@ -132,3 +132,33 @@ test('preview', function(t) { var expected = "aaaa"; t.equal(getText(file), expected, "no replacement if 'preview' is true"); }) + +test('dot', function(t) { + t.plan(8); + + //var changedFiles = ['./test_files/.test']; + var file = "./test_files/.test"; + + replace({ + regex: "dot", + replacement: "DOT", + paths: [file], + recursive: false, + dot: true + }); + + var expected = "DOT"; + + t.equal(getText(file), expected, "- found a file that start with dot"); + + replace({ + regex: "DOT", + replacement: "dot", + paths: [file], + recursive: false, + dot: true + }); + + var expected = "dot"; + t.equal(getText(file), expected, "reverting worked"); +}) \ No newline at end of file From 7ee86c4e11a14b491efd07442ee746d29291795c Mon Sep 17 00:00:00 2001 From: Mantz Date: Thu, 20 Aug 2015 21:06:58 +0300 Subject: [PATCH 2/3] removed log --- bin/replace.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/replace.js b/bin/replace.js index a0cb289..2c3e192 100755 --- a/bin/replace.js +++ b/bin/replace.js @@ -44,7 +44,6 @@ var addlOptions = { var opts = {}; for (var opt in sharedOptions) { - console.log(opt); opts[opt] = sharedOptions[opt]; } for (var opt in addlOptions) { From 722cd8b795760f88b10a901d2ea79335085e6e9b Mon Sep 17 00:00:00 2001 From: Mantz Date: Thu, 20 Aug 2015 21:50:08 +0300 Subject: [PATCH 3/3] dot is active just when using the include option improved the tests --- bin/shared-options.js | 2 +- test/sanity.js | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/bin/shared-options.js b/bin/shared-options.js index 865eaf2..618c1f1 100644 --- a/bin/shared-options.js +++ b/bin/shared-options.js @@ -80,7 +80,7 @@ module.exports = { flag: true }, dot: { - help: "include or exclude file starting with dot, e.g. '.class' or '.project'", + help: "when using include option, include files starting with dot, e.g. '.class' or '.project'", default: false } }; diff --git a/test/sanity.js b/test/sanity.js index 7e9dd43..6e0917e 100644 --- a/test/sanity.js +++ b/test/sanity.js @@ -136,14 +136,14 @@ test('preview', function(t) { test('dot', function(t) { t.plan(8); - //var changedFiles = ['./test_files/.test']; - var file = "./test_files/.test"; + var file = "./test_files/.project"; replace({ regex: "dot", replacement: "DOT", paths: [file], - recursive: false, + recursive: true, + include: '*', dot: true }); @@ -155,10 +155,39 @@ test('dot', function(t) { regex: "DOT", replacement: "dot", paths: [file], - recursive: false, + recursive: true, + include: '*', dot: true }); var expected = "dot"; t.equal(getText(file), expected, "reverting worked"); + + replace({ + regex: "dot", + replacement: "DOT", + paths: [file], + recursive: true, + include: '*', + fileColor: 'red', + dot: false + }); + + var expected = "dot"; + + t.equal(getText(file), expected, "- default without dot still working"); + + replace({ + regex: "DOT", + replacement: "dot", + paths: [file], + recursive: true, + include: '*', + fileColor: 'red', + dot: false + }); + + var expected = "dot"; + t.equal(getText(file), expected, "reverting worked if mess"); + }) \ No newline at end of file