2017-06-25 18:30:44 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2019-02-09 21:04:00 +02:00
|
|
|
// Use njstrace to find out what Node.js might be spending time on
|
|
|
|
// var njstrace = require('njstrace').inject();
|
|
|
|
|
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';
|
2019-12-19 00:25:14 +02:00
|
|
|
if (compareVersion(nodeVersion, '10.0.0') < 0) {
|
|
|
|
console.error(`Joplin requires Node 10+. 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');
|
2020-11-05 18:58:23 +02:00
|
|
|
const Folder = require('@joplinapp/lib/models/Folder.js');
|
|
|
|
const Resource = require('@joplinapp/lib/models/Resource.js');
|
|
|
|
const BaseItem = require('@joplinapp/lib/models/BaseItem.js');
|
|
|
|
const Note = require('@joplinapp/lib/models/Note.js');
|
|
|
|
const Tag = require('@joplinapp/lib/models/Tag.js');
|
|
|
|
const NoteTag = require('@joplinapp/lib/models/NoteTag.js');
|
|
|
|
const MasterKey = require('@joplinapp/lib/models/MasterKey');
|
|
|
|
const Setting = require('@joplinapp/lib/models/Setting').default;
|
|
|
|
const Revision = require('@joplinapp/lib/models/Revision.js');
|
|
|
|
const Logger = require('@joplinapp/lib/Logger').default;
|
|
|
|
const FsDriverNode = require('@joplinapp/lib/fs-driver-node').default;
|
|
|
|
const sharp = require('sharp');
|
|
|
|
const { shimInit } = require('@joplinapp/lib/shim-init-node.js');
|
|
|
|
const shim = require('@joplinapp/lib/shim').default;
|
|
|
|
const { _ } = require('@joplinapp/lib/locale');
|
|
|
|
const { FileApiDriverLocal } = require('@joplinapp/lib/file-api-driver-local.js');
|
|
|
|
const EncryptionService = require('@joplinapp/lib/services/EncryptionService');
|
|
|
|
const envFromArgs = require('@joplinapp/lib/envFromArgs');
|
2020-06-03 18:07:50 +02:00
|
|
|
|
|
|
|
const env = envFromArgs(process.argv);
|
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);
|
2019-05-06 22:35:29 +02:00
|
|
|
BaseItem.loadClass('Revision', Revision);
|
2017-07-10 22:03:46 +02:00
|
|
|
|
2020-06-03 18:07:50 +02:00
|
|
|
Setting.setConstant('appId', `net.cozic.joplin${env === 'dev' ? 'dev' : ''}-cli`);
|
2018-03-09 22:59:12 +02:00
|
|
|
Setting.setConstant('appType', 'cli');
|
2017-06-29 22:52:52 +02:00
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
let keytar;
|
|
|
|
try {
|
|
|
|
keytar = shim.platformSupportsKeyChain() ? require('keytar') : null;
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Cannot load keytar - keychain support will be disabled', error);
|
|
|
|
keytar = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
shimInit(sharp, keytar);
|
2017-06-22 23:52:27 +02:00
|
|
|
|
2017-08-04 18:50:12 +02:00
|
|
|
const application = app();
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
if (process.platform === 'win32') {
|
2020-03-14 01:46:14 +02:00
|
|
|
const rl = require('readline').createInterface({
|
2017-08-04 18:50:12 +02:00
|
|
|
input: process.stdin,
|
2019-07-30 09:35:42 +02:00
|
|
|
output: process.stdout,
|
2017-08-04 18:50:12 +02:00
|
|
|
});
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
rl.on('SIGINT', function() {
|
|
|
|
process.emit('SIGINT');
|
2017-08-04 18:50:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-30 09:35:42 +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
|
2019-07-30 09:35:42 +02:00
|
|
|
if (err.code == 'EPIPE') {
|
2017-08-04 22:13:29 +02:00
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-21 10:14:33 +02:00
|
|
|
application.start(process.argv).catch(error => {
|
2018-03-09 22:59:12 +02:00
|
|
|
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);
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|