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
|
2023-06-14 02:54:16 +00:00
|
|
|
// `www` is necessary due to https://github.com/faressoft/terminalizer/issues/207
|
|
|
|
global.BASEURL = 'https://www.terminalizer.com';
|
2018-10-14 18:54:39 +00:00
|
|
|
|
2018-07-22 22:34:35 +00:00
|
|
|
// Dependency Injection
|
2018-11-25 12:51:28 +00:00
|
|
|
di.require('chalk');
|
|
|
|
di.require('async');
|
2024-08-29 00:37:59 +00:00
|
|
|
di.require('axios');
|
2018-11-25 12:51:28 +00:00
|
|
|
di.require('death');
|
|
|
|
di.require('path');
|
|
|
|
di.require('os');
|
|
|
|
di.require('electron');
|
|
|
|
di.require('deepmerge');
|
|
|
|
di.require('uuid');
|
2023-07-09 09:59:16 +00:00
|
|
|
di.require('tmp');
|
2018-11-25 12:51:28 +00:00
|
|
|
di.require('lodash', '_');
|
|
|
|
di.require('fs-extra', 'fs');
|
|
|
|
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');
|
|
|
|
|
2024-08-29 00:37:59 +00:00
|
|
|
di.set('pty', require('@homebridge/node-pty-prebuilt-multiarch'));
|
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
|
2023-07-08 09:19:52 +00:00
|
|
|
.epilogue('For more information, check https://www.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);
|
|
|
|
|
|
|
|
}
|