@plugjs/plug
Version:
PlugJS Build System ===================
33 lines • 1.35 kB
JavaScript
import { install } from "../pipe.js";
import { execChild } from "../utils/exec.js";
import { parseOptions } from "../utils/options.js";
/* ========================================================================== *
* INSTALLATION / IMPLEMENTATION *
* ========================================================================== */
install('exec', class Exec {
_cmd;
_args;
_options;
constructor(...args) {
const { params, options } = parseOptions(args, {});
const [_cmd, ..._args] = params;
this._cmd = _cmd;
this._args = _args;
this._options = options;
}
async pipe(files, context) {
const { relativePaths = true, ...options } = this._options;
if (!options.cwd)
options.cwd = files.directory;
// What to use as extra arguments? Relative or absolute paths?
const params = [...(relativePaths ? files : files.absolutePaths())];
// In case of shell usage, each extra parameter (file) gets quoted!
if (options.shell)
params.forEach((s, i, a) => a[i] = JSON.stringify(s));
// Run our child
await execChild(this._cmd, [...this._args, ...params], options, context);
// Return our files
return files;
}
});
//# sourceMappingURL=exec.js.map