mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +02:00
71efff6827
* Update eslint config * Applied linter to lib * Applied eslint config to CliClient/app * Removed prettier due to https://github.com/prettier/prettier/pull/4765 * First pass on test units * Applied linter config to test units * Applied eslint config to clipper * Applied to plugin dir * Applied to root of ElectronClient * Applied on RN root * Applied on CLI root * Applied on Clipper root * Applied config to tools * test hook * test hook * test hook * Added pre-commit hook * Applied rule no-trailing-spaces * Make sure root packages are installed when installing sub-dir * Added doc
50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
const { BaseCommand } = require('./base-command.js');
|
|
const InteropService = require('lib/services/InteropService.js');
|
|
const BaseModel = require('lib/BaseModel.js');
|
|
const { app } = require('./app.js');
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
class Command extends BaseCommand {
|
|
usage() {
|
|
return 'export <path>';
|
|
}
|
|
|
|
description() {
|
|
return _('Exports Joplin data to the given path. By default, it will export the complete database including notebooks, notes, tags and resources.');
|
|
}
|
|
|
|
options() {
|
|
const service = new InteropService();
|
|
const formats = service
|
|
.modules()
|
|
.filter(m => m.type === 'exporter')
|
|
.map(m => m.format + (m.description ? ' (' + m.description + ')' : ''));
|
|
|
|
return [['--format <format>', _('Destination format: %s', formats.join(', '))], ['--note <note>', _('Exports only the given note.')], ['--notebook <notebook>', _('Exports only the given notebook.')]];
|
|
}
|
|
|
|
async action(args) {
|
|
let exportOptions = {};
|
|
exportOptions.path = args.path;
|
|
|
|
exportOptions.format = args.options.format ? args.options.format : 'jex';
|
|
|
|
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);
|
|
} 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);
|
|
}
|
|
|
|
const service = new InteropService();
|
|
const result = await service.export(exportOptions);
|
|
|
|
result.warnings.map(w => this.stdout(w));
|
|
}
|
|
}
|
|
|
|
module.exports = Command;
|