From a4c836c337b0d06ad68601e4d572c949d7b4d98a Mon Sep 17 00:00:00 2001 From: Simon Hampton Date: Fri, 15 Feb 2019 22:47:28 +0100 Subject: [PATCH 1/2] add extra test --- .gitignore | 2 ++ src/lib.js | 14 +++++++++----- src/lib.spec.js | 5 +++++ test/simple/{inner => }/test-inside-root.excl | 0 test/test2/includeme.txt | 0 test/test2/node_modules/local/.excludedFile.txt | 1 + test/test2/node_modules/local/.testfile | 0 .../node_modules/local/folderA/test-inside-a.txt | 1 + test/test2/node_modules/local/test-inside-root.txt | 1 + 9 files changed, 19 insertions(+), 5 deletions(-) rename test/simple/{inner => }/test-inside-root.excl (100%) create mode 100644 test/test2/includeme.txt create mode 100644 test/test2/node_modules/local/.excludedFile.txt create mode 100644 test/test2/node_modules/local/.testfile create mode 100644 test/test2/node_modules/local/folderA/test-inside-a.txt create mode 100644 test/test2/node_modules/local/test-inside-root.txt diff --git a/.gitignore b/.gitignore index 6f6b23b..ab1bfea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ node_modules/ ignore .vscode test/remote +!test/test2/node_modules +playground .DS_Store notes.md diff --git a/src/lib.js b/src/lib.js index f82c2cd..4e19167 100644 --- a/src/lib.js +++ b/src/lib.js @@ -42,19 +42,22 @@ function getPassword(config) { } } -// Analysing local firstory - +// Analysing local directory function canIncludePath(includes, excludes, filePath) { + const options = { matchBase: true }; let go = (acc, item) => - acc || minimatch(filePath, item, { matchBase: true }); + acc || minimatch(filePath, item, options); let canInclude = includes.reduce(go, false); // Now check whether the file should in fact be specifically excluded if (canInclude) { // if any excludes match return false if (excludes) { - let go2 = (acc, item) => - acc && !minimatch(filePath, item, { matchBase: true }); + let go2 = (acc, exclItem) => { + const val = minimatch(filePath, exclItem, options); + // console.log(`minimatch("${filePath}", "${exclItem}", { matchBase: true })`, val); + return acc && !val; + } canInclude = excludes.reduce(go2, true); } } @@ -133,6 +136,7 @@ mkDirExists = (ftp, dir) => { return ftp.mkdir(dir, true) .catch(err => { if (err.message.startsWith("EEXIST")) { + // Ignore an error that the directory already exists return Promise.resolve() } else { console.log('[mkDirExists]', err.message); diff --git a/src/lib.spec.js b/src/lib.spec.js index 20e1bc9..62cfa23 100644 --- a/src/lib.spec.js +++ b/src/lib.spec.js @@ -66,6 +66,11 @@ describe('dirParseSync', () => { let exp2 = Object.assign(exp, { "folderA/folderB/FolderC": ["test-inside-c.txt"] }); assert.deepEqual(lib.parseLocal(['*'], ['.excludeme/**/*'], rootDir, '/'), exp2); }); + it('should be able to exclude node_modules', () => { + const rootDir = path.join(__dirname, '../test/test2'); + let exp = {'/': ['includeme.txt']}; + assert.deepEqual(lib.parseLocal(['*'], ['node_modules/**'], rootDir, '/'), exp); + }); }); let exp = { diff --git a/test/simple/inner/test-inside-root.excl b/test/simple/test-inside-root.excl similarity index 100% rename from test/simple/inner/test-inside-root.excl rename to test/simple/test-inside-root.excl diff --git a/test/test2/includeme.txt b/test/test2/includeme.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/test2/node_modules/local/.excludedFile.txt b/test/test2/node_modules/local/.excludedFile.txt new file mode 100644 index 0000000..d6d9d34 --- /dev/null +++ b/test/test2/node_modules/local/.excludedFile.txt @@ -0,0 +1 @@ +blah \ No newline at end of file diff --git a/test/test2/node_modules/local/.testfile b/test/test2/node_modules/local/.testfile new file mode 100644 index 0000000..e69de29 diff --git a/test/test2/node_modules/local/folderA/test-inside-a.txt b/test/test2/node_modules/local/folderA/test-inside-a.txt new file mode 100644 index 0000000..60018fe --- /dev/null +++ b/test/test2/node_modules/local/folderA/test-inside-a.txt @@ -0,0 +1 @@ +test inside a \ No newline at end of file diff --git a/test/test2/node_modules/local/test-inside-root.txt b/test/test2/node_modules/local/test-inside-root.txt new file mode 100644 index 0000000..9d777e8 --- /dev/null +++ b/test/test2/node_modules/local/test-inside-root.txt @@ -0,0 +1 @@ +test inside root From 10f497d95b91d2d66246b40de17215221c388365 Mon Sep 17 00:00:00 2001 From: Simon Hampton Date: Sat, 16 Feb 2019 07:58:55 +0100 Subject: [PATCH 2/2] more docs --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 24762c9..956c98c 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,8 @@ var config = { port: 21, localRoot: __dirname + '/local-folder', remoteRoot: '/public_html/remote-folder/', - // include: ['*', '**/*'], // this would upload everything except dot files include: ['*.php', 'dist/*'], - exclude: ['dist/**/*.map'], // e.g. exclude sourcemaps - ** exclude: [] if nothing to exclude ** + exclude: ['dist/**/*.map'], deleteRemote: false, // delete ALL existing files at destination before uploading, if true forcePasv: true // Passive mode is forced (EPSV command is not sent) } @@ -57,10 +56,10 @@ ftpDeploy.deploy(config, function(err, res) { ## Configuration -You need to list all file patterns that you want to include for uploading, and the exclude option enables exceptions to the rule +The exclude / include options take lists of globs - see https://github.com/isaacs/minimatch for examples. A file is uploaded if it matches an include, and does not match any of the excludes. For example: - * `include`: all files that match will be uploaded. **Note** that a `[ ]` matches nothing - * `exclude`: if a file matches the include pattern a subset may nonetheless be excluded + - `{ include: ['*'], exclude: [] }` matches everything in the first level of directory + - `{ include: ['*', '**/*'], exclude: ['node_modules/**'] }` matches everything (escept dot files) but excludes one directory ## Events