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.
45 lines (44 loc) • 1.82 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 style_tree_1 = require("./style-tree");
class StyleTrees {
constructor(relativeJcrPaths) {
this.relativeJcrPaths = relativeJcrPaths;
this.styleTrees = {};
}
init() {
const promises = [];
this.relativeJcrPaths.forEach(jcrPath => {
const absolutePath = path_1.default.resolve(jcrPath);
const styleTree = new style_tree_1.StyleTree(absolutePath);
promises.push(styleTree.init().then(() => {
this.styleTrees[absolutePath] = styleTree;
}));
});
return Promise.all(promises);
}
findClientlibs(absoluteFilePaths) {
const clientlibCssPathsRelative = [];
const rootDirs = Object.keys(this.styleTrees);
absoluteFilePaths.forEach(filePath => {
rootDirs.forEach(rootDir => {
if (filePath.indexOf(rootDir) === 0) {
const styleTree = this.styleTrees[rootDir];
const filePathRelative = path_1.default.relative(rootDir, filePath);
const relatedClientlibCssFilesRelative = styleTree.findClientlibs(filePathRelative);
relatedClientlibCssFilesRelative.forEach(clientlib => {
if (clientlibCssPathsRelative.indexOf(clientlib) === -1) {
clientlibCssPathsRelative.push(clientlib);
}
});
}
});
});
return clientlibCssPathsRelative;
}
}
exports.StyleTrees = StyleTrees;