-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (44 loc) · 1.42 KB
/
app.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const CSON = require('cson');
const sanitize = require('sanitize-filename');
const fs = require('fs');
const path = require('path');
const R = require('ramda');
const mkdirSync = function(dirPath) {
try {
fs.mkdirSync(dirPath);
} catch (err) {
if (err.code !== 'EEXIST') throw err;
}
};
const notesDir = '~/Boostnote';
const outDir = '~/Boostnote/notes/out';
mkdirSync(outDir);
fs.readFile(path.join(notesDir, 'boostnote.json'), function(err, indexFile) {
const index = JSON.parse(indexFile);
fs.readdir(path.join(notesDir, 'notes'), function(err2, files) {
if (err) {
console.error('Could not list the directory.', err);
process.exit(1);
}
files.forEach(function(file) {
if (!fs.statSync(path.join(notesDir, 'notes', file)).isDirectory()) {
const note = CSON.load(path.join(notesDir, 'notes', file));
let filename = sanitize(note.title) + '.md';
if (note.folder) {
const folder = R.find(R.propEq('key', note.folder))(index.folders);
if (folder) {
filename = path.join(folder.name, filename);
mkdirSync(path.join(outDir, folder.name));
}
}
filename = path.join(outDir, filename);
fs.writeFile(filename, note.content, function(err) {
if (err) {
return console.log(err);
}
console.log(`Exported ${filename}`);
});
}
});
});
});