@spartacus/schematics
Version:
Spartacus schematics
34 lines • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildMethodComment = exports.migrateMethodPropertiesDeprecation = void 0;
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
const constants_1 = require("../../../shared/constants");
const file_utils_1 = require("../../../shared/utils/file-utils");
const workspace_utils_1 = require("../../../shared/utils/workspace-utils");
function migrateMethodPropertiesDeprecation(tree, _context, methodProperties) {
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 data of methodProperties) {
// 'source' has to be reloaded after each committed change
const source = file_utils_1.getTsSourceFile(tree, sourcePath);
if (ast_utils_1.isImported(source, data.class, data.importPath)) {
const changes = file_utils_1.insertCommentAboveIdentifier(sourcePath, source, data.deprecatedNode, data.comment
? `${data.comment}\n`
: `${buildMethodComment(data.deprecatedNode, data.newNode)}\n`);
file_utils_1.commitChanges(tree, sourcePath, changes, file_utils_1.InsertDirection.RIGHT);
}
}
}
return tree;
}
exports.migrateMethodPropertiesDeprecation = migrateMethodPropertiesDeprecation;
function buildMethodComment(oldApiMethod, newApiMethod) {
const comment = `// ${constants_1.TODO_SPARTACUS} '${oldApiMethod}' has been removed.`;
return newApiMethod
? `${comment} Please try using '${newApiMethod}' instead.`
: comment;
}
exports.buildMethodComment = buildMethodComment;
//# sourceMappingURL=methods-and-properties-deprecations.js.map