]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - cli/actions.js
Add missing callback in upload
[perso/Immae/Projets/Nodejs/Surfer.git] / cli / actions.js
index 954ca6b36e27a7556dda9ed18ac6ea031402694f..ab982a7a14418d6ea977ae5f84d1ddba6b6ec889 100644 (file)
@@ -31,17 +31,20 @@ function checkConfig() {
     console.error('Using server %s', config.server().yellow);
 }
 
-function collectFiles(filesOrFolders) {
+function collectFiles(filesOrFolders, options) {
     var tmp = [];
 
     filesOrFolders.forEach(function (filePath) {
+        var baseName = path.basename(filePath);
+        if (!options.all && baseName[0] === '.' && baseName.length > 1) return;
+
         var stat = fs.statSync(filePath);
 
         if (stat.isFile()) {
             tmp.push(filePath);
         } else if (stat.isDirectory()) {
             var files = fs.readdirSync(filePath).map(function (file) { return path.join(filePath, file); });
-            tmp = tmp.concat(collectFiles(files));
+            tmp = tmp.concat(collectFiles(files, options));
         } else {
             console.log('Skipping %s', filePath.cyan);
         }
@@ -90,13 +93,14 @@ function login(uri) {
 function put(filePath, otherFilePaths, options) {
     checkConfig();
 
-    var files = collectFiles([ filePath ].concat(otherFilePaths));
+    var files = collectFiles([ filePath ].concat(otherFilePaths), options);
 
     async.eachSeries(files, function (file, callback) {
         var relativeFilePath;
+
         if (path.isAbsolute(file)) {
             relativeFilePath = path.basename(file);
-        } else if (path.resolve(file).indexOf(process.cwd().length) === 0) { // relative to current dir
+        } else if (path.resolve(file).indexOf(process.cwd()) === 0) { // relative to current dir
             relativeFilePath = path.resolve(file).slice(process.cwd().length + 1);
         } else { // relative but somewhere else
             relativeFilePath = path.basename(file);
@@ -110,6 +114,8 @@ function put(filePath, otherFilePaths, options) {
             if (result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode));
 
             console.log('Uploaded to ' + config.server() + destinationPath);
+
+            callback(null);
         });
     }, function (error) {
         if (error) {