terminalizer/app.js

62 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2018-07-22 22:34:35 +00:00
/**
* Terminalizer
2023-06-29 13:19:17 +00:00
*
2018-07-22 22:34:35 +00:00
* @author Mohammad Fares <faressoft.com@gmail.com>
*/
2023-06-29 13:19:17 +00:00
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { join as pathJoin } from 'path';
import yargs from 'yargs';
import commands from './commands/index.js';
import errorHandler from './error-handler.js';
2018-07-22 22:34:35 +00:00
2023-06-29 13:19:17 +00:00
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const { version } = JSON.parse(readFileSync(pathJoin(__dirname, './package.json'), 'utf8'));
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
// Initialize yargs
2023-06-29 13:19:17 +00:00
yargs
.usage('Usage: $0 <command> [options]')
// Add link
.epilogue('For more information, check https://terminalizer.com')
// Set the version number
.version(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-07-22 22:34:35 +00:00
2018-10-01 09:25:09 +00:00
// Load commands
2023-06-29 13:19:17 +00:00
yargs
.command(commands.init)
.command(commands.config)
.command(commands.record)
.command(commands.play)
.command(commands.render)
.command(commands.share)
.command(commands.generate);
2018-11-25 12:51:28 +00:00
2023-06-29 13:19:17 +00:00
// 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
}