UNPKG

gulp-dotnet-cli

Version:
56 lines 2.23 kB
"use strict"; // tslint:disable-next-line:no-reference /// <reference path="./declarations/child-process-promise.d.ts" /> Object.defineProperty(exports, "__esModule", { value: true }); const cp = require("child-process-promise"); const path = require("path"); const PluginError = require("plugin-error"); const through = require("through2"); // Consts const PLUGIN_NAME = "gulp-dotnet-cli"; // Plugin level function(dealing with files) /* * Wrapper over through2 to execute commands with promises * @param {string} command the root command to run usually dotnet * @param {string|Array<string>} noun The action to take build, push, pack, etc * @param {Array<String>} args the arguments to pass such as ['--verbosity', 'normal'] * @param {boolean} echo Should the command be printed to the console? * @param {boolean} optional default false, if true sets the current working directory to the files directory. */ // tslint:disable-next-line:max-line-length function shelly(command, noun, args, echo = false, setCwd = false) { if (!command) { throw new PluginError(PLUGIN_NAME, "command not passed"); } if (!noun) { throw new PluginError(PLUGIN_NAME, "noun not passed"); } if (!Array.isArray(args)) { throw new PluginError(PLUGIN_NAME, "Arguments has to be an array"); } // Creating a stream through which each file will pass return through.obj(function (file, enc, cb) { if (!file || !file.path) { // return empty file return cb(null, file); } const calculatedArgs = [].concat(noun, file.path, args); if (echo) { console.log(`${command} ${calculatedArgs.join(" ")}`); } const options = { stdio: "inherit" }; if (setCwd) { options.cwd = path.dirname(file.path); } cp.spawn(command, calculatedArgs, options) .then((a) => cb(null, file)) .catch((ex) => { let pluginError = new PluginError(PLUGIN_NAME, `failed to ${noun}`); this.emit("error", pluginError); cb(pluginError, file); }) .catch((ex) => { }); }); } exports.default = shelly; //# sourceMappingURL=shelly.js.map