-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 1002 Bytes
/
index.js
File metadata and controls
40 lines (32 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var Hackpad = require("hackpad");
var fs = require("fs");
var argv = require("optimist")
.usage("Exports hackpad documents")
.options("c", {
alias: "client_id",
describe: "The hackpad client ID"
})
.options("s", {
alias: "secret",
describe: "The hackpad secret"
})
.options("f", {
alias: "format",
describe: "The format to export the hackpad in (either 'html', 'md' or 'txt' - defaults to 'html')"
})
.demand("c", "s")
.argv;
if(argv.format && !(argv.format in { html: true, md: true, txt: true })) {
throw new Error("Format must be 'html', 'md' or 'txt'");
}
var client = new Hackpad(argv.client_id, argv.secret);
var format = argv.format || "html";
argv._.forEach(function(padId) {
client.export(padId, null, format, function(error, response) {
if(error) {
console.error(error);
} else {
fs.writeFileSync(padId + "." + format, response);
}
});
});