2017-06-25 18:30:44 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2017-12-13 21:01:04 +02:00
|
|
|
// Make it possible to require("/lib/...") without specifying full path
|
2017-11-03 20:39:08 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
2017-06-22 23:52:27 +02:00
|
|
|
|
2018-01-09 21:56:38 +02:00
|
|
|
const compareVersion = require('compare-version');
|
|
|
|
const nodeVersion = process && process.versions && process.versions.node ? process.versions.node : '0.0.0';
|
|
|
|
if (compareVersion(nodeVersion, '8.0.0') < 0) {
|
|
|
|
console.error('Joplin requires Node 8+. Detected version ' + nodeVersion);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2017-11-03 02:09:34 +02:00
|
|
|
const { app } = require('./app.js');
|
2017-12-14 20:12:14 +02:00
|
|
|
const Folder = require('lib/models/Folder.js');
|
|
|
|
const Resource = require('lib/models/Resource.js');
|
|
|
|
const BaseItem = require('lib/models/BaseItem.js');
|
|
|
|
const Note = require('lib/models/Note.js');
|
|
|
|
const Tag = require('lib/models/Tag.js');
|
|
|
|
const NoteTag = require('lib/models/NoteTag.js');
|
2017-12-13 21:01:04 +02:00
|
|
|
const MasterKey = require('lib/models/MasterKey');
|
2017-12-14 20:12:14 +02:00
|
|
|
const Setting = require('lib/models/Setting.js');
|
2017-11-03 02:09:34 +02:00
|
|
|
const { Logger } = require('lib/logger.js');
|
2017-11-04 15:23:15 +02:00
|
|
|
const { FsDriverNode } = require('lib/fs-driver-node.js');
|
2017-11-03 02:09:34 +02:00
|
|
|
const { shimInit } = require('lib/shim-init-node.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
2018-01-17 20:51:15 +02:00
|
|
|
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
|
2017-12-13 21:01:04 +02:00
|
|
|
const EncryptionService = require('lib/services/EncryptionService');
|
2017-06-22 23:52:27 +02:00
|
|
|
|
2017-07-05 23:52:31 +02:00
|
|
|
const fsDriver = new FsDriverNode();
|
|
|
|
Logger.fsDriver_ = fsDriver;
|
|
|
|
Resource.fsDriver_ = fsDriver;
|
2017-12-13 21:01:04 +02:00
|
|
|
EncryptionService.fsDriver_ = fsDriver;
|
2018-01-17 20:51:15 +02:00
|
|
|
FileApiDriverLocal.fsDriver_ = fsDriver;
|
2017-07-05 23:52:31 +02:00
|
|
|
|
2017-07-10 22:03:46 +02:00
|
|
|
// That's not good, but it's to avoid circular dependency issues
|
|
|
|
// in the BaseItem class.
|
|
|
|
BaseItem.loadClass('Note', Note);
|
|
|
|
BaseItem.loadClass('Folder', Folder);
|
|
|
|
BaseItem.loadClass('Resource', Resource);
|
|
|
|
BaseItem.loadClass('Tag', Tag);
|
|
|
|
BaseItem.loadClass('NoteTag', NoteTag);
|
2017-12-13 21:01:04 +02:00
|
|
|
BaseItem.loadClass('MasterKey', MasterKey);
|
2017-07-10 22:03:46 +02:00
|
|
|
|
2017-06-29 22:52:52 +02:00
|
|
|
Setting.setConstant('appId', 'net.cozic.joplin-cli');
|
2017-07-07 00:15:31 +02:00
|
|
|
Setting.setConstant('appType', 'cli');
|
2017-06-29 22:52:52 +02:00
|
|
|
|
2017-07-10 22:03:46 +02:00
|
|
|
shimInit();
|
2017-06-22 23:52:27 +02:00
|
|
|
|
2017-08-04 18:50:12 +02:00
|
|
|
const application = app();
|
|
|
|
|
|
|
|
if (process.platform === "win32") {
|
|
|
|
var rl = require("readline").createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
|
|
|
});
|
|
|
|
|
|
|
|
rl.on("SIGINT", function () {
|
|
|
|
process.emit("SIGINT");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-04 22:13:29 +02:00
|
|
|
process.stdout.on('error', function( err ) {
|
|
|
|
// https://stackoverflow.com/questions/12329816/error-write-epipe-when-piping-node-output-to-head#15884508
|
|
|
|
if (err.code == "EPIPE") {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-01-21 19:01:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// async function main() {
|
|
|
|
// const WebDavApi = require('lib/WebDavApi');
|
2018-01-25 21:01:14 +02:00
|
|
|
// const api = new WebDavApi('http://nextcloud.local/remote.php/dav/files/admin/Joplin', { username: 'admin', password: '1234567' });
|
2018-01-21 19:01:37 +02:00
|
|
|
// const { FileApiDriverWebDav } = new require('lib/file-api-driver-webdav');
|
|
|
|
// const driver = new FileApiDriverWebDav(api);
|
|
|
|
|
2018-01-25 21:01:14 +02:00
|
|
|
// const stat = await driver.stat('');
|
2018-01-21 19:01:37 +02:00
|
|
|
// console.info(stat);
|
|
|
|
|
2018-01-25 21:01:14 +02:00
|
|
|
// // const stat = await driver.stat('testing.txt');
|
|
|
|
// // console.info(stat);
|
2018-01-21 19:01:37 +02:00
|
|
|
|
2018-01-25 21:01:14 +02:00
|
|
|
|
|
|
|
// // const content = await driver.get('testing.txta');
|
|
|
|
// // console.info(content);
|
|
|
|
|
|
|
|
// // const content = await driver.get('testing.txta', { target: 'file', path: '/var/www/joplin/CliClient/testing-file.txt' });
|
|
|
|
// // console.info(content);
|
|
|
|
|
|
|
|
// // const content = await driver.mkdir('newdir5');
|
|
|
|
// // console.info(content);
|
|
|
|
|
|
|
|
// //await driver.put('myfile4.md', 'this is my content');
|
|
|
|
|
|
|
|
// // await driver.put('testimg.jpg', null, { source: 'file', path: '/mnt/d/test.jpg' });
|
|
|
|
|
|
|
|
// // await driver.delete('myfile4.md');
|
|
|
|
|
|
|
|
// // const deltaResult = await driver.delta('', {
|
|
|
|
// // allItemIdsHandler: () => { return []; }
|
|
|
|
// // });
|
|
|
|
// // console.info(deltaResult);
|
2018-01-21 19:01:37 +02:00
|
|
|
// }
|
|
|
|
|
|
|
|
// main().catch((error) => { console.error(error); });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-04 14:23:46 +02:00
|
|
|
application.start(process.argv).catch((error) => {
|
2017-07-18 20:21:03 +02:00
|
|
|
console.error(_('Fatal error:'));
|
2017-07-10 22:03:46 +02:00
|
|
|
console.error(error);
|
2017-06-22 23:52:27 +02:00
|
|
|
});
|