1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-03 08:35:29 +02:00
joplin/CliClient/app/command-export.js

50 lines
1.8 KiB
JavaScript
Raw Normal View History

const { BaseCommand } = require('./base-command.js');
const InteropService = require('lib/services/InteropService.js');
2017-12-14 20:12:14 +02:00
const BaseModel = require('lib/BaseModel.js');
const { app } = require('./app.js');
const { _ } = require('lib/locale.js');
2017-08-20 16:29:18 +02:00
class Command extends BaseCommand {
usage() {
return 'export <path>';
2017-08-20 16:29:18 +02:00
}
description() {
return _('Exports Joplin data to the given path. By default, it will export the complete database including notebooks, notes, tags and resources.');
2017-08-20 16:29:18 +02:00
}
options() {
2018-02-27 22:04:38 +02:00
const service = new InteropService();
const formats = service
.modules()
2018-02-27 22:04:38 +02:00
.filter(m => m.type === 'exporter')
2019-09-19 23:51:18 +02:00
.map(m => m.format + (m.description ? ` (${m.description})` : ''));
2018-02-27 22:04:38 +02:00
return [['--format <format>', _('Destination format: %s', formats.join(', '))], ['--note <note>', _('Exports only the given note.')], ['--notebook <notebook>', _('Exports only the given notebook.')]];
2017-08-20 16:29:18 +02:00
}
2017-08-20 16:29:18 +02:00
async action(args) {
let exportOptions = {};
exportOptions.path = args.path;
exportOptions.format = args.options.format ? args.options.format : 'jex';
2017-08-20 16:29:18 +02:00
if (args.options.note) {
const notes = await app().loadItems(BaseModel.TYPE_NOTE, args.options.note, { parent: app().currentFolder() });
if (!notes.length) throw new Error(_('Cannot find "%s".', args.options.note));
exportOptions.sourceNoteIds = notes.map(n => n.id);
2017-08-20 16:29:18 +02:00
} else if (args.options.notebook) {
const folders = await app().loadItems(BaseModel.TYPE_FOLDER, args.options.notebook);
if (!folders.length) throw new Error(_('Cannot find "%s".', args.options.notebook));
exportOptions.sourceFolderIds = folders.map(n => n.id);
2017-08-20 16:29:18 +02:00
}
const service = new InteropService();
const result = await service.export(exportOptions);
2017-08-20 16:29:18 +02:00
result.warnings.map(w => this.stdout(w));
2017-08-20 16:29:18 +02:00
}
}
module.exports = Command;