UNPKG

approvals

Version:

Approval Tests Library - Capturing Human Intelligence

57 lines (56 loc) 2.61 kB
"use strict"; 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.LogUtils = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const axios_1 = __importDefault(require("axios")); class LogUtils { static ensureTempDirectoryExists() { if (this.runOnce) { return this.APPROVAL_TEMP_DIRECTORY; } this.runOnce = true; if (!fs_1.default.existsSync(this.APPROVAL_TEMP_DIRECTORY)) { fs_1.default.mkdirSync(this.APPROVAL_TEMP_DIRECTORY); } this.downloadApproveAllScriptIfMissing().then(); return this.APPROVAL_TEMP_DIRECTORY; } static downloadApproveAllScriptIfMissing() { return __awaiter(this, void 0, void 0, function* () { yield this.downloadFile(`approve_all.py`); yield this.downloadFile(`remove_abandoned_files.py`); }); } static downloadFile(script) { return __awaiter(this, void 0, void 0, function* () { try { const scriptPath = path_1.default.join(this.APPROVAL_TEMP_DIRECTORY, script); if (!fs_1.default.existsSync(scriptPath)) { const githubUrl = "https://raw.githubusercontent.com/approvals/ApprovalTests.CommonScripts/refs/heads/main/"; const response = yield axios_1.default.get(`${githubUrl}${script}`); fs_1.default.writeFileSync(scriptPath, response.data); fs_1.default.chmodSync(scriptPath, 0o755); } } catch (error) { // Do nothing } }); } } exports.LogUtils = LogUtils; LogUtils.runOnce = false; LogUtils.APPROVAL_TEMP_DIRECTORY = ".approval_tests_temp";