UNPKG

igniteui-angular

Version:

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

93 lines (92 loc) 4.68 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 }); // 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 UpdateChanges_1 = require("../common/UpdateChanges"); const util_1 = require("../common/util"); const version = '13.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 GRID_TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid', 'igx-row-island']; const prop = ['[movable]']; const changes = new Map(); const gridsToMigrate = new Set(); 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]); } }; const getMovingColumns = (parent, columns) => { const movingNestedGroup = parent.children.filter(column => column.name === 'igx-column-group'); const movingColumns = parent.children.filter(column => column.name === 'igx-column' && (0, util_1.hasAttribute)(column, prop)); columns.push(...movingColumns); movingNestedGroup.forEach(group => { if ((0, util_1.hasAttribute)(group, prop)) { columns.push(group); } getMovingColumns(group, columns); }); }; // migrate movable on column-level to moving on grid-level for grid, tree grid, hierarchical grid and row island for (const path of update.templateFiles) { gridsToMigrate.clear(); const grids = (0, util_1.findElementNodes)((0, util_1.parseFile)(new HtmlParser(), host, path), GRID_TAGS); grids.forEach(grid => { const grid_elem = grid; const columns = []; getMovingColumns(grid_elem, columns); columns.map(node => (0, util_1.getSourceOffset)(node)) .forEach(offset => { const { startTag, file, node } = offset; const { name, value } = (0, util_1.getAttribute)(node, prop)[0]; if (value === 'true') { gridsToMigrate.add(grid_elem); } const repTxt = file.content.substring(startTag.start, startTag.end); const property = `${name}="${value}"`; const removePropTxt = repTxt.replace(property, ''); addChange(file.url, new util_1.FileChange(startTag.start, removePropTxt, repTxt, 'replace')); }); }); Array.from(gridsToMigrate).map(node => (0, util_1.getSourceOffset)(node)).forEach(offset => { const { startTag, file } = offset; addChange(file.url, new util_1.FileChange(startTag.end - 1, ' [moving]="true"')); }); } const _import = new RegExp(`@import ('|")~igniteui-angular\/lib\/core\/styles\/themes\/index('|");`, 'g'); for (const path of update.sassFiles) { const fileContent = host.read(path).toString(); const replacedString = `/* Line added via automated migrations. */ @use "igniteui-angular/theming" as *; ` + fileContent.replace(_import, ''); if (_import.test(fileContent)) { host.overwrite(path, replacedString); } } applyChanges(); update.applyChanges(); changes.clear(); });