magica
Version:
ImageMagick for browser and Node.js, easy setup, high level API and Command Line Interface, including WASM binary for an easy setup.
84 lines • 3.32 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const misc_utils_of_mine_generic_1 = require("misc-utils-of-mine-generic");
const file_1 = require("../file/file");
const magickLoaded_1 = require("../imageMagick/magickLoaded");
const options_1 = require("../options");
const fileUtil_1 = require("../util/fileUtil");
const main_1 = require("./main");
const run_1 = require("./run");
function isCustomCommand(c) {
return __awaiter(this, void 0, void 0, function* () {
return c.join(' ').trim().startsWith(options_1.getOption('customCommandPrefix'));
});
}
exports.isCustomCommand = isCustomCommand;
class CustomCommandContextImpl {
constructor(o) {
this.main = main_1.main;
this.run = run_1.run;
this.log = magickLoaded_1.pushStdout;
this.error = magickLoaded_1.pushStderr;
this.options = o.options;
this.FS = o.FS;
this.outputFiles = o.outputFiles;
this.File = file_1.File;
}
isFile(f) {
return fileUtil_1.isFile(f, this.FS);
}
readFile(f) {
return fileUtil_1.readFile(f, this.FS);
}
isDirectory(f) {
return fileUtil_1.isDir(f, this.FS);
}
writeFile(f) {
fileUtil_1.writeFile(f, this.FS);
}
includeOutputFiles(files, exclude = false) {
if (exclude) {
misc_utils_of_mine_generic_1.arrayDifference(this.outputFiles, files, file_1.File.equals, this.outputFiles);
}
else {
misc_utils_of_mine_generic_1.arrayUnion(this.outputFiles, files, file_1.File.equals, this.outputFiles);
}
}
}
function dispatchCustomCommand(o) {
return __awaiter(this, void 0, void 0, function* () {
const s = o.command.slice(1).join(' ').trim();
o.options.debug && console.log('custom command js expression: ' + s);
var context = new CustomCommandContextImpl(o);
var error;
var returnValue;
magickLoaded_1.resetStdout();
magickLoaded_1.resetStderr();
try {
var f = eval(s);
o.options.debug && console.log('custom command js evaluated result function: ' + f);
returnValue = yield f(context);
}
catch (er) {
o.options.debug && console.error('Custom command ', s, 'evaluation error: ', er);
error = er;
}
return {
stdout: magickLoaded_1.getStdout(),
stderr: magickLoaded_1.getStderr(),
returnValue,
error,
};
});
}
exports.dispatchCustomCommand = dispatchCustomCommand;
//# sourceMappingURL=customCommand.js.map