2017-07-10 22:03:46 +02:00
|
|
|
import { BaseCommand } from './base-command.js';
|
|
|
|
import { app } from './app.js';
|
|
|
|
import { _ } from 'lib/locale.js';
|
|
|
|
import { Folder } from 'lib/models/folder.js';
|
|
|
|
import { Note } from 'lib/models/note.js';
|
|
|
|
import { Tag } from 'lib/models/tag.js';
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-07-10 22:03:46 +02:00
|
|
|
async action(args) {
|
|
|
|
let items = [];
|
|
|
|
let folders = await Folder.all();
|
|
|
|
for (let i = 0; i < folders.length; i++) {
|
|
|
|
let folder = folders[i];
|
|
|
|
let notes = await Note.previews(folder.id);
|
|
|
|
items.push(folder);
|
|
|
|
items = items.concat(notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
let tags = await Tag.all();
|
|
|
|
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);
|
|
|
|
|
2017-10-07 18:30:27 +02:00
|
|
|
this.stdout(JSON.stringify(items));
|
2017-07-10 22:03:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Command;
|