@eris/image-cli
Version:
CLI wrapper and standalone executable API for @eris/image.
88 lines • 3.16 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("fs");
const config_entry_1 = require("../lib/config-entry");
const reporters_1 = require("../lib/reporters");
const runner_1 = require("../lib/runner");
const yargs = require('yargs'); // tslint:disable-line
const PRESETS = fs
.readdirSync(path.join(__dirname, '../../presets'))
.map(p => p.replace('.json', ''));
const argv = yargs
.usage('Usage: $0 -c [config]')
.option('mode', {
type: 'string',
default: 'constrained',
choices: ['freeform', 'constrained'],
})
.option('config', {
alias: 'c',
type: 'string',
required: true,
})
.option('force', {
type: 'boolean',
})
.option('reporter', {
alias: 'r',
default: 'pretty',
choices: ['json', 'pretty'],
}).argv;
function runFreeform() {
return __awaiter(this, void 0, void 0, function* () {
try {
const imageModules = {
'@eris/exif': require('@eris/exif'),
'@eris/image': require('@eris/image'),
sharp: require('sharp'),
};
const unsafeGlobal = global;
unsafeGlobal['@eris/image-cli'] = imageModules;
const freeformModule = require(path.resolve(process.cwd(), argv.config));
let freeformFn;
if (typeof freeformModule === 'function')
freeformFn = freeformModule;
if (typeof freeformModule.run === 'function')
freeformFn = freeformModule.run;
if (freeformFn)
yield freeformFn(imageModules, argv);
}
catch (err) {
process.stderr.write(`Fatal Error: ${err.stack}\n`);
process.exit(1);
}
});
}
function runConstrained() {
if (PRESETS.indexOf(argv.config) >= 0) {
argv.config = path.join(__dirname, `../../presets/${argv.config}.json`);
}
const configEntries = config_entry_1.readAllFrom(argv.config);
const reporter = reporters_1.from(argv);
const runner = new runner_1.Runner(reporter, configEntries);
runner.run(argv._, argv).catch(err => reporter.finished(err));
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
switch (argv.mode) {
case 'freeform':
runFreeform();
break;
case 'constrained':
default:
runConstrained();
}
});
}
run();
//# sourceMappingURL=cli.js.map