diff --git a/.gitignore b/.gitignore index 2a4123e..ab1bfea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ ignore .vscode test/remote +!test/test2/node_modules playground .DS_Store diff --git a/README.md b/README.md index c195e00..55af9b5 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ npm install --save-dev ftp-deploy ## Usage The most basic usage: + ```js var FtpDeploy = require("ftp-deploy"); var ftpDeploy = new FtpDeploy(); @@ -28,7 +29,12 @@ var config = { // include: ["*", "**/*"], // this would upload everything except dot files include: ["*.php", "dist/*", ".*"], // e.g. exclude sourcemaps, and ALL files in node_modules (including dot files) - exclude: ["dist/**/*.map", "node_modules/**", "node_modules/**/.*", ".git/**"], + exclude: [ + "dist/**/*.map", + "node_modules/**", + "node_modules/**/.*", + ".git/**" + ], // delete ALL existing files at destination before uploading, if true deleteRemote: false, // Passive mode is forced (EPSV command is not sent) @@ -48,10 +54,11 @@ ftpDeploy.deploy(config, function(err, res) { }); ``` -**Note:** - - in version 2 the config file expects a field of `user` rather than `username` in 1.x. - - The config file is passed as-is to Promise-FTP. - - I create a file - e.g. deploy.js - in the root of my source code and add a script to its `package.json` so that I can `npm run deploy`. +**Note:** + +- in version 2 the config file expects a field of `user` rather than `username` in 1.x. +- The config file is passed as-is to Promise-FTP. +- I create a file - e.g. deploy.js - in the root of my source code and add a script to its `package.json` so that I can `npm run deploy`. ```json "scripts": { @@ -68,7 +75,7 @@ These are lists of [minimatch globs](https://github.com/isaacs/minimatch). ftp-d ## Events -ftp-deploy reports to clients using events. To get the output you need to implement watchers for "uploading", "uploaded" and "log": +ftp-deploy reports to clients using events. To get the output you need to implement watchers for "uploading", "uploaded" and "log": ```js ftpDeploy.on("uploading", function(data) { @@ -105,6 +112,5 @@ npm test ## ToDo - - re-enable continueOnError - - update newer files only (PR welcome) - +- re-enable continueOnError +- update newer files only (PR welcome) diff --git a/src/lib.js b/src/lib.js index 8d66eb1..96ffa09 100644 --- a/src/lib.js +++ b/src/lib.js @@ -43,19 +43,21 @@ function getPassword(config) { } } -// Analysing local firstory - +// Analysing local directory function canIncludePath(includes, excludes, filePath) { - let go = (acc, item) => - acc || minimatch(filePath, item, { matchBase: true }); + const options = { matchBase: true }; + let go = (acc, item) => 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 +135,7 @@ mkDirExists = (ftp, dir) => { // Make the directory using recursive expand 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 e8446ec..cfab3f9 100644 --- a/src/lib.spec.js +++ b/src/lib.spec.js @@ -100,6 +100,11 @@ describe("dirParseSync", () => { 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