-
Notifications
You must be signed in to change notification settings - Fork 500
/
app.js
104 lines (86 loc) · 2.54 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Terminalizer
*
* @author Mohammad Fares <[email protected]>
*/
var yargs = require('yargs'),
requireDir = require('require-dir');
var package = require('./package.json'),
commands = requireDir('./commands'),
DI = require('./di.js');
// Define the DI as a global object
global.di = new DI();
// Define the the root path of the app as a global constant
global.ROOT_PATH = __dirname;
// The base url of the Terminalizer website
// `www` is necessary due to https://github.com/faressoft/terminalizer/issues/207
global.BASEURL = 'https://www.terminalizer.com';
// Dependency Injection
di.require('chalk');
di.require('async');
di.require('axios');
di.require('death');
di.require('path');
di.require('os');
di.require('electron');
di.require('deepmerge');
di.require('uuid');
di.require('tmp');
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');
di.set('pty', require('@homebridge/node-pty-prebuilt-multiarch'));
di.set('PNG', require('pngjs').PNG);
di.set('spawn', require('child_process').spawn);
di.set('utility', require('./utility.js'));
di.set('commands', commands);
di.set('errorHandler', errorHandler);
// Initialize yargs
yargs.usage('Usage: $0 <command> [options]')
// Add link
.epilogue('For more information, check https://www.terminalizer.com')
// 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);
// Load commands
yargs.command(commands.init)
.command(commands.config)
.command(commands.record)
.command(commands.play)
.command(commands.render)
.command(commands.share)
.command(commands.generate)
debugger;
try {
// Parse the command line arguments
yargs.parse();
} catch (error) {
// Print the error
errorHandler(error);
}
/**
* Print an error
*
* @param {String|Error} error
*/
function errorHandler(error) {
error = error.toString();
console.error('Error: \n ' + error + '\n');
console.error('Hint:\n Use the ' + di.chalk.green('--help') + ' option to get help about the usage');
process.exit(1);
}