@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
108 lines • 3.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoerceLayoutRoutes = CoerceLayoutRoutes;
const ts_morph_1 = require("ts-morph");
const coerce_imports_1 = require("../coerce-imports");
const coerce_routes_1 = require("./coerce-routes");
function CoerceLayoutRoutes(sourceFile, options = {}) {
var _a;
const { component = 'LayoutComponent', withNavigation = false, withDefaultHeader = true, withStatusCheckGuard = false, withUserTheme = true, } = options;
const obj = {
path: w => w.quote(''),
component,
children: w => {
w.write('[');
w.indent(() => {
ts_morph_1.Writers.object({
path: w => w.quote('**'),
redirectTo: w => w.quote('')
})(w);
});
w.write(']');
},
providers: w => {
w.write('[');
w.indent(() => {
if (withUserTheme) {
w.writeLine('provideUserTheme(),');
}
w.write('provideLayout(');
if (withNavigation) {
w.newLine();
w.indent(() => {
w.write('withNavigationConfig(APP_NAVIGATION)');
w.write(',');
});
}
if (withDefaultHeader) {
w.newLine();
w.indent(() => {
w.write('withDefaultHeaderComponent()');
w.write(',');
});
}
if (withDefaultHeader || withNavigation) {
w.newLine();
}
w.write(')');
});
w.write(']');
}
};
(0, coerce_imports_1.CoerceImports)(sourceFile, {
namedImports: ['provideLayout'],
moduleSpecifier: '@rxap/layout'
});
if (withUserTheme) {
(0, coerce_imports_1.CoerceImports)(sourceFile, {
namedImports: ['provideUserTheme'],
moduleSpecifier: '@rxap/ngx-user',
});
}
if (withStatusCheckGuard) {
obj['canActivateChild'] = '[StatusCheckGuard]';
(0, coerce_imports_1.CoerceImports)(sourceFile, [
{
namedImports: ['StatusCheckGuard'],
moduleSpecifier: '@rxap/ngx-status-check'
}
]);
}
if (withNavigation) {
(0, coerce_imports_1.CoerceImports)(sourceFile, [
{
namedImports: ['APP_NAVIGATION'],
moduleSpecifier: './app.navigation'
},
{
namedImports: ['withNavigationConfig'],
moduleSpecifier: '@rxap/layout'
}
]);
}
if (withDefaultHeader) {
(0, coerce_imports_1.CoerceImports)(sourceFile, {
namedImports: ['withDefaultHeaderComponent'],
moduleSpecifier: '@rxap/layout'
});
}
(0, coerce_imports_1.CoerceImports)(sourceFile, {
namedImports: [component],
moduleSpecifier: '@rxap/layout'
});
const variableDeclaration = (0, coerce_routes_1.CoerceRoutes)(sourceFile, Object.assign(Object.assign({}, options), { initializer: (_a = options.initializer) !== null && _a !== void 0 ? _a : (w => {
w.writeLine('[');
w.indent(() => {
ts_morph_1.Writers.object(obj)(w);
w.write(',');
});
ts_morph_1.Writers.object({
path: w => w.quote('**'),
redirectTo: w => w.quote('')
})(w);
w.newLine();
w.write(']');
}) }));
return variableDeclaration;
}
//# sourceMappingURL=coerce-layout-routes.js.map