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);
}
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 = path.resolve(file).slice(process.cwd().length + 1);
+ var relativeFilePath;
+
+ if (path.isAbsolute(file)) {
+ relativeFilePath = path.basename(file);
+ } 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);
+ }
+
var destinationPath = (options.destination ? '/' + options.destination : '') + '/' + relativeFilePath;
console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan);
console.log('\t %s', entry);
});
} else {
- console.log(body);
+ process.stdout.write(body);
}
});
// var req = superagent.get(config.server() + API + filePath);