terminalizer/app.js

105 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-07-22 22:34:35 +00:00
/**
* Terminalizer
*
* @author Mohammad Fares <faressoft.com@gmail.com>
*/
2018-11-25 12:51:28 +00:00
var yargs = require('yargs'),
requireDir = require('require-dir');
var package = require('./package.json'),
commands = requireDir('./commands'),
DI = require('./di.js');
2018-07-22 22:34:35 +00:00
// Define the DI as a global object
2018-11-25 12:51:28 +00:00
global.di = new DI();
2018-07-22 22:34:35 +00:00
// Define the the root path of the app as a global constant
global.ROOT_PATH = __dirname;
2018-10-14 18:54:39 +00:00
// The base url of the Terminalizer website
global.BASEURL = 'https://terminalizer.com';
2018-07-22 22:34:35 +00:00
// Dependency Injection
2018-11-25 12:51:28 +00:00
di.require('chalk');
di.require('async');
di.require('request');
di.require('death');
di.require('path');
di.require('os');
di.require('electron');
di.require('deepmerge');
di.require('uuid');
di.require('is_js', 'is');
di.require('lodash', '_');
di.require('fs-extra', 'fs');
di.require('flowa', 'Flowa');
di.require('js-yaml', 'yaml');
di.require('performance-now', 'now');
di.require('async-promises', 'asyncPromises');
di.require('string-argv', 'stringArgv');
di.require('progress', 'ProgressBar');
di.require('gif-encoder', 'GIFEncoder');
di.require('inquirer');
di.set('pty', require('@faressoft/node-pty-prebuilt'));
2018-11-25 12:51:28 +00:00
di.set('PNG', require('pngjs').PNG);
di.set('spawn', require('child_process').spawn);
di.set('utility', require('./utility.js'));
di.set('commands', commands);
2018-07-22 22:34:35 +00:00
di.set('errorHandler', errorHandler);
// Initialize yargs
yargs.usage('Usage: $0 <command> [options]')
// Add link
2018-10-01 09:22:52 +00:00
.epilogue('For more information, check https://terminalizer.com')
2018-07-22 22:34:35 +00:00
// Set the version number
.version(package.version)
// Add aliases for version and help options
.alias({v: 'version', h: 'help'})
// Require to pass a command
.demandCommand(1, 'The command is missing')
// Strict mode
.strict()
// Set width to 90 cols
.wrap(100)
// Handle failures
.fail(errorHandler);
2018-10-01 09:25:09 +00:00
// Load commands
2018-11-25 12:51:28 +00:00
yargs.command(commands.init)
.command(commands.config)
.command(commands.record)
.command(commands.play)
.command(commands.render)
.command(commands.share)
.command(commands.generate)
debugger;
2018-07-22 22:34:35 +00:00
2018-10-01 09:25:24 +00:00
try {
// Parse the command line arguments
yargs.parse();
} catch (error) {
// Print the error
errorHandler(error);
}
2018-07-22 22:34:35 +00:00
/**
2018-10-01 09:25:24 +00:00
* Print an error
2018-07-22 22:34:35 +00:00
*
2018-10-01 09:25:24 +00:00
* @param {String|Error} error
2018-07-22 22:34:35 +00:00
*/
2018-10-01 09:25:24 +00:00
function errorHandler(error) {
error = error.toString();
2018-07-22 22:34:35 +00:00
2018-10-01 09:25:24 +00:00
console.error('Error: \n ' + error + '\n');
2018-11-25 12:51:28 +00:00
console.error('Hint:\n Use the ' + di.chalk.green('--help') + ' option to get help about the usage');
2018-07-22 22:34:35 +00:00
process.exit(1);
}