UNPKG

@spartacus/schematics

Version:
40 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.migrateConstructorDeprecation = void 0; const ast_utils_1 = require("@schematics/angular/utility/ast-utils"); const file_utils_1 = require("../../../shared/utils/file-utils"); const workspace_utils_1 = require("../../../shared/utils/workspace-utils"); function migrateConstructorDeprecation(tree, context, constructorDeprecations) { context.logger.info('Checking constructor deprecations...'); const project = workspace_utils_1.getSourceRoot(tree, {}); const sourceFiles = file_utils_1.getAllTsSourceFiles(tree, project); for (const originalSource of sourceFiles) { const sourcePath = originalSource.fileName; for (const constructorDeprecation of constructorDeprecations) { if (!file_utils_1.isCandidateForConstructorDeprecation(originalSource, constructorDeprecation)) { continue; } for (const newConstructorParam of constructorDeprecation.addParams || []) { // 'source' has to be reloaded after each committed change const source = file_utils_1.getTsSourceFile(tree, sourcePath); const nodes = ast_utils_1.getSourceNodes(source); const constructorNode = file_utils_1.findConstructor(nodes); const changes = file_utils_1.addConstructorParam(source, sourcePath, constructorNode, newConstructorParam); file_utils_1.commitChanges(tree, sourcePath, changes, file_utils_1.InsertDirection.RIGHT); } for (const constructorParamToRemove of constructorDeprecation.removeParams || []) { // 'source' has to be reloaded after each committed change const source = file_utils_1.getTsSourceFile(tree, sourcePath); const nodes = ast_utils_1.getSourceNodes(source); const constructorNode = file_utils_1.findConstructor(nodes); const changes = file_utils_1.removeConstructorParam(source, sourcePath, constructorNode, constructorParamToRemove); file_utils_1.commitChanges(tree, sourcePath, changes, file_utils_1.InsertDirection.RIGHT); } } } return tree; } exports.migrateConstructorDeprecation = migrateConstructorDeprecation; //# sourceMappingURL=constructor-deprecations.js.map