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
|
2018-03-09 22:59:12 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
2017-06-22 23:52:27 +02:00
|
|
|
|
2018-03-09 22:59:12 +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);
|
2018-01-09 21:56:38 +02:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
const { app } = require('./app.js');
|
|
|
|
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');
|
|
|
|
const MasterKey = require('lib/models/MasterKey');
|
|
|
|
const Setting = require('lib/models/Setting.js');
|
|
|
|
const { Logger } = require('lib/logger.js');
|
|
|
|
const { FsDriverNode } = require('lib/fs-driver-node.js');
|
|
|
|
const { shimInit } = require('lib/shim-init-node.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
|
|
|
|
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.
|
2018-03-09 22:59:12 +02:00
|
|
|
BaseItem.loadClass('Note', Note);
|
|
|
|
BaseItem.loadClass('Folder', Folder);
|
|
|
|
BaseItem.loadClass('Resource', Resource);
|
|
|
|
BaseItem.loadClass('Tag', Tag);
|
|
|
|
BaseItem.loadClass('NoteTag', NoteTag);
|
|
|
|
BaseItem.loadClass('MasterKey', MasterKey);
|
2017-07-10 22:03:46 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
Setting.setConstant('appId', 'net.cozic.joplin-cli');
|
|
|
|
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,
|
2018-03-09 22:59:12 +02:00
|
|
|
output: process.stdout
|
2017-08-04 18:50:12 +02:00
|
|
|
});
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
rl.on("SIGINT", function () {
|
2017-08-04 18:50:12 +02:00
|
|
|
process.emit("SIGINT");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
process.stdout.on('error', function( err ) {
|
2017-08-04 22:13:29 +02:00
|
|
|
// https://stackoverflow.com/questions/12329816/error-write-epipe-when-piping-node-output-to-head#15884508
|
|
|
|
if (err.code == "EPIPE") {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-21 19:01:37 +02:00
|
|
|
// async function main() {
|
2018-02-27 22:04:38 +02:00
|
|
|
// const InteropService = require('lib/services/InteropService');
|
|
|
|
// const service = new InteropService();
|
|
|
|
// console.info(service.moduleByFormat('importer', 'enex'));
|
|
|
|
// //await service.modules();
|
2018-01-21 19:01:37 +02:00
|
|
|
// }
|
|
|
|
|
|
|
|
// main().catch((error) => { console.error(error); });
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application.start(process.argv).catch((error) => {
|
|
|
|
if (error.code == 'flagError') {
|
2018-03-07 21:11:55 +02:00
|
|
|
console.error(error.message);
|
2018-03-09 22:59:12 +02:00
|
|
|
console.error(_('Type `joplin help` for usage information.'));
|
2018-03-07 21:11:55 +02:00
|
|
|
} else {
|
2018-03-09 22:59:12 +02:00
|
|
|
console.error(_('Fatal error:'));
|
2018-03-07 21:11:55 +02:00
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
process.exit(1);
|
2018-03-09 22:59:12 +02:00
|
|
|
});
|