2017-06-25 18:30:44 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2017-08-03 19:48:14 +02:00
|
|
|
// Loading time: 20170803: 1.5s with no commands
|
|
|
|
|
2017-06-22 23:52:27 +02:00
|
|
|
require('source-map-support').install();
|
|
|
|
require('babel-plugin-transform-runtime');
|
|
|
|
|
2017-11-03 02:09:34 +02:00
|
|
|
const { app } = require('./app.js');
|
|
|
|
const { BaseModel } = require('lib/base-model.js');
|
|
|
|
const { Folder } = require('lib/models/folder.js');
|
|
|
|
const { Resource } = require('lib/models/resource.js');
|
|
|
|
const { BaseItem } = require('lib/models/base-item.js');
|
|
|
|
const { Note } = require('lib/models/note.js');
|
|
|
|
const { Tag } = require('lib/models/tag.js');
|
|
|
|
const { NoteTag } = require('lib/models/note-tag.js');
|
|
|
|
const { Setting } = require('lib/models/setting.js');
|
|
|
|
const { Logger } = require('lib/logger.js');
|
|
|
|
const { FsDriverNode } = require('./fs-driver-node.js');
|
|
|
|
const { shimInit } = require('lib/shim-init-node.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
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-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-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-10-14 20:03:23 +02:00
|
|
|
// let commandCancelCalled_ = false;
|
2017-08-20 16:29:18 +02:00
|
|
|
|
2017-10-14 20:03:23 +02:00
|
|
|
// process.on("SIGINT", async function() {
|
|
|
|
// const cmd = application.currentCommand();
|
2017-08-20 16:29:18 +02:00
|
|
|
|
2017-10-14 20:03:23 +02:00
|
|
|
// if (!cmd || !cmd.cancellable() || commandCancelCalled_) {
|
|
|
|
// process.exit(0);
|
|
|
|
// } else {
|
|
|
|
// commandCancelCalled_ = true;
|
|
|
|
// await cmd.cancel();
|
|
|
|
// }
|
|
|
|
// });
|
2017-08-04 18:50:12 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-04 18:50:12 +02:00
|
|
|
application.start().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
|
|
|
});
|