1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-08 13:06:15 +02:00

Chore: Cli: Migrate most commands to TypeScript (#9552)

This commit is contained in:
Henry Heino 2023-12-20 11:08:07 -08:00 committed by GitHub
parent ddebeb68b2
commit 4ec2fb216e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 252 additions and 199 deletions

View File

@ -87,13 +87,35 @@ packages/lib/countable/Countable.js
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
packages/app-cli/app/LinkSelector.js
packages/app-cli/app/base-command.js
packages/app-cli/app/command-apidoc.js
packages/app-cli/app/command-attach.js
packages/app-cli/app/command-cat.js
packages/app-cli/app/command-config.js
packages/app-cli/app/command-cp.js
packages/app-cli/app/command-done.test.js
packages/app-cli/app/command-done.js
packages/app-cli/app/command-dump.js
packages/app-cli/app/command-e2ee.js
packages/app-cli/app/command-edit.js
packages/app-cli/app/command-exit.js
packages/app-cli/app/command-export-sync-status.js
packages/app-cli/app/command-export.js
packages/app-cli/app/command-geoloc.js
packages/app-cli/app/command-help.js
packages/app-cli/app/command-import.js
packages/app-cli/app/command-ls.js
packages/app-cli/app/command-mkbook.test.js
packages/app-cli/app/command-mkbook.js
packages/app-cli/app/command-mv.js
packages/app-cli/app/command-ren.js
packages/app-cli/app/command-rmbook.js
packages/app-cli/app/command-rmnote.js
packages/app-cli/app/command-set.js
packages/app-cli/app/command-settingschema.js
packages/app-cli/app/command-sync.js
packages/app-cli/app/command-testing.js
packages/app-cli/app/command-use.js
packages/app-cli/app/command-version.js
packages/app-cli/app/gui/StatusBarWidget.js
packages/app-cli/app/services/plugins/PluginRunner.js
packages/app-cli/app/setupCommand.js

22
.gitignore vendored
View File

@ -67,13 +67,35 @@ docs/**/*.mustache
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
packages/app-cli/app/LinkSelector.js
packages/app-cli/app/base-command.js
packages/app-cli/app/command-apidoc.js
packages/app-cli/app/command-attach.js
packages/app-cli/app/command-cat.js
packages/app-cli/app/command-config.js
packages/app-cli/app/command-cp.js
packages/app-cli/app/command-done.test.js
packages/app-cli/app/command-done.js
packages/app-cli/app/command-dump.js
packages/app-cli/app/command-e2ee.js
packages/app-cli/app/command-edit.js
packages/app-cli/app/command-exit.js
packages/app-cli/app/command-export-sync-status.js
packages/app-cli/app/command-export.js
packages/app-cli/app/command-geoloc.js
packages/app-cli/app/command-help.js
packages/app-cli/app/command-import.js
packages/app-cli/app/command-ls.js
packages/app-cli/app/command-mkbook.test.js
packages/app-cli/app/command-mkbook.js
packages/app-cli/app/command-mv.js
packages/app-cli/app/command-ren.js
packages/app-cli/app/command-rmbook.js
packages/app-cli/app/command-rmnote.js
packages/app-cli/app/command-set.js
packages/app-cli/app/command-settingschema.js
packages/app-cli/app/command-sync.js
packages/app-cli/app/command-testing.js
packages/app-cli/app/command-use.js
packages/app-cli/app/command-version.js
packages/app-cli/app/gui/StatusBarWidget.js
packages/app-cli/app/services/plugins/PluginRunner.js
packages/app-cli/app/setupCommand.js

View File

@ -1,33 +1,34 @@
const BaseCommand = require('./base-command').default;
const BaseItem = require('@joplin/lib/models/BaseItem').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
import BaseCommand from './base-command';
import BaseItem from '@joplin/lib/models/BaseItem';
import BaseModel from '@joplin/lib/BaseModel';
const { toTitleCase } = require('@joplin/lib/string-utils.js');
const { reg } = require('@joplin/lib/registry.js');
const markdownUtils = require('@joplin/lib/markdownUtils').default;
const Database = require('@joplin/lib/database').default;
const shim = require('@joplin/lib/shim').default;
import { reg } from '@joplin/lib/registry.js';
import markdownUtils, { MarkdownTableRow } from '@joplin/lib/markdownUtils';
import Database from '@joplin/lib/database';
import shim from '@joplin/lib/shim';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'apidoc <file>';
}
description() {
public override description() {
return 'Build the API doc';
}
enabled() {
public override enabled() {
return false;
}
createPropertiesTable(tableFields) {
private createPropertiesTable(tableFields: MarkdownTableRow[]) {
const headers = [
{ name: 'name', label: 'Name' },
{
name: 'type',
label: 'Type',
filter: value => {
return Database.enumName('fieldType', value);
filter: (value: string|number) => {
const valueAsNumber = typeof value === 'number' ? value : parseInt(value, 10);
return Database.enumName('fieldType', valueAsNumber);
},
},
{ name: 'description', label: 'Description' },
@ -36,7 +37,7 @@ class Command extends BaseCommand {
return markdownUtils.createMarkdownTable(headers, tableFields);
}
async action(args) {
public override async action(args: any) {
const models = [
{
type: BaseModel.TYPE_NOTE,

View File

@ -1,19 +1,19 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const shim = require('@joplin/lib/shim').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import shim from '@joplin/lib/shim';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'attach <note> <file>';
}
description() {
public override description() {
return _('Attaches the given file to the note.');
}
async action(args) {
public override async action(args: any) {
const title = args['note'];
const note = await app().loadItem(BaseModel.TYPE_NOTE, title, { parent: app().currentFolder() });

View File

@ -1,24 +1,24 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const BaseItem = require('@joplin/lib/models/BaseItem').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import BaseItem from '@joplin/lib/models/BaseItem';
import Note from '@joplin/lib/models/Note';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'cat <note>';
}
description() {
public override description() {
return _('Displays the given note.');
}
options() {
public override options() {
return [['-v, --verbose', _('Displays the complete information about note.')]];
}
async action(args) {
public override async action(args: any) {
const title = args['note'];
const item = await app().loadItem(BaseModel.TYPE_NOTE, title, { parent: app().currentFolder() });

View File

@ -1,19 +1,20 @@
const BaseCommand = require('./base-command').default;
const { _, setLocale } = require('@joplin/lib/locale');
import BaseCommand from './base-command';
import { _, setLocale } from '@joplin/lib/locale';
const { app } = require('./app.js');
const fs = require('fs-extra');
const Setting = require('@joplin/lib/models/Setting').default;
import * as fs from 'fs-extra';
import Setting, { AppType } from '@joplin/lib/models/Setting';
import { ReadStream } from 'tty';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'config [name] [value]';
}
description() {
public override description() {
return _('Gets or sets a config value. If [value] is not provided, it will show the value of [name]. If neither [name] nor [value] is provided, it will list the current configuration.');
}
options() {
public override options() {
return [
['-v, --verbose', _('Also displays unset and hidden config variables.')],
['--export', 'Writes all settings to STDOUT as JSON including secure variables.'],
@ -21,11 +22,12 @@ class Command extends BaseCommand {
['--import-file <file>', 'Reads in settings from <file>. <file> must contain valid JSON.'],
];
}
async __importSettings(inputStream) {
return new Promise((resolve, reject) => {
private async __importSettings(inputStream: ReadStream|fs.ReadStream) {
return new Promise<void>((resolve, reject) => {
// being defensive and not attempting to settle twice
let isSettled = false;
const chunks = [];
const chunks: any = [];
inputStream.on('readable', () => {
let chunk;
@ -64,13 +66,14 @@ class Command extends BaseCommand {
});
});
}
async action(args) {
public override async action(args: any) {
const verbose = args.options.verbose;
const isExport = args.options.export;
const isImport = args.options.import || args.options.importFile;
const importFile = args.options.importFile;
const renderKeyValue = name => {
const renderKeyValue = (name: string) => {
const md = Setting.settingMetadata(name);
let value = Setting.value(name);
if (typeof value === 'object' || Array.isArray(value)) value = JSON.stringify(value);
@ -84,11 +87,11 @@ class Command extends BaseCommand {
};
if (isExport || (!isImport && !args.value)) {
const keys = Setting.keys(!verbose, 'cli');
const keys = Setting.keys(!verbose, AppType.Cli);
keys.sort();
if (isExport) {
const resultObj = keys.reduce((acc, key) => {
const resultObj = keys.reduce<Record<string, any>>((acc, key) => {
const value = Setting.value(key);
if (!verbose && !value) return acc;
acc[key] = value;
@ -113,7 +116,7 @@ class Command extends BaseCommand {
}
if (isImport) {
let fileStream = process.stdin;
let fileStream: ReadStream|fs.ReadStream = process.stdin;
if (importFile) {
fileStream = fs.createReadStream(importFile, { autoClose: true });
}

View File

@ -1,19 +1,19 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Note from '@joplin/lib/models/Note';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'cp <note> [notebook]';
}
description() {
public override description() {
return _('Duplicates the notes matching <note> to [notebook]. If no notebook is specified the note is duplicated in the current notebook.');
}
async action(args) {
public override async action(args: any) {
let folder = null;
if (args['notebook']) {
folder = await app().loadItem(BaseModel.TYPE_FOLDER, args['notebook']);
@ -28,7 +28,7 @@ class Command extends BaseCommand {
for (let i = 0; i < notes.length; i++) {
const newNote = await Note.copyToFolder(notes[i].id, folder.id);
Note.updateGeolocation(newNote.id);
void Note.updateGeolocation(newNote.id);
}
}
}

View File

@ -1,20 +1,20 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Note = require('@joplin/lib/models/Note').default;
const time = require('@joplin/lib/time').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Note from '@joplin/lib/models/Note';
import time from '@joplin/lib/time';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'done <note>';
}
description() {
public override description() {
return _('Marks a to-do as done.');
}
static async handleAction(commandInstance, args, isCompleted) {
public static async handleAction(commandInstance: BaseCommand, args: any, isCompleted: boolean) {
const note = await app().loadItem(BaseModel.TYPE_NOTE, args.note);
commandInstance.encryptionCheck(note);
if (!note) throw new Error(_('Cannot find "%s".', args.note));
@ -30,7 +30,7 @@ class Command extends BaseCommand {
});
}
async action(args) {
public override async action(args: any) {
await Command.handleAction(this, args, true);
}
}

View File

@ -1,22 +1,22 @@
const BaseCommand = require('./base-command').default;
const Folder = require('@joplin/lib/models/Folder').default;
const Note = require('@joplin/lib/models/Note').default;
const Tag = require('@joplin/lib/models/Tag').default;
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';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'dump';
}
description() {
public override description() {
return 'Dumps the complete database as JSON.';
}
hidden() {
public override hidden() {
return true;
}
async action() {
public override async action() {
let items = [];
const folders = await Folder.all();
for (let i = 0; i < folders.length; i++) {

View File

@ -1,24 +1,24 @@
const fs = require('fs-extra');
const BaseCommand = require('./base-command').default;
const { splitCommandString } = require('@joplin/utils');
const uuid = require('@joplin/lib/uuid').default;
import * as fs from 'fs-extra';
import BaseCommand from './base-command';
import { splitCommandString } from '@joplin/utils';
import uuid from '@joplin/lib/uuid';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const Note = require('@joplin/lib/models/Note').default;
const Setting = require('@joplin/lib/models/Setting').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
import { _ } from '@joplin/lib/locale';
import Note from '@joplin/lib/models/Note';
import Setting from '@joplin/lib/models/Setting';
import BaseModel from '@joplin/lib/BaseModel';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'edit <note>';
}
description() {
public override description() {
return _('Edit note.');
}
async action(args) {
let tempFilePath = null;
public override async action(args: any) {
let tempFilePath: string|null = null;
const onFinishedEditing = async () => {
if (tempFilePath) fs.removeSync(tempFilePath);

View File

@ -1,21 +1,21 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
import { _ } from '@joplin/lib/locale';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'exit';
}
description() {
public override description() {
return _('Exits the application.');
}
compatibleUis() {
public override compatibleUis() {
return ['gui'];
}
async action() {
public override async action() {
await app().exit();
}
}

View File

@ -1,25 +1,25 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const Setting = require('@joplin/lib/models/Setting').default;
const ReportService = require('@joplin/lib/services/ReportService').default;
const fs = require('fs-extra');
import Setting from '@joplin/lib/models/Setting';
import ReportService from '@joplin/lib/services/ReportService';
import * as fs from 'fs-extra';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'export-sync-status';
}
description() {
public override description() {
return 'Export sync status';
}
hidden() {
public override hidden() {
return true;
}
async action() {
public override async action() {
const service = new ReportService();
const csv = await service.basicItemList({ format: 'csv' });
const csv = await service.basicItemList({ format: 'csv' }) as string;
const filePath = `${Setting.value('profileDir')}/syncReport-${new Date().getTime()}.csv`;
await fs.writeFileSync(filePath, csv);
this.stdout(`Sync status exported to ${filePath}`);

View File

@ -1,19 +1,20 @@
const BaseCommand = require('./base-command').default;
const InteropService = require('@joplin/lib/services/interop/InteropService').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
import BaseCommand from './base-command';
import InteropService from '@joplin/lib/services/interop/InteropService';
import BaseModel from '@joplin/lib/BaseModel';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
import { _ } from '@joplin/lib/locale';
import { ExportOptions } from '@joplin/lib/services/interop/types';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'export <path>';
}
description() {
public override description() {
return _('Exports Joplin data to the given path. By default, it will export the complete database including notebooks, notes, tags and resources.');
}
options() {
public override options() {
const service = InteropService.instance();
const formats = service
.modules()
@ -23,8 +24,8 @@ class Command extends BaseCommand {
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) {
const exportOptions = {};
public override async action(args: any) {
const exportOptions: ExportOptions = {};
exportOptions.path = args.path;
exportOptions.format = args.options.format ? args.options.format : 'jex';
@ -34,11 +35,11 @@ class Command extends BaseCommand {
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);
exportOptions.sourceNoteIds = notes.map((n: any) => 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);
exportOptions.sourceFolderIds = folders.map((n: any) => n.id);
}
const service = InteropService.instance();

View File

@ -1,19 +1,19 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Note from '@joplin/lib/models/Note';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'geoloc <note>';
}
description() {
public override description() {
return _('Displays a geolocation URL for the note.');
}
async action(args) {
public override async action(args: any) {
const title = args['note'];
const item = await app().loadItem(BaseModel.TYPE_NOTE, title, { parent: app().currentFolder() });

View File

@ -1,19 +1,19 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { renderCommandHelp } = require('./help-utils.js');
const { _ } = require('@joplin/lib/locale');
import { _ } from '@joplin/lib/locale';
const { cliUtils } = require('./cli-utils.js');
class Command extends BaseCommand {
usage() {
public override usage() {
return 'help [command]';
}
description() {
public override description() {
return _('Displays usage information.');
}
allCommands() {
private allCommands() {
const commands = app().commands(app().uiType());
const output = [];
for (const n in commands) {
@ -29,7 +29,7 @@ class Command extends BaseCommand {
return output;
}
async action(args) {
public override async action(args: any) {
const stdoutWidth = app().commandStdoutMaxWidth();
if (args.command === 'shortcuts' || args.command === 'keymap') {
@ -52,7 +52,7 @@ class Command extends BaseCommand {
for (let i = 0; i < keymap.length; i++) {
const item = keymap[i];
const keys = item.keys.map(k => (k === ' ' ? '(SPACE)' : k));
const keys = item.keys.map((k: string) => (k === ' ' ? '(SPACE)' : k));
rows.push([keys.join(', '), item.command]);
}

View File

@ -1,20 +1,21 @@
const BaseCommand = require('./base-command').default;
const InteropService = require('@joplin/lib/services/interop/InteropService').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
import BaseCommand from './base-command';
import InteropService from '@joplin/lib/services/interop/InteropService';
import BaseModel from '@joplin/lib/BaseModel';
const { cliUtils } = require('./cli-utils.js');
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
import { _ } from '@joplin/lib/locale';
import { ImportOptions } from '@joplin/lib/services/interop/types';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'import <path> [notebook]';
}
description() {
public override description() {
return _('Imports data into Joplin.');
}
options() {
public override options() {
const service = InteropService.instance();
const formats = service
.modules()
@ -28,12 +29,12 @@ class Command extends BaseCommand {
];
}
async action(args) {
public override async action(args: any) {
const folder = await app().loadItem(BaseModel.TYPE_FOLDER, args.notebook);
if (args.notebook && !folder) throw new Error(_('Cannot find "%s".', args.notebook));
const importOptions = {};
const importOptions: ImportOptions = {};
importOptions.path = args.path;
importOptions.format = args.options.format ? args.options.format : 'auto';
importOptions.destinationFolderId = folder ? folder.id : null;

View File

@ -1,28 +1,28 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Folder = require('@joplin/lib/models/Folder').default;
const Setting = require('@joplin/lib/models/Setting').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Folder from '@joplin/lib/models/Folder';
import Setting from '@joplin/lib/models/Setting';
import Note from '@joplin/lib/models/Note';
const { sprintf } = require('sprintf-js');
const time = require('@joplin/lib/time').default;
import time from '@joplin/lib/time';
const { cliUtils } = require('./cli-utils.js');
class Command extends BaseCommand {
usage() {
public override usage() {
return 'ls [note-pattern]';
}
description() {
public override description() {
return _('Displays the notes in the current notebook. Use `ls /` to display the list of notebooks.');
}
enabled() {
public override enabled() {
return true;
}
options() {
public override options() {
return [
['-n, --limit <num>', _('Displays only the first top <num> notes.')],
['-s, --sort <field>', _('Sorts the item by <field> (eg. title, updated_time, created_time).')],
@ -33,12 +33,12 @@ class Command extends BaseCommand {
];
}
async action(args) {
public override async action(args: any) {
const pattern = args['note-pattern'];
let items = [];
const options = args.options;
const queryOptions = {};
const queryOptions: any = {};
if (options.limit) queryOptions.limit = options.limit;
if (options.sort) {
queryOptions.orderBy = options.sort;

View File

@ -1,20 +1,20 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Folder = require('@joplin/lib/models/Folder').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Folder from '@joplin/lib/models/Folder';
import Note from '@joplin/lib/models/Note';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'mv <item> [notebook]';
}
description() {
public override description() {
return _('Moves the given <item> to [notebook]');
}
async action(args) {
public override async action(args: any) {
const pattern = args['item'];
const destination = args['notebook'];
let folder = null;

View File

@ -1,20 +1,20 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Folder = require('@joplin/lib/models/Folder').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Folder from '@joplin/lib/models/Folder';
import Note from '@joplin/lib/models/Note';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'ren <item> <name>';
}
description() {
public override description() {
return _('Renames the given <item> (note or notebook) to <name>.');
}
async action(args) {
public override async action(args: any) {
const pattern = args['item'];
const name = args['name'];

View File

@ -1,23 +1,23 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const Folder = require('@joplin/lib/models/Folder').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
import { _ } from '@joplin/lib/locale';
import Folder from '@joplin/lib/models/Folder';
import BaseModel from '@joplin/lib/BaseModel';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'rmbook <notebook>';
}
description() {
public override description() {
return _('Deletes the given notebook.');
}
options() {
public override options() {
return [['-f, --force', _('Deletes the notebook without asking for confirmation.')]];
}
async action(args) {
public override async action(args: any) {
const pattern = args['notebook'];
const force = args.options && args.options.force === true;

View File

@ -1,23 +1,23 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const Note = require('@joplin/lib/models/Note').default;
const BaseModel = require('@joplin/lib/BaseModel').default;
import { _ } from '@joplin/lib/locale';
import Note from '@joplin/lib/models/Note';
import BaseModel from '@joplin/lib/BaseModel';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'rmnote <note-pattern>';
}
description() {
public override description() {
return _('Deletes the notes matching <note-pattern>.');
}
options() {
public override options() {
return [['-f, --force', _('Deletes the notes without asking for confirmation.')]];
}
async action(args) {
public override async action(args: any) {
const pattern = args['note-pattern'];
const force = args.options && args.options.force === true;
@ -26,7 +26,7 @@ class Command extends BaseCommand {
const ok = force ? true : await this.prompt(notes.length > 1 ? _('%d notes match this pattern. Delete them?', notes.length) : _('Delete note?'), { booleanAnswerDefault: 'n' });
if (!ok) return;
const ids = notes.map(n => n.id);
const ids = notes.map((n: any) => n.id);
await Note.batchDelete(ids);
}
}

View File

@ -1,16 +1,16 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
const Database = require('@joplin/lib/database').default;
const Note = require('@joplin/lib/models/Note').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
import Database from '@joplin/lib/database';
import Note from '@joplin/lib/models/Note';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'set <note> <name> [value]';
}
description() {
public override description() {
const fields = Note.fields();
const s = [];
for (let i = 0; i < fields.length; i++) {
@ -22,7 +22,7 @@ class Command extends BaseCommand {
return _('Sets the property <name> of the given <note> to the given [value]. Possible properties are:\n\n%s', s.join(', '));
}
async action(args) {
public override async action(args: any) {
const title = args['note'];
const propName = args['name'];
let propValue = args['value'];
@ -36,7 +36,7 @@ class Command extends BaseCommand {
const timestamp = Date.now();
const newNote = {
const newNote: any = {
id: notes[i].id,
type_: notes[i].type_,
updated_time: timestamp,

View File

@ -1,22 +1,22 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { app } = require('./app.js');
const { _ } = require('@joplin/lib/locale');
const BaseModel = require('@joplin/lib/BaseModel').default;
import { _ } from '@joplin/lib/locale';
import BaseModel from '@joplin/lib/BaseModel';
class Command extends BaseCommand {
usage() {
public override usage() {
return 'use <notebook>';
}
description() {
public override description() {
return _('Switches to [notebook] - all further operations will happen within this notebook.');
}
compatibleUis() {
public override compatibleUis() {
return ['cli'];
}
async action(args) {
public override async action(args: any) {
const folder = await app().loadItem(BaseModel.TYPE_FOLDER, args['notebook']);
if (!folder) throw new Error(_('Cannot find "%s".', args['notebook']));
app().switchCurrentFolder(folder);

View File

@ -1,17 +1,17 @@
const BaseCommand = require('./base-command').default;
import BaseCommand from './base-command';
const { _ } = require('@joplin/lib/locale');
const versionInfo = require('@joplin/lib/versionInfo').default;
class Command extends BaseCommand {
usage() {
public override usage() {
return 'version';
}
description() {
public override description() {
return _('Displays version information');
}
async action() {
public override async action() {
this.stdout(versionInfo(require('./package.json'), {}).message);
}
}

View File

@ -16,8 +16,7 @@ export enum MarkdownTableJustify {
export interface MarkdownTableHeader {
name: string;
label: string;
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
filter?: Function;
filter?: (content: string)=> string;
disableEscape?: boolean;
disableHtmlEscape?: boolean;
justify?: MarkdownTableJustify;

View File

@ -44,6 +44,10 @@ export interface ImportOptions {
destinationFolderId?: string;
destinationFolder?: any;
outputFormat?: ImportModuleOutputFormat;
// Only supported by some importers.
onProgress?: (progressState: any, progress?: any)=> void;
onError?: (error: any)=> void;
}
export enum ExportProgressState {