UNPKG

aemfed

Version:

Upload front-end changes into AEM, refresh relevant resources in the page and get instant notifications from the error.log, all for easier and faster development.

107 lines (106 loc) 3.81 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const boxen = __importStar(require("boxen")); const chalk_1 = __importDefault(require("chalk")); const graceful_fs_1 = __importDefault(require("graceful-fs")); const is_installed_globally_1 = __importDefault(require("is-installed-globally")); const path_1 = __importDefault(require("path")); function getRef(message, pattern, jcrContentRoots, mapping) { if (!mapping) { mapping = { jcrPath: 1, line: 2, column: 3, filePath: -1 }; } const match = pattern.exec(message); if (match) { const ref = { jcrPath: mapping.jcrPath >= 0 ? match[mapping.jcrPath] : undefined, absoluteFilePath: mapping.filePath >= 0 ? match[mapping.filePath] : undefined, column: mapping.column >= 0 ? parseInt(match[mapping.column], 10) : undefined, line: mapping.line >= 0 ? parseInt(match[mapping.line], 10) : undefined }; setFilePath(ref, jcrContentRoots); return ref; } } exports.getRef = getRef; function getLocalSourceLine({ absoluteFilePath, relativeFilePath, line, column }) { const filePath = absoluteFilePath; if (filePath) { const fragments = [filePath]; if (line) { fragments.push(`${line}`); if (column) { fragments.push(`${column}`); } } return fragments.join(":"); } } exports.getLocalSourceLine = getLocalSourceLine; function formatMessage(ref) { if (ref) { const combined = getLocalSourceLine(ref); if (combined) { return `Local source: ${chalk_1.default.blue(combined)}`; } } } exports.formatMessage = formatMessage; function formatUpdateMessage(update) { if (update) { const message = `Update available ${chalk_1.default.dim(update.version)}${chalk_1.default.reset(" → ")}${chalk_1.default.green(update.latest)} \nRun ${chalk_1.default.cyan("npm i " + (is_installed_globally_1.default ? "-g " : "") + update.name)} to update`; const boxenOpts = { align: "center", borderColor: "yellow", borderStyle: "round", margin: 1, padding: 1 }; return boxen.default(message, boxenOpts); } } exports.formatUpdateMessage = formatUpdateMessage; function setFilePath(ref, jcrContentRoots) { const jcrPath = ref.jcrPath; if (jcrPath && !ref.absoluteFilePath) { const jcrContentRoot = jcrContentRoots.find(root => { const absolutePath = path_1.default.join(root, jcrPath); try { const stat = graceful_fs_1.default.statSync(absolutePath); if (!stat.isDirectory()) { ref.absoluteFilePath = absolutePath; return true; } } catch (err) { } return false; }); } setRelativePath(ref); return ref; } exports.setFilePath = setFilePath; function setRelativePath(ref) { if (ref.absoluteFilePath) { const currentDir = path_1.default.resolve("."); if (ref.absoluteFilePath.startsWith(currentDir)) { ref.relativeFilePath = path_1.default.relative(currentDir, ref.absoluteFilePath); } } return ref; }