UNPKG

ngx-scrolltop

Version:

Lightweight, Material Design inspired button for scroll-to-top of the page. No dependencies. Pure Angular!

35 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addDeclarationToAppModule = addDeclarationToAppModule; const core_1 = require("@angular-devkit/core"); const schematics_1 = require("@angular-devkit/schematics"); const ts = require("typescript"); const ast_utils_1 = require("../utility/ast-utils"); const change_1 = require("../utility/change"); function addDeclarationToAppModule(appModule) { return (host) => { if (!appModule) { return host; } // Part I: Construct path and read file const modulePath = (0, core_1.normalize)('/' + appModule); const text = host.read(modulePath); if (text === null) { throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`); } const sourceText = text.toString('utf-8'); const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true); // Part II: Find out, what to change const changes = (0, ast_utils_1.addSymbolToNgModuleMetadata)(source, modulePath, 'imports', 'NgxScrollTopModule', 'ngx-scrolltop'); // Part III: Apply changes 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; }; } //# sourceMappingURL=add-declaration-to-module.rule.js.map