shellcheck
Version:
Wrapper to download shellcheck
64 lines (63 loc) • 3.38 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.shellcheck = void 0;
const promises_1 = __importDefault(require("node:fs/promises"));
const node_process_1 = __importDefault(require("node:process"));
const node_child_process_1 = __importDefault(require("node:child_process"));
const configs_1 = require("./configs");
const logger_1 = require("./logger");
const helpers_1 = require("./helpers");
/**
* Spawn ShellCheck.
* Download ShellCheck if not found or invalid.
*
* @param args - ShellCheck arguments.
* @returns ShellCheck output.
*/
function shellcheck(args) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
const opts = {
bin: (_a = args === null || args === void 0 ? void 0 : args.bin) !== null && _a !== void 0 ? _a : configs_1.config.bin,
args: (_b = args === null || args === void 0 ? void 0 : args.args) !== null && _b !== void 0 ? _b : node_process_1.default.argv.slice(2),
stdio: (_c = args === null || args === void 0 ? void 0 : args.stdio) !== null && _c !== void 0 ? _c : 'pipe',
token: (_d = args === null || args === void 0 ? void 0 : args.token) !== null && _d !== void 0 ? _d : node_process_1.default.env.GITHUB_TOKEN
};
logger_1.logger.debug(`ShellCheck: ${JSON.stringify(opts)}`);
try {
// Check binary
logger_1.logger.debug(`ShellCheck checking binary '${opts.bin}'`);
yield promises_1.default.access(opts.bin,
// eslint-disable-next-line no-bitwise
promises_1.default.constants.F_OK | promises_1.default.constants.W_OK | promises_1.default.constants.X_OK);
}
catch (_e) {
// Download ShellCheck
try {
logger_1.logger.info(`ShellCheck binary not found or invalid, downloading to '${opts.bin}'`);
yield (0, helpers_1.download)({ destination: opts.bin, token: opts.token });
logger_1.logger.info(`ShellCheck binary successfully downloaded to '${opts.bin}'`);
}
catch (err) {
logger_1.logger.error(`Error downloading ShellCheck binary to '${opts.bin}': ${err}`);
throw err;
}
}
// Spawn ShellCheck
logger_1.logger.debug(`ShellCheck spawning binary '${opts.bin}' with arguments '${opts.args}'`);
return node_child_process_1.default.spawnSync(opts.bin, opts.args, { stdio: opts.stdio });
});
}
exports.shellcheck = shellcheck;
;