@netgrif/components
Version:
Netgrif Application Engine frontend Angular components
61 lines • 2.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getViewIdSegmentFromPath = exports.constructRoutePath = exports.addImportsToAppModule = exports.updateAppModule = exports.parentViewDefined = exports.getParentPath = void 0;
const utility_functions_1 = require("../../_utility/utility-functions");
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
function getParentPath(path) {
const index = path.lastIndexOf('/');
if (index === -1) {
return '';
}
return path.substring(0, index);
}
exports.getParentPath = getParentPath;
function parentViewDefined(tree, path) {
const parentPath = getParentPath(path);
if (parentPath === '') {
return true;
}
const pathSegments = parentPath.split('/');
const naeConfig = (0, utility_functions_1.getNaeConfiguration)(tree);
let views = naeConfig.views;
for (const pathSegment of pathSegments) {
if (views === undefined) {
return false;
}
const view = views[pathSegment];
if (view === undefined) {
return false;
}
views = view.children;
}
return true;
}
exports.parentViewDefined = parentViewDefined;
function updateAppModule(tree, className, componentPath, imports = []) {
const appModule = (0, utility_functions_1.getAppModule)(tree, (0, utility_functions_1.getProjectInfo)(tree).path);
(0, utility_functions_1.commitChangesToFile)(tree, appModule.fileEntry, (0, ast_utils_1.addDeclarationToModule)(appModule.sourceFile, appModule.fileEntry.path, className, componentPath));
addImportsToAppModule(tree, imports);
}
exports.updateAppModule = updateAppModule;
function addImportsToAppModule(tree, imports) {
const projectPath = (0, utility_functions_1.getProjectInfo)(tree).path;
imports.forEach(importToAdd => {
const appModule = (0, utility_functions_1.getAppModule)(tree, projectPath);
(0, utility_functions_1.commitChangesToFile)(tree, appModule.fileEntry, (0, ast_utils_1.addImportToModule)(appModule.sourceFile, appModule.fileEntry.path, importToAdd.className, importToAdd.fileImportPath));
});
}
exports.addImportsToAppModule = addImportsToAppModule;
function constructRoutePath(pathPrefix, pathPart) {
return `${pathPrefix}${pathPrefix.length > 0 ? '/' : ''}${pathPart}`;
}
exports.constructRoutePath = constructRoutePath;
function getViewIdSegmentFromPath(path) {
const index = path.lastIndexOf('/');
if (index === -1) {
return path;
}
return path.substring(index + 1);
}
exports.getViewIdSegmentFromPath = getViewIdSegmentFromPath;
//# sourceMappingURL=view-utility-functions.js.map