UNPKG

a2r

Version:
58 lines (57 loc) 2.56 kB
"use strict"; 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 docker_1 = require("../docker"); const getProjectPath_1 = __importDefault(require("../getProjectPath")); const onError_1 = __importDefault(require("./onError")); const watchFolder_1 = __importDefault(require("./watchFolder")); const colors_1 = require("../colors"); /** * Watch project folder for changes * @param projectPath Project path (as in project info) * @param dockerName Docker name (as in project info) * @param dockerRootPath Docker working dir * @param pathsToIgnore Paths to ignore (node_modules is always ignored) */ const watchNextProject = async (projectPath, dockerName, dockerRootPath, pathsToIgnore) => { const mainProjectPath = await (0, getProjectPath_1.default)(); const currentProjectPath = path_1.default.resolve(mainProjectPath, projectPath); const onWatcherReady = async (watcher, targetPath) => { (0, colors_1.log)(`Watcher running for project: ${projectPath}`); watcher.on('all', async (eventName, eventPath) => { const relativePath = path_1.default.relative(targetPath, eventPath); const dockerPath = path_1.default.resolve(dockerRootPath, relativePath); if (eventName === 'add' || eventName === 'addDir' || eventName === 'change') { (0, docker_1.copyPathToDocker)(eventPath, dockerPath, dockerName); } if (eventName === 'unlink') { (0, docker_1.removeFileFromDocker)(dockerPath, dockerName); } if (eventName === 'unlinkDir') { (0, docker_1.removeFolderFromDocker)(dockerPath, dockerName); } }); }; const allPathsToIgnore = [ `${projectPath}/node_modules`, ...(pathsToIgnore || []).map((p) => `${projectPath}/${p}`), ]; const watcherOptions = { onError: onError_1.default, targetPath: currentProjectPath, onReady: onWatcherReady, options: { ignored: (eventPath) => { const relative = path_1.default.relative(currentProjectPath, eventPath); return allPathsToIgnore.some((p) => relative.indexOf(p) !== -1); }, }, }; await (0, watchFolder_1.default)(watcherOptions); }; exports.default = watchNextProject;