@eris/image-cli
Advanced tools
Comparing version 0.3.1-alpha.5 to 0.3.1-alpha.6
@@ -17,2 +17,7 @@ #!/usr/bin/env node | ||
.usage('Usage: $0 -c [config]') | ||
.option('mode', { | ||
type: 'string', | ||
default: 'constrained', | ||
choices: ['freeform', 'constrained'], | ||
}) | ||
.option('config', { | ||
@@ -32,9 +37,45 @@ alias: 'c', | ||
if (PRESETS.indexOf(argv.config) >= 0) { | ||
argv.config = path.join(__dirname, `../../presets/${argv.config}.json`) | ||
async function runFreeform(): Promise<void> { | ||
try { | ||
const imageModules = { | ||
'@eris/image': require('@eris/image'), // tslint:disable-line | ||
sharp: require('sharp'), // tslint:disable-line | ||
} | ||
const unsafeGlobal = global as any | ||
unsafeGlobal['@eris/image-cli'] = imageModules | ||
const freeformModule = require(path.resolve(process.cwd(), argv.config)) | ||
let freeformFn: undefined | ((...args: any[]) => Promise<void>) | ||
if (typeof freeformModule === 'function') freeformFn = freeformModule | ||
if (typeof freeformModule.run === 'function') freeformFn = freeformModule.run | ||
if (freeformFn) await freeformFn(imageModules, argv) | ||
} catch (err) { | ||
process.stderr.write(`Fatal Error: ${err.stack}\n`) | ||
process.exit(1) | ||
} | ||
} | ||
const configEntries = readAllFrom(argv.config) | ||
const reporter = from(argv) | ||
const runner = new Runner(reporter, configEntries) | ||
runner.run(argv._, argv).catch(err => reporter.finished(err)) | ||
function runConstrained(): void { | ||
if (PRESETS.indexOf(argv.config) >= 0) { | ||
argv.config = path.join(__dirname, `../../presets/${argv.config}.json`) | ||
} | ||
const configEntries = readAllFrom(argv.config) | ||
const reporter = from(argv) | ||
const runner = new Runner(reporter, configEntries) | ||
runner.run(argv._, argv).catch(err => reporter.finished(err)) | ||
} | ||
async function run(): Promise<void> { | ||
switch (argv.mode) { | ||
case 'freeform': | ||
runFreeform() | ||
break | ||
case 'constrained': | ||
default: | ||
runConstrained() | ||
} | ||
} | ||
run() |
#!/usr/bin/env node | ||
"use strict"; | ||
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 }); | ||
@@ -15,2 +23,7 @@ const path = require("path"); | ||
.usage('Usage: $0 -c [config]') | ||
.option('mode', { | ||
type: 'string', | ||
default: 'constrained', | ||
choices: ['freeform', 'constrained'], | ||
}) | ||
.option('config', { | ||
@@ -29,9 +42,48 @@ alias: 'c', | ||
}).argv; | ||
if (PRESETS.indexOf(argv.config) >= 0) { | ||
argv.config = path.join(__dirname, `../../presets/${argv.config}.json`); | ||
function runFreeform() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const imageModules = { | ||
'@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); | ||
} | ||
}); | ||
} | ||
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 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 |
@@ -37,3 +37,5 @@ "use strict"; | ||
} | ||
return fs.readFileSync(filePath); | ||
const buffer = fs.readFileSync(filePath); | ||
this._cachedFiles.set(filePath, buffer); | ||
return buffer; | ||
} | ||
@@ -40,0 +42,0 @@ _processCachedEntry(entry) { |
@@ -57,3 +57,5 @@ import * as fs from 'fs' | ||
return fs.readFileSync(filePath) | ||
const buffer = fs.readFileSync(filePath) | ||
this._cachedFiles.set(filePath, buffer) | ||
return buffer | ||
} | ||
@@ -91,3 +93,2 @@ | ||
const input = this._getBufferFromCacheOrDisk(entry.input) | ||
const image = Image.from(input).options(entry.settings) | ||
@@ -94,0 +95,0 @@ const result = entry.action ? await image[entry.action]() : input |
{ | ||
"name": "@eris/image-cli", | ||
"version": "0.3.1-alpha.5", | ||
"version": "0.3.1-alpha.6", | ||
"description": "CLI wrapper and standalone executable API for @eris/image.", | ||
@@ -10,2 +10,3 @@ "main": "./dist/lib/client.js", | ||
"scripts": { | ||
"start": "node ./bin/run.js", | ||
"download-prebuilt": "./scripts/download-prebuilt.sh", | ||
@@ -38,3 +39,3 @@ "build": "tsc && bash ./scripts/build.sh", | ||
"devDependencies": { | ||
"@eris/image": "0.3.1-alpha.5", | ||
"@eris/image": "0.3.1-alpha.6", | ||
"chai": "^4.1.2", | ||
@@ -54,3 +55,3 @@ "chai-as-promised": "^7.1.1", | ||
}, | ||
"gitHead": "4a01e090d5f1a5691e6d7c19b51186bfcbed411f" | ||
"gitHead": "e29256322a834ae6b6ee08211890314f16d97687" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
58162
1087
5