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);
+
+ superagent.put(config.server() + API + destinationPath).query(gQuery).attach('file', file).end(function (error, result) {
+ if (error) return callback(error);
+ if (result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode));
- console.log('Uploading file %s -> %s', relativeFilePath.cyan, ((options.destination ? options.destination : '') + '/' + relativeFilePath).cyan);
+ console.log('Uploaded to ' + config.server() + destinationPath);
- superagent.put(config.server() + API + relativeFilePath).query(gQuery).attach('file', file).end(callback);
+ callback(null);
+ });
}, function (error) {
if (error) {
console.log('Failed to put file.', error);
console.log('\t %s', entry);
});
} else {
- console.log(body);
+ process.stdout.write(body);
}
});
// var req = superagent.get(config.server() + API + filePath);