@rxap/ts-morph
Version:
Provides utilities for manipulating TypeScript code using the ts-morph library. It offers a fluent API to add, modify, and remove code elements such as classes, decorators, imports, and properties in both Angular and NestJS projects. This package simplifi
67 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BuildRouteObject = BuildRouteObject;
const ts_morph_1 = require("ts-morph");
function BuildRouteObject(route) {
var _a;
const obj = {
path: w => w.quote(route.path),
};
if (route.loadChildren) {
if (typeof route.loadChildren === 'string') {
obj['loadChildren'] = `() => import('${route.loadChildren}')`;
}
else {
obj['loadChildren'] = `() => import('${route.loadChildren.import}').then((m) => m.${route.loadChildren.then})`;
}
}
if (route.loadRemoteModule) {
let entry = './routes';
let name;
if (typeof route.loadRemoteModule === 'string') {
name = route.loadRemoteModule;
}
else {
name = route.loadRemoteModule.name;
entry = (_a = route.loadRemoteModule.entry) !== null && _a !== void 0 ? _a : entry;
}
obj['loadChildren'] = `() => loadRemoteModule('${name}', '${entry}')`;
}
if (route.loadComponent) {
if (typeof route.loadComponent === 'string') {
obj['loadComponent'] = `() => import('${route.loadComponent}')`;
}
else {
obj['loadComponent'] = `() => import('${route.loadComponent.import}').then((m) => m.${route.loadComponent.then})`;
}
}
else if (route.component) {
obj['component'] = route.component;
}
if (route.outlet) {
obj['outlet'] = w => w.quote(route.outlet);
}
if (route.data) {
obj['data'] = ts_morph_1.Writers.object(Object.entries(route.data)
.reduce((acc, [key, value]) => {
if (['true', 'false'].includes(value) || typeof value === 'boolean') {
if (typeof value === 'string') {
acc[key] = w => w.quote(value);
}
else {
acc[key] = value ? 'true' : 'false';
}
}
if (typeof value === 'number') {
acc[key] = value.toString();
}
if (!isNaN(Number(value))) {
acc[key] = value;
}
acc[key] = w => w.quote(value);
return acc;
}, {}));
}
return ts_morph_1.Writers.object(obj);
}
//# sourceMappingURL=build-route-object.js.map