Use the new revamped DI

This commit is contained in:
Mohammad Fares 2018-11-25 14:51:28 +02:00
parent 911acf91ab
commit 52d6bebe90
2 changed files with 43 additions and 64 deletions

105
app.js
View File

@ -4,37 +4,14 @@
* @author Mohammad Fares <faressoft.com@gmail.com> * @author Mohammad Fares <faressoft.com@gmail.com>
*/ */
var yargs = require('yargs'), var yargs = require('yargs'),
is = require('is_js'), requireDir = require('require-dir');
chalk = require('chalk'), var package = require('./package.json'),
_ = require('lodash'), commands = requireDir('./commands'),
async = require('async'), DI = require('./di.js');
asyncPromises = require('async-promises'),
request = require('request'),
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'),
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 // Define the DI as a global object
global.di = di; global.di = new DI();
// Define the the root path of the app as a global constant // Define the the root path of the app as a global constant
global.ROOT_PATH = __dirname; global.ROOT_PATH = __dirname;
@ -43,32 +20,32 @@ global.ROOT_PATH = __dirname;
global.BASEURL = 'https://terminalizer.com'; global.BASEURL = 'https://terminalizer.com';
// Dependency Injection // Dependency Injection
di.set('is', is); di.require('chalk');
di.set('chalk', chalk); di.require('async');
di.set('_', _); di.require('request');
di.set('async', async); di.require('death');
di.set('asyncPromises', asyncPromises); di.require('path');
di.set('request', request); di.require('os');
di.set('death', death); di.require('electron');
di.set('stringArgv', stringArgv); di.require('deepmerge');
di.set('path', path); di.require('uuid');
di.set('ProgressBar', ProgressBar); di.require('is_js', 'is');
di.set('GIFEncoder', GIFEncoder); di.require('lodash', '_');
di.set('PNG', PNG); di.require('fs-extra', 'fs');
di.set('os', os); di.require('flowa', 'Flowa');
di.set('spawn', spawn); di.require('js-yaml', 'yaml');
di.set('electron', electron); di.require('node-pty-prebuilt', 'pty');
di.set('deepmerge', deepmerge); di.require('performance-now', 'now');
di.set('pty', pty); di.require('async-promises', 'asyncPromises');
di.set('fs', fs); di.require('string-argv', 'stringArgv');
di.set('now', now); di.require('progress', 'ProgressBar');
di.set('fs', fs); di.require('gif-encoder', 'GIFEncoder');
di.set('Flowa', Flowa); di.require('inquirer');
di.set('inquirer', inquirer);
di.set('yaml', yaml); di.set('PNG', require('pngjs').PNG);
di.set('uuid', uuid); di.set('spawn', require('child_process').spawn);
di.set('utility', utility); di.set('utility', require('./utility.js'));
di.set('play', play); di.set('commands', commands);
di.set('errorHandler', errorHandler); di.set('errorHandler', errorHandler);
// Initialize yargs // Initialize yargs
@ -89,13 +66,15 @@ yargs.usage('Usage: $0 <command> [options]')
.fail(errorHandler); .fail(errorHandler);
// Load commands // Load commands
yargs.command(require('./commands/init.js')) yargs.command(commands.init)
.command(require('./commands/config.js')) .command(commands.config)
.command(require('./commands/record.js')) .command(commands.record)
.command(require('./commands/play.js')) .command(commands.play)
.command(require('./commands/render.js')) .command(commands.render)
.command(require('./commands/share.js')) .command(commands.share)
.command(require('./commands/generate.js')) .command(commands.generate)
debugger;
try { try {
@ -119,7 +98,7 @@ function errorHandler(error) {
error = error.toString(); error = error.toString();
console.error('Error: \n ' + error + '\n'); console.error('Error: \n ' + error + '\n');
console.error('Hint:\n Use the ' + chalk.green('--help') + ' option to get help about the usage'); console.error('Hint:\n Use the ' + di.chalk.green('--help') + ' option to get help about the usage');
process.exit(1); process.exit(1);
} }

View File

@ -332,7 +332,7 @@ function command(argv) {
di._.partial(renderFrames, records, renderingOptions), di._.partial(renderFrames, records, renderingOptions),
// Adjust frames delays // Adjust frames delays
di._.partial(di.play.adjustFramesDelays, records, adjustFramesDelaysOptions), di._.partial(di.commands.play.adjustFramesDelays, records, adjustFramesDelaysOptions),
// Get the dimensions of the first rendered frame // Get the dimensions of the first rendered frame
di._.partial(getFrameDimensions), di._.partial(getFrameDimensions),