aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@nebulon.de>2015-06-27 17:28:23 +0200
committerJohannes Zellner <johannes@nebulon.de>2015-06-27 17:28:23 +0200
commiteb83e4daa3726d3e7f12c513a19d212b709dadff (patch)
tree00b2b5c41cffbe738d23cc2a026fa62a97358d90
parent8c3ae0719e1f7d266ee04d86e7e1c3756745d372 (diff)
downloadSurfer-eb83e4daa3726d3e7f12c513a19d212b709dadff.tar.gz
Surfer-eb83e4daa3726d3e7f12c513a19d212b709dadff.tar.zst
Surfer-eb83e4daa3726d3e7f12c513a19d212b709dadff.zip
Use del instead of rimraf
-rw-r--r--cli/actions.js5
-rwxr-xr-xcli/surfer.js1
-rw-r--r--package.json2
-rw-r--r--src/files.js6
4 files changed, 8 insertions, 6 deletions
diff --git a/cli/actions.js b/cli/actions.js
index 592d809..00ffb6f 100644
--- a/cli/actions.js
+++ b/cli/actions.js
@@ -46,7 +46,7 @@ function login(server) {
46 config.set('server', server); 46 config.set('server', server);
47} 47}
48 48
49function put(filePath, otherFilePaths) { 49function put(filePath, otherFilePaths, options) {
50 checkConfig(); 50 checkConfig();
51 51
52 var files = collectFiles([ filePath ].concat(otherFilePaths)); 52 var files = collectFiles([ filePath ].concat(otherFilePaths));
@@ -54,7 +54,7 @@ function put(filePath, otherFilePaths) {
54 async.eachSeries(files, function (file, callback) { 54 async.eachSeries(files, function (file, callback) {
55 var relativeFilePath = path.resolve(file).slice(process.cwd().length + 1); 55 var relativeFilePath = path.resolve(file).slice(process.cwd().length + 1);
56 56
57 console.log('Uploading file %s', relativeFilePath.cyan); 57 console.log('Uploading file %s -> %s', relativeFilePath.cyan, ((options.destination ? options.destination : '') + '/' + relativeFilePath).cyan);
58 58
59 superagent.put(config.server() + API + relativeFilePath).attach('file', file).end(callback); 59 superagent.put(config.server() + API + relativeFilePath).attach('file', file).end(callback);
60 }, function (error) { 60 }, function (error) {
@@ -90,6 +90,7 @@ function del(filePath) {
90 90
91 var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); 91 var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1);
92 superagent.del(config.server() + API + relativeFilePath).end(function (error, result) { 92 superagent.del(config.server() + API + relativeFilePath).end(function (error, result) {
93 if (error.status === 404) return console.log('No such file or directory');
93 if (error) return console.log('Failed', result ? result.body : error); 94 if (error) return console.log('Failed', result ? result.body : error);
94 console.log('Success', result.body); 95 console.log('Success', result.body);
95 }); 96 });
diff --git a/cli/surfer.js b/cli/surfer.js
index d906d62..fbc95b6 100755
--- a/cli/surfer.js
+++ b/cli/surfer.js
@@ -15,6 +15,7 @@ program.command('login')
15 .action(actions.login); 15 .action(actions.login);
16 16
17program.command('put <file> [files...]') 17program.command('put <file> [files...]')
18 .option('-d --destination <folder>', 'Destination folder. This is prepended to the relative <file> path')
18 .description('Put a file') 19 .description('Put a file')
19 .action(actions.put); 20 .action(actions.put);
20 21
diff --git a/package.json b/package.json
index 5e97c28..01e9eff 100644
--- a/package.json
+++ b/package.json
@@ -24,12 +24,12 @@
24 "connect-lastmile": "0.0.10", 24 "connect-lastmile": "0.0.10",
25 "connect-timeout": "^1.6.2", 25 "connect-timeout": "^1.6.2",
26 "debug": "^2.2.0", 26 "debug": "^2.2.0",
27 "del": "^1.2.0",
27 "ejs": "^2.3.1", 28 "ejs": "^2.3.1",
28 "express": "^4.12.4", 29 "express": "^4.12.4",
29 "mkdirp": "^0.5.1", 30 "mkdirp": "^0.5.1",
30 "morgan": "^1.6.0", 31 "morgan": "^1.6.0",
31 "multiparty": "^4.1.2", 32 "multiparty": "^4.1.2",
32 "rimraf": "^2.4.0",
33 "safetydance": "0.0.16", 33 "safetydance": "0.0.16",
34 "superagent": "^1.2.0", 34 "superagent": "^1.2.0",
35 "underscore": "^1.8.3" 35 "underscore": "^1.8.3"
diff --git a/src/files.js b/src/files.js
index 48f91a8..6946ff3 100644
--- a/src/files.js
+++ b/src/files.js
@@ -3,7 +3,7 @@
3var fs = require('fs'), 3var fs = require('fs'),
4 path = require('path'), 4 path = require('path'),
5 ejs = require('ejs'), 5 ejs = require('ejs'),
6 rimraf = require('rimraf'), 6 rm = require('del'),
7 debug = require('debug')('files'), 7 debug = require('debug')('files'),
8 mkdirp = require('mkdirp'), 8 mkdirp = require('mkdirp'),
9 HttpError = require('connect-lastmile').HttpError, 9 HttpError = require('connect-lastmile').HttpError,
@@ -116,9 +116,9 @@ function del(req, res, next) {
116 fs.stat(absoluteFilePath, function (error, result) { 116 fs.stat(absoluteFilePath, function (error, result) {
117 if (error) return next(new HttpError(404, error)); 117 if (error) return next(new HttpError(404, error));
118 118
119 rimraf(absoluteFilePath, function (error) { 119 rm(absoluteFilePath, function (error, result) {
120 if (error) return next(new HttpError(500, 'Unable to remove')); 120 if (error) return next(new HttpError(500, 'Unable to remove'));
121 next(new HttpSuccess(200, {})); 121 next(new HttpSuccess(200, { entries: result }));
122 }); 122 });
123 }); 123 });
124} 124}