UNPKG

@skyux/packages

Version:

Handles the `ng update` command for SKY UX component libraries.

37 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceCustomProperty = replaceCustomProperty; const workspace_1 = require("@schematics/angular/utility/workspace"); const visit_project_files_1 = require("../../utility/visit-project-files"); function replaceCustomPropertyInFile(tree, filePath, context, oldCustomProperty, newCustomProperty) { const content = tree.readText(filePath); // Check if the old custom property exists in the file if (content.includes(oldCustomProperty)) { const recorder = tree.beginUpdate(filePath); // Replace all occurrences of the old custom property with the new one const updatedContent = content.replace(new RegExp(oldCustomProperty.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), newCustomProperty); // Only update if there were actual changes if (updatedContent !== content) { recorder.remove(0, content.length); recorder.insertLeft(0, updatedContent); tree.commitUpdate(recorder); context.logger.info(`Replaced ${oldCustomProperty} with ${newCustomProperty} in ${filePath}`); } } } function replaceCustomProperty(oldCustomProperty, newCustomProperty) { return async (tree, context) => { context.logger.info(`Replacing ${oldCustomProperty} with ${newCustomProperty} in all workspace files...`); const workspace = await (0, workspace_1.getWorkspace)(tree); workspace.projects.forEach((project) => { (0, visit_project_files_1.visitProjectFiles)(tree, project.sourceRoot || project.root, (filePath) => { // Process TypeScript and SCSS files if (filePath.endsWith('.ts') || filePath.endsWith('.scss')) { replaceCustomPropertyInFile(tree, filePath, context, oldCustomProperty, newCustomProperty); } }); }); context.logger.info(`Finished replacing ${oldCustomProperty} with ${newCustomProperty}`); }; } //# sourceMappingURL=replace-custom-property.js.map