UNPKG

@ngneat/transloco

Version:

The internationalization (i18n) library for Angular

46 lines 2.12 kB
"use strict"; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.addDeclarationToNgModule = void 0; const schematics_1 = require("@angular-devkit/schematics"); const ts = require("typescript"); const ast_utils_1 = require("./ast-utils"); const change_1 = require("./change"); const find_module_1 = require("./find-module"); function addDeclarationToNgModule(options) { return (host) => { const modulePath = options.module; if (options.skipImport || options.standalone || !modulePath) { return host; } const sourceText = host.readText(modulePath); const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true); const filePath = `/${options.path}/` + (options.flat ? '' : schematics_1.strings.dasherize(options.name) + '/') + schematics_1.strings.dasherize(options.name) + (options.type ? '.' : '') + schematics_1.strings.dasherize(options.type); const importPath = (0, find_module_1.buildRelativePath)(modulePath, filePath); const classifiedName = schematics_1.strings.classify(options.name) + schematics_1.strings.classify(options.type); const changes = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, importPath); if (options.export) { changes.push(...(0, ast_utils_1.addSymbolToNgModuleMetadata)(source, modulePath, 'exports', classifiedName)); } const recorder = host.beginUpdate(modulePath); for (const change of changes) { if (change instanceof change_1.InsertChange) { recorder.insertLeft(change.pos, change.toAdd); } } host.commitUpdate(recorder); return host; }; } exports.addDeclarationToNgModule = addDeclarationToNgModule; //# sourceMappingURL=add-declaration-to-ng-module.js.map