"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readTestSpecs = exports.writeTestSpecs = void 0;
const utils_1 = require("@syftdata/common/lib/utils");
const fs = require("fs");
const path = require("path");
function writeTestSpecs(testFiles, outDir) {
    testFiles.forEach((file) => {
        if (file.content === undefined) {
            (0, utils_1.logError)(`:warning: Test file ${file.name} is empty. Skipping..`);
            return;
        }
        const filePath = path.join(outDir, file.path);
        const fileDir = path.dirname(filePath);
        if (!fs.existsSync(fileDir)) {
            fs.mkdirSync(fileDir, { recursive: true });
        }
        fs.writeFileSync(filePath, file.content);
    });
}
exports.writeTestSpecs = writeTestSpecs;
function readTestSpecs(input, remoteConfig) {
    const testFiles = fs
        .readdirSync(path.join(input, 'tests'), {
        withFileTypes: true
    })
        .filter((file) => file.isFile())
        .map((file) => {
        const filePath = path.join('tests', file.name);
        return {
            name: file.name,
            path: filePath,
            size: 0,
            sha: remoteConfig.shas.testSpecShas[filePath],
            content: ''
        };
    });
    return testFiles.map((file) => {
        const filePath = path.join(input, file.path);
        const fileContent = fs.readFileSync(filePath, 'utf-8');
        file.size = fileContent.length;
        file.content = fileContent;
        return file;
    });
}
exports.readTestSpecs = readTestSpecs;
