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-07-10 22:03:46 +02:00
|
|
|
import { app } from './app.js';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { BaseModel } from 'lib/base-model.js';
|
|
|
|
import { Folder } from 'lib/models/folder.js';
|
2017-07-02 14:02:07 +02:00
|
|
|
import { Resource } from 'lib/models/resource.js';
|
2017-06-25 09:35:59 +02:00
|
|
|
import { BaseItem } from 'lib/models/base-item.js';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { Note } from 'lib/models/note.js';
|
2017-07-03 20:58:01 +02:00
|
|
|
import { Tag } from 'lib/models/tag.js';
|
2017-07-06 21:48:17 +02:00
|
|
|
import { NoteTag } from 'lib/models/note-tag.js';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { Setting } from 'lib/models/setting.js';
|
|
|
|
import { Logger } from 'lib/logger.js';
|
2017-07-05 23:52:31 +02:00
|
|
|
import { FsDriverNode } from './fs-driver-node.js';
|
2017-07-10 20:09:58 +02:00
|
|
|
import { shimInit } from 'lib/shim-init-node.js';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { _ } from '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-08-20 16:29:18 +02:00
|
|
|
let commandCancelCalled_ = false;
|
|
|
|
|
2017-08-04 18:50:12 +02:00
|
|
|
process.on("SIGINT", async function() {
|
2017-08-20 16:29:18 +02:00
|
|
|
const cmd = application.currentCommand();
|
|
|
|
|
2017-09-12 20:01:15 +02:00
|
|
|
if (!cmd || !cmd.cancellable() || commandCancelCalled_) {
|
2017-08-20 16:29:18 +02:00
|
|
|
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
|
|
|
});
|