Skip to content

Commit 354282b

Browse files
author
Stephen Parente
committed
Gruntfile placeholder and new arg
1 parent a5b6b5a commit 354282b

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
export.csv

Gruntfile.js

Whitespace-only changes.

args.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ Arguments.prototype.last = function() {
5353
return last;
5454
}
5555

56+
Arguments.prototype.penultimate = function() {
57+
var keys = Object.keys(this.args);
58+
var key = keys.reverse()[1];
59+
60+
if (key == undefined) return undefined;
61+
62+
var arg = this.args[key];
63+
return arg;
64+
}
65+
5666
Arguments.prototype.extend = function(key, cb) {
5767
this.fn[key] = cb.bind(this);
5868
}

index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@ function fetch(url, cb, path) {
3232

3333
if (require.main === module) {
3434

35+
args.extend('filepath', function() {
36+
var path = this.penultimate();
37+
if (!path) return false;
38+
path = this.last();
39+
40+
return _.resolvePath(path);
41+
42+
});
43+
3544
args.extend('firebaseUrl', function() {
36-
return this.last();
45+
var arg = this.penultimate();
46+
if (!arg) arg = this.last();
47+
return arg;
3748
});
3849

50+
var path = args.getArgument('filepath', './export.csv');
3951
var firebaseUrl = args.getArgument('firebaseUrl', new Error('Must specify a firebase URL'));
4052

4153
colors.setTheme({
@@ -54,16 +66,17 @@ if (require.main === module) {
5466
}
5567
});
5668

69+
/*
5770
fetch(firebaseUrl, function(stream) {
5871
stream
5972
.pipe(process.stdout);
6073
6174
stream.on('end', process.exit);
62-
});
75+
});*/
6376

64-
/*fetch(firebaseUrl, function() {
77+
fetch(firebaseUrl, function() {
6578
process.exit();
66-
}, './export.csv');*/
79+
}, path);
6780

6881
}
6982

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"keywords": [
1010
"XLS"
1111
],
12+
"repository": "git@github.com:webmakersteve/firebase-to-csv.git",
1213
"author": "Stephen Parente",
1314
"license": "GPL-3.0",
1415
"dependencies": {
@@ -17,5 +18,8 @@
1718
"firebase": "^2.2.5",
1819
"lodash": "^3.9.3",
1920
"when": "^3.7.3"
21+
},
22+
"devDependencies": {
23+
"grunt": "^0.4.5"
2024
}
2125
}

tools.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('lodash');
2+
var path = require('path');
23

34
module.exports.$toArray = function(obj) {
45
var records = [];
@@ -43,4 +44,10 @@ module.exports.prepareCSV = function(obj) {
4344

4445
return data;
4546

46-
};
47+
};
48+
49+
module.exports.resolvePath = function(string) {
50+
if (string.substr(0,1) === '~')
51+
string = process.env.HOME + string.substr(1)
52+
return path.resolve(string)
53+
}

0 commit comments

Comments
 (0)