diff --git a/bin/shared-options.js b/bin/shared-options.js index 47b58c2..618c1f1 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: "when using include option, include files 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..6e0917e 100644 --- a/test/sanity.js +++ b/test/sanity.js @@ -132,3 +132,62 @@ 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 file = "./test_files/.project"; + + replace({ + regex: "dot", + replacement: "DOT", + paths: [file], + recursive: true, + include: '*', + 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: 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