UNPKG

igniteui-angular

Version:

Ignite UI for Angular is a dependency-free Angular toolkit for building modern web apps

65 lines (64 loc) 3.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const UpdateChanges_1 = require("../common/UpdateChanges"); const util_1 = require("../common/util"); // use bare specifier to escape the schematics encapsulation for the dynamic import: const import_helper_js_1 = require("igniteui-angular/migrations/common/import-helper.js"); const version = '17.1.0'; exports.default = () => (host, context) => __awaiter(void 0, void 0, void 0, function* () { context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`); const { HtmlParser } = yield (0, import_helper_js_1.nativeImport)('@angular/compiler'); const update = new UpdateChanges_1.UpdateChanges(__dirname, host, context); const changes = new Map(); const tags = ['button', 'span', 'a', 'div', 'igx-prefix', 'igx-suffix']; const type = ['igxButton']; const applyChanges = () => { for (const [path, change] of changes.entries()) { let buffer = host.read(path).toString(); change.sort((c, c1) => c.position - c1.position) .reverse() .forEach(c => buffer = c.apply(buffer)); host.overwrite(path, buffer); } }; const addChange = (path, change) => { if (changes.has(path)) { changes.get(path).push(change); } else { changes.set(path, [change]); } }; for (const path of update.templateFiles) { const components = (0, util_1.findElementNodes)((0, util_1.parseFile)(new HtmlParser(), host, path), tags); components .filter(node => (0, util_1.hasAttribute)(node, type)) .map(node => (0, util_1.getSourceOffset)(node)) .forEach(offset => { const { startTag, file, node } = offset; const { name, value } = (0, util_1.getAttribute)(node, type)[0]; const repTxt = file.content.substring(startTag.start, startTag.end - 1); const btn = `${name}="${value}"`; const iconBtn = `igxIconButton="flat"`; if (value === 'raised') { const renameType = repTxt.replace(`raised`, `contained`); addChange(file.url, new util_1.FileChange(startTag.start, renameType, repTxt, 'replace')); } else if (value === 'icon') { const removePropTxt = repTxt.replace(btn, iconBtn); addChange(file.url, new util_1.FileChange(startTag.start, removePropTxt, repTxt, 'replace')); } }); } applyChanges(); update.applyChanges(); });