shellcheck
Version:
Wrapper to download shellcheck
75 lines (74 loc) • 3.9 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.buildURL = void 0;
const node_process_1 = __importDefault(require("node:process"));
const node_url_1 = __importDefault(require("node:url"));
const configs_1 = require("../configs");
const errors_1 = require("../errors");
const logger_1 = require("../logger");
const shellCheckPlatform_1 = require("./shellCheckPlatform");
const shellCheckArchitecture_1 = require("./shellCheckArchitecture");
const request_1 = require("./request");
/**
* Find latest release version.
*
* @returns Latest release version.
*/
function findLatestReleaseVersion(args) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const opts = {
url: (_a = args === null || args === void 0 ? void 0 : args.url) !== null && _a !== void 0 ? _a : configs_1.config.apiURL,
token: args === null || args === void 0 ? void 0 : args.token
};
logger_1.logger.debug(`Finding latest release version from ${opts.url}`);
const data = yield (0, request_1.requestJSON)({
url: opts.url,
token: opts.token
});
if (!data.tag_name)
throw new errors_1.ReleaseError(`Unable to determine latest release version because 'tag_name' is missing`);
logger_1.logger.debug(`Latest release version is '${data.tag_name}'`);
return data.tag_name;
});
}
/**
* Build URL.
*
* @param args - Arguments.
* @returns Download URL.
*/
function buildURL(args) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
const opts = {
baseURL: (_a = args === null || args === void 0 ? void 0 : args.baseURL) !== null && _a !== void 0 ? _a : configs_1.config.downloadURL,
release: !(args === null || args === void 0 ? void 0 : args.release) || (args === null || args === void 0 ? void 0 : args.release) === 'latest'
? yield findLatestReleaseVersion({ token: args === null || args === void 0 ? void 0 : args.token })
: args.release,
platform: (_b = args === null || args === void 0 ? void 0 : args.platform) !== null && _b !== void 0 ? _b : node_process_1.default.platform,
architecture: (_c = args === null || args === void 0 ? void 0 : args.architecture) !== null && _c !== void 0 ? _c : node_process_1.default.arch,
archive: (_d = args === null || args === void 0 ? void 0 : args.archive) !== null && _d !== void 0 ? _d : 'tar.gz'
};
logger_1.logger.debug(`Building URL: ${JSON.stringify(opts)}`);
const platform = (0, shellCheckPlatform_1.shellCheckPlatform)({ platform: opts.platform });
const architecture = (0, shellCheckArchitecture_1.shellCheckArchitecture)({
platform: opts.platform,
architecture: opts.architecture
});
return new node_url_1.default.URL(`${opts.baseURL}/${opts.release}/shellcheck-${opts.release}.${platform}.${architecture}.${opts.archive}`);
});
}
exports.buildURL = buildURL;
;