1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00
joplin/packages/app-cli/app/command-dump.ts

42 lines
1010 B
TypeScript
Raw Normal View History

import BaseCommand from './base-command';
import Folder from '@joplin/lib/models/Folder';
import Note from '@joplin/lib/models/Note';
import Tag from '@joplin/lib/models/Tag';
import { FolderEntity, NoteEntity } from '@joplin/lib/services/database/types';
2017-07-10 22:03:46 +02:00
class Command extends BaseCommand {
public override usage() {
2017-07-10 22:03:46 +02:00
return 'dump';
}
public override description() {
2017-07-10 22:03:46 +02:00
return 'Dumps the complete database as JSON.';
}
public override hidden() {
2017-07-18 20:21:03 +02:00
return true;
}
public override async action() {
let items: (NoteEntity | FolderEntity)[] = [];
const folders = await Folder.all();
2017-07-10 22:03:46 +02:00
for (let i = 0; i < folders.length; i++) {
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);
}
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);
2017-10-07 18:30:27 +02:00
this.stdout(JSON.stringify(items));
2017-07-10 22:03:46 +02:00
}
}
module.exports = Command;