"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runDevBuild = exports.hasDevBuild = exports.ensureDevBuild = void 0;
const fse = require("fs-extra");
const path_1 = require("path");
const I18n_1 = require("../modules/I18n");
const Logger_1 = require("../modules/Logger");
const dev_1 = require("../Api/dev");
const requiredFiles = ['app.js', 'index.js'];
function ensureDevBuild(presentationPath) {
    return __awaiter(this, void 0, void 0, function* () {
        if (yield hasDevBuild(presentationPath)) {
            return true;
        }
        Logger_1.default.info((I18n_1.default.info('DEV_BUILD_START')));
        yield runDevBuild(presentationPath);
        Logger_1.default.info((I18n_1.default.info('DEV_BUILD_READY')));
        return false;
    });
}
exports.ensureDevBuild = ensureDevBuild;
function hasDevBuild(presentationPath) {
    return __awaiter(this, void 0, void 0, function* () {
        const devBuildFolder = path_1.join(presentationPath, 'build', 'dev');
        try {
            const devBuildFiles = yield fse.readdir(devBuildFolder);
            return requiredFiles.every(file => devBuildFiles.includes(file));
        }
        catch (err) {
            return false;
        }
    });
}
exports.hasDevBuild = hasDevBuild;
function runDevBuild(presentationPath) {
    return __awaiter(this, void 0, void 0, function* () {
        const devAction = yield dev_1.createAction(presentationPath);
        yield devAction(presentationPath, {
            template: true,
        });
    });
}
exports.runDevBuild = runDevBuild;
//# sourceMappingURL=ensureDevBuild.js.map