Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Includedot #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/shared-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
6 changes: 4 additions & 2 deletions replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions test/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

})