terminalizer/app.js

126 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-07-22 22:34:35 +00:00
/**
* Terminalizer
*
* @author Mohammad Fares <faressoft.com@gmail.com>
*/
var yargs = require('yargs'),
is = require('is_js'),
chalk = require('chalk'),
_ = require('lodash'),
async = require('async'),
asyncPromises = require('async-promises'),
request = require('request'),
2018-07-22 22:34:35 +00:00
death = require('death'),
stringArgv = require('string-argv'),
path = require('path'),
ProgressBar = require('progress'),
GIFEncoder = require('gif-encoder'),
PNG = require('pngjs').PNG,
yaml = require('js-yaml'),
uuid = require('uuid'),
Flowa = require('flowa'),
inquirer = require('inquirer'),
2018-07-22 22:34:35 +00:00
os = require('os'),
spawn = require('child_process').spawn,
electron = require('electron'),
deepmerge = require('deepmerge'),
pty = require('node-pty-prebuilt'),
fs = require('fs-extra'),
now = require('performance-now');
var package = require('./package.json'),
utility = require('./utility.js'),
di = require('./di.js'),
play = require('./commands/play.js');
// Define the DI as a global object
global.di = di;
// 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
di.set('is', is);
di.set('chalk', chalk);
di.set('_', _);
di.set('async', async);
di.set('asyncPromises', asyncPromises);
di.set('request', request);
2018-07-22 22:34:35 +00:00
di.set('death', death);
di.set('stringArgv', stringArgv);
di.set('path', path);
di.set('ProgressBar', ProgressBar);
di.set('GIFEncoder', GIFEncoder);
di.set('PNG', PNG);
di.set('os', os);
di.set('spawn', spawn);
di.set('electron', electron);
di.set('deepmerge', deepmerge);
di.set('pty', pty);
di.set('fs', fs);
di.set('now', now);
di.set('fs', fs);
di.set('Flowa', Flowa);
di.set('inquirer', inquirer);
2018-07-22 22:34:35 +00:00
di.set('yaml', yaml);
di.set('uuid', uuid);
2018-07-22 22:34:35 +00:00
di.set('utility', utility);
di.set('play', play);
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
yargs.command(require('./commands/init.js'))
.command(require('./commands/config.js'))
.command(require('./commands/record.js'))
.command(require('./commands/play.js'))
.command(require('./commands/render.js'))
.command(require('./commands/share.js'))
.command(require('./commands/generate.js'))
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-07-28 16:09:43 +00:00
console.error('Hint:\n Use the ' + chalk.green('--help') + ' option to get help about the usage');
2018-07-22 22:34:35 +00:00
process.exit(1);
}