From ee4faf23f3e9653a68646022f568524b44d75a0b Mon Sep 17 00:00:00 2001 From: Nikolay Demyankov Date: Mon, 26 Oct 2015 11:58:43 +0100 Subject: [PATCH] Hidden files are now ignored by "build" and "server". Issue https://github.com/nordnet/cordova-hot-code-push-cli/issues/8 --- dist/build.js | 19 ++++++++++++++----- dist/server.js | 3 ++- package.json | 3 ++- src/build.js | 19 ++++++++++++++----- src/server.js | 3 ++- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/dist/build.js b/dist/build.js index 124d5d5..6351edc 100644 --- a/dist/build.js +++ b/dist/build.js @@ -10,6 +10,7 @@ _ = require('lodash'), createHash = require('crypto').createHash, recursive = require('recursive-readdir'), + hidefile = require('hidefile'), chcpContext; module.exports = { @@ -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); @@ -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 = {}; diff --git a/dist/server.js b/dist/server.js index 6985051..4b10ed1 100644 --- a/dist/server.js +++ b/dist/server.js @@ -14,6 +14,7 @@ compression = require('compression'), build = require('./build.js').execute, minimatch = require('minimatch'), + hidefile = require('hidefile'), io, chcpContext, sourceDirectory, @@ -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; } diff --git a/package.json b/package.json index 6c49e46..b3e31c5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/build.js b/src/build.js index 9a5e838..5aa7504 100644 --- a/src/build.js +++ b/src/build.js @@ -8,6 +8,7 @@ _ = require('lodash'), createHash = require('crypto').createHash, recursive = require('recursive-readdir'), + hidefile = require('hidefile'), chcpContext; module.exports = { @@ -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); @@ -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 = {}; diff --git a/src/server.js b/src/server.js index fe09787..f5eb874 100644 --- a/src/server.js +++ b/src/server.js @@ -12,6 +12,7 @@ compression = require('compression'), build = require('./build.js').execute, minimatch = require('minimatch'), + hidefile = require('hidefile'), io, chcpContext, sourceDirectory, @@ -83,7 +84,7 @@ var fileIsAllowed = true; var relativeFilePath = path.relative(chcpContext.sourceDirectory, file); for (var i=0, len=ignoredFiles.length; i