a2r
Version:
A2R Framework
60 lines (59 loc) • 3.22 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const telemetry_1 = require("@a2r/telemetry");
const fs_1 = require("@a2r/fs");
const colors_1 = require("../colors");
const runtimeValidator_1 = __importDefault(require("./runtimeValidator"));
const modelFileValidation_1 = __importDefault(require("./modelFileValidation"));
const onModelValidation_1 = __importDefault(require("./onModelValidation"));
const onError_1 = __importDefault(require("./onError"));
const watchFolder_1 = __importDefault(require("./watchFolder"));
const apiFileValidation_1 = __importDefault(require("./apiFileValidation"));
const onApiValidation_1 = __importDefault(require("./onApiValidation"));
const settings_1 = require("../../settings");
const watchFolders_1 = __importDefault(require("./watchFolders"));
const start = async (mainProjectPath, devServerInternalPath, additionalFolders) => {
const mainServerPath = path_1.default.resolve(mainProjectPath, settings_1.serverPath);
const pathExists = await (0, fs_1.exists)(settings_1.serverPath);
if (!pathExists) {
const error = `Provided server path doesn't exist: ${(0, colors_1.fullPath)(settings_1.serverPath)}`;
telemetry_1.out.error(error);
throw new Error(error);
}
const mainProxyPath = path_1.default.resolve(devServerInternalPath, settings_1.proxyPath);
await (0, fs_1.ensureDir)(mainProxyPath);
const modelSourcePath = path_1.default.resolve(mainServerPath, settings_1.modelPath);
const onModelWatcherReady = async (watcher, targetPath) => {
(0, colors_1.log)(`Model watcher running at path: ${(0, colors_1.fullPath)(modelSourcePath)}`);
const validator = new runtimeValidator_1.default(modelFileValidation_1.default, onModelValidation_1.default, targetPath, mainProxyPath);
watcher.on('all', (eventName, eventPath) => {
validator.addFileToQueue({ targetPath: eventPath, type: eventName });
});
};
const modelWatcherOptions = {
onError: onError_1.default,
targetPath: modelSourcePath,
onReady: onModelWatcherReady,
};
await (0, watchFolder_1.default)(modelWatcherOptions);
const apiSourcePath = path_1.default.resolve(mainServerPath, settings_1.apiPath);
const onApiWatcherReady = async (watcher, targetPath) => {
(0, colors_1.log)(`API watcher running at path: ${(0, colors_1.fullPath)(apiSourcePath)}`);
const validator = new runtimeValidator_1.default(apiFileValidation_1.default, onApiValidation_1.default, targetPath, mainProxyPath);
watcher.on('all', (eventName, eventPath) => {
validator.addFileToQueue({ targetPath: eventPath, type: eventName });
});
};
const apiWatcherOptions = {
onError: onError_1.default,
targetPath: apiSourcePath,
onReady: onApiWatcherReady,
};
await (0, watchFolder_1.default)(apiWatcherOptions);
await (0, watchFolders_1.default)(additionalFolders, mainServerPath);
};
exports.default = start;