Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Hidden files are now ignored by "build" and "server". Issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Oct 26, 2015
1 parent 3a3f08f commit ee4faf2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
19 changes: 14 additions & 5 deletions dist/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_ = require('lodash'),
createHash = require('crypto').createHash,
recursive = require('recursive-readdir'),
hidefile = require('hidefile'),
chcpContext;

module.exports = {
Expand All @@ -24,11 +25,7 @@
ignore = context.ignoredFiles();

recursive(chcpContext.sourceDirectory, ignore, function (err, files) {
var hashQueue = [];
for (var i in files) {
var file = files[i];
hashQueue.push(hashFile.bind(null, file));
}
var hashQueue = prepareFilesHashQueue(files);

async.parallelLimit(hashQueue, 10, function (err, result) {
var json = JSON.stringify(result, null, 2);
Expand Down Expand Up @@ -57,6 +54,18 @@
return executeDfd.promise;
}

function prepareFilesHashQueue(files) {
var queue = [];
for (var i in files) {
var file = files[i];
if (!hidefile.isHiddenSync(file)) {
queue.push(hashFile.bind(null, file));
}
}

return queue;
}

function prepareConfig(context) {
var config = {};

Expand Down
3 changes: 2 additions & 1 deletion dist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
compression = require('compression'),
build = require('./build.js').execute,
minimatch = require('minimatch'),
hidefile = require('hidefile'),
io,
chcpContext,
sourceDirectory,
Expand Down Expand Up @@ -85,7 +86,7 @@
var fileIsAllowed = true;
var relativeFilePath = path.relative(chcpContext.sourceDirectory, file);
for (var i = 0, len = ignoredFiles.length; i < len; i++) {
if (minimatch(relativeFilePath, ignoredFiles[i])) {
if (hidefile.isHiddenSync(file) || minimatch(relativeFilePath, ignoredFiles[i])) {
fileIsAllowed = false;
break;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"socket.io": "^1.3.6",
"watch": "^0.16.0",
"yargs": "^3.16.1",
"minimatch": "^3.0.0"
"minimatch": "^3.0.0",
"hidefile": "^1.1.0"
},
"devDependencies": {
"babel": "^5.8.19",
Expand Down
19 changes: 14 additions & 5 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
_ = require('lodash'),
createHash = require('crypto').createHash,
recursive = require('recursive-readdir'),
hidefile = require('hidefile'),
chcpContext;

module.exports = {
Expand All @@ -22,11 +23,7 @@
ignore = context.ignoredFiles();

recursive(chcpContext.sourceDirectory, ignore, function(err, files) {
var hashQueue = [];
for (var i in files) {
var file = files[i];
hashQueue.push(hashFile.bind(null, file));
}
var hashQueue = prepareFilesHashQueue(files);

async.parallelLimit(hashQueue, 10, function(err, result) {
var json = JSON.stringify(result, null, 2);
Expand Down Expand Up @@ -55,6 +52,18 @@
return executeDfd.promise;
}

function prepareFilesHashQueue(files) {
var queue = [];
for (var i in files) {
var file = files[i];
if (!hidefile.isHiddenSync(file)) {
queue.push(hashFile.bind(null, file));
}
}

return queue;
}

function prepareConfig(context) {
var config = {};

Expand Down
3 changes: 2 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
compression = require('compression'),
build = require('./build.js').execute,
minimatch = require('minimatch'),
hidefile = require('hidefile'),
io,
chcpContext,
sourceDirectory,
Expand Down Expand Up @@ -83,7 +84,7 @@
var fileIsAllowed = true;
var relativeFilePath = path.relative(chcpContext.sourceDirectory, file);
for (var i=0, len=ignoredFiles.length; i<len; i++) {
if (minimatch(relativeFilePath, ignoredFiles[i])) {
if (hidefile.isHiddenSync(file) || minimatch(relativeFilePath, ignoredFiles[i])) {
fileIsAllowed = false;
break;
}
Expand Down

0 comments on commit ee4faf2

Please sign in to comment.