2017-11-03 02:09:34 +02:00
|
|
|
const { BaseCommand } = require('./base-command.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const Folder = require('@joplin/lib/models/Folder.js');
|
|
|
|
const Note = require('@joplin/lib/models/Note.js');
|
|
|
|
const Tag = require('@joplin/lib/models/Tag.js');
|
2017-07-10 22:03:46 +02:00
|
|
|
|
|
|
|
class Command extends BaseCommand {
|
|
|
|
usage() {
|
|
|
|
return 'dump';
|
|
|
|
}
|
|
|
|
|
|
|
|
description() {
|
|
|
|
return 'Dumps the complete database as JSON.';
|
|
|
|
}
|
|
|
|
|
2017-07-18 20:21:03 +02:00
|
|
|
hidden() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-13 00:16:42 +02:00
|
|
|
async action() {
|
2017-07-10 22:03:46 +02:00
|
|
|
let items = [];
|
2020-03-14 01:46:14 +02:00
|
|
|
const folders = await Folder.all();
|
2017-07-10 22:03:46 +02:00
|
|
|
for (let i = 0; i < folders.length; i++) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const folder = folders[i];
|
|
|
|
const notes = await Note.previews(folder.id);
|
2017-07-10 22:03:46 +02:00
|
|
|
items.push(folder);
|
|
|
|
items = items.concat(notes);
|
|
|
|
}
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const tags = await Tag.all();
|
2017-07-10 22:03:46 +02:00
|
|
|
for (let i = 0; i < tags.length; i++) {
|
2017-07-25 20:36:52 +02:00
|
|
|
tags[i].notes_ = await Tag.noteIds(tags[i].id);
|
2017-07-10 22:03:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
items = items.concat(tags);
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2017-10-07 18:30:27 +02:00
|
|
|
this.stdout(JSON.stringify(items));
|
2017-07-10 22:03:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
module.exports = Command;
|