@vkontakte/vkui-codemods 1.0.0-beta.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +62 -19
  2. package/dist/autoDetectVKUIVersion.js +17 -7
  3. package/dist/cli.js +80 -32
  4. package/dist/codemod-helpers.js +86 -1
  5. package/dist/getAvailableCodemods.js +17 -7
  6. package/dist/index.js +45 -57
  7. package/dist/transforms/v7/action-sheet.js +16 -0
  8. package/dist/transforms/v7/alert.js +16 -0
  9. package/dist/transforms/v7/appearance-provider.js +35 -0
  10. package/dist/transforms/v7/appearance.js +45 -0
  11. package/dist/transforms/v7/banner.js +47 -0
  12. package/dist/transforms/v7/calendar.js +17 -0
  13. package/dist/transforms/v7/card-grid.js +16 -0
  14. package/dist/transforms/v7/card-scroll.js +59 -0
  15. package/dist/transforms/v7/cell-button.js +3 -15
  16. package/dist/transforms/v7/cell.js +19 -0
  17. package/dist/transforms/v7/chips-select.js +20 -0
  18. package/dist/transforms/v7/common/moveFromChildrenToLabel.js +68 -0
  19. package/dist/transforms/v7/common/remapSizePropValue.js +10 -5
  20. package/dist/transforms/v7/common/removeChildrenFromComponent.js +17 -0
  21. package/dist/transforms/v7/config-provider.js +136 -0
  22. package/dist/transforms/v7/content-card.js +21 -0
  23. package/dist/transforms/v7/counter.js +60 -0
  24. package/dist/transforms/v7/custom-scroll-view.js +21 -0
  25. package/dist/transforms/v7/custom-select.js +20 -0
  26. package/dist/transforms/v7/date-picker.js +26 -0
  27. package/dist/transforms/v7/form-item.js +2 -2
  28. package/dist/transforms/v7/form-status.js +18 -0
  29. package/dist/transforms/v7/header.js +47 -0
  30. package/dist/transforms/v7/horizontal-cell-show-more.js +33 -13
  31. package/dist/transforms/v7/horizontal-cell.js +16 -0
  32. package/dist/transforms/v7/image-overlay.js +10 -10
  33. package/dist/transforms/v7/mini-info-cell.js +18 -0
  34. package/dist/transforms/v7/modal-card.js +29 -0
  35. package/dist/transforms/v7/onboarding-tooltip.js +16 -0
  36. package/dist/transforms/v7/panel-header-back.js +18 -0
  37. package/dist/transforms/v7/panel-header-close.js +18 -0
  38. package/dist/transforms/v7/panel-header-content.js +16 -0
  39. package/dist/transforms/v7/panel-header-edit.js +19 -0
  40. package/dist/transforms/v7/panel-header-submit.js +18 -0
  41. package/dist/transforms/v7/panel-spinner.js +30 -0
  42. package/dist/transforms/v7/placeholder.js +19 -0
  43. package/dist/transforms/v7/rich-cell.js +20 -0
  44. package/dist/transforms/v7/screen-spinner.js +25 -2
  45. package/dist/transforms/v7/scroll-arrow.js +52 -0
  46. package/dist/transforms/v7/select.js +20 -0
  47. package/dist/transforms/v7/separator.js +1 -0
  48. package/dist/transforms/v7/simple-cell.js +19 -0
  49. package/dist/transforms/v7/subnavigation-bar.js +46 -0
  50. package/dist/transforms/v7/subnavigation-button.js +18 -0
  51. package/dist/transforms/v7/tabbar-item.js +16 -0
  52. package/dist/transforms/v7/tooltip.js +16 -0
  53. package/dist/transforms/v7/users-stack.js +2 -15
  54. package/package.json +9 -9
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ function transformer(file, api, options) {
8
+ var alias = options.alias;
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ActionSheet', alias).localName;
12
+ if (localName) {
13
+ (0, codemod_helpers_1.renameProp)(j, source, localName, { header: 'title', text: 'description' });
14
+ }
15
+ return source.toSource();
16
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ function transformer(file, api, options) {
8
+ var alias = options.alias;
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Alert', alias).localName;
12
+ if (localName) {
13
+ (0, codemod_helpers_1.renameProp)(j, source, localName, { header: 'title', text: 'description' });
14
+ }
15
+ return source.toSource();
16
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ var OLD_PROVIDER_NAME = 'AppearanceProvider';
8
+ var OLD_PROVIDER_PROPS_NAME = 'AppearanceProviderProps';
9
+ var NEW_PROVIDER_NAME = 'ColorSchemeProvider';
10
+ var NEW_PROVIDER_PROPS_NAME = 'ColorSchemeProviderProps';
11
+ function transformer(file, api, options) {
12
+ var alias = options.alias;
13
+ var j = api.jscodeshift;
14
+ var source = j(file.source);
15
+ var providerLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, OLD_PROVIDER_NAME, alias).localName;
16
+ var providerPropsLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, OLD_PROVIDER_PROPS_NAME, alias).localName;
17
+ if (!providerLocalName && !providerPropsLocalName) {
18
+ return source.toSource();
19
+ }
20
+ if (providerLocalName) {
21
+ var isAliasUsed = providerLocalName !== OLD_PROVIDER_NAME;
22
+ (0, codemod_helpers_1.renameImportName)(j, source, providerLocalName, NEW_PROVIDER_NAME, alias, isAliasUsed);
23
+ if (!isAliasUsed) {
24
+ (0, codemod_helpers_1.renameIdentifier)(j, source, providerLocalName, NEW_PROVIDER_NAME);
25
+ }
26
+ }
27
+ if (providerPropsLocalName) {
28
+ var isAliasUsed = providerPropsLocalName !== OLD_PROVIDER_PROPS_NAME;
29
+ (0, codemod_helpers_1.renameImportName)(j, source, providerPropsLocalName, NEW_PROVIDER_PROPS_NAME, alias, isAliasUsed);
30
+ if (!isAliasUsed) {
31
+ (0, codemod_helpers_1.renameTypeIdentifier)(j, source, providerPropsLocalName, NEW_PROVIDER_PROPS_NAME);
32
+ }
33
+ }
34
+ return source.toSource();
35
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ var OLD_APPEARANCE_NAME = 'Appearance';
8
+ var OLD_APPEARANCE_TYPE_NAME = 'AppearanceType';
9
+ var OLD_HOOK_APPEARANCE_NAME = 'useAppearance';
10
+ var NEW_APPEARANCE_NAME = 'ColorScheme';
11
+ var NEW_APPEARANCE_TYPE_NAME = 'ColorSchemeType';
12
+ var NEW_HOOK_APPEARANCE_NAME = 'useColorScheme';
13
+ function transformer(file, api, options) {
14
+ var alias = options.alias;
15
+ var j = api.jscodeshift;
16
+ var source = j(file.source);
17
+ var appearanceLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, OLD_APPEARANCE_NAME, alias).localName;
18
+ var appearanceTypeLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, OLD_APPEARANCE_TYPE_NAME, alias).localName;
19
+ var useAppearanceLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, OLD_HOOK_APPEARANCE_NAME, alias).localName;
20
+ if (!appearanceLocalName && !appearanceTypeLocalName && !useAppearanceLocalName) {
21
+ return source.toSource();
22
+ }
23
+ if (appearanceLocalName) {
24
+ var isAliasUsed = appearanceLocalName !== OLD_APPEARANCE_NAME;
25
+ (0, codemod_helpers_1.renameImportName)(j, source, appearanceLocalName, NEW_APPEARANCE_NAME, alias, isAliasUsed);
26
+ if (!isAliasUsed) {
27
+ (0, codemod_helpers_1.renameIdentifier)(j, source, appearanceLocalName, NEW_APPEARANCE_NAME);
28
+ }
29
+ }
30
+ if (appearanceTypeLocalName) {
31
+ var isAliasUsed = appearanceTypeLocalName !== OLD_APPEARANCE_TYPE_NAME;
32
+ (0, codemod_helpers_1.renameImportName)(j, source, appearanceTypeLocalName, NEW_APPEARANCE_TYPE_NAME, alias, isAliasUsed);
33
+ if (!isAliasUsed) {
34
+ (0, codemod_helpers_1.renameTypeIdentifier)(j, source, appearanceTypeLocalName, NEW_APPEARANCE_TYPE_NAME);
35
+ }
36
+ }
37
+ if (useAppearanceLocalName) {
38
+ var isAliasUsed = useAppearanceLocalName !== OLD_HOOK_APPEARANCE_NAME;
39
+ (0, codemod_helpers_1.renameImportName)(j, source, useAppearanceLocalName, NEW_HOOK_APPEARANCE_NAME, alias, isAliasUsed);
40
+ if (!isAliasUsed) {
41
+ (0, codemod_helpers_1.renameIdentifier)(j, source, useAppearanceLocalName, NEW_HOOK_APPEARANCE_NAME);
42
+ }
43
+ }
44
+ return source.toSource();
45
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ var report_1 = require("../../report");
7
+ exports.parser = 'tsx';
8
+ function transformer(file, api, options) {
9
+ var alias = options.alias;
10
+ var j = api.jscodeshift;
11
+ var source = j(file.source);
12
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Banner', alias).localName;
13
+ if (!localName) {
14
+ return source.toSource();
15
+ }
16
+ (0, codemod_helpers_1.renameProp)(j, source, localName, {
17
+ subheader: 'subtitle',
18
+ text: 'extraSubtitle',
19
+ header: 'title',
20
+ asideMode: 'after',
21
+ });
22
+ source
23
+ .find(j.JSXOpeningElement)
24
+ .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
25
+ .find(j.JSXAttribute)
26
+ .filter(function (attribute) { return attribute.node.name.name === 'after'; })
27
+ .forEach(function (attribute) {
28
+ var _a, _b;
29
+ if (((_a = attribute.node.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
30
+ if (attribute.node.value.value === 'expand') {
31
+ attribute.node.value.value = 'chevron';
32
+ }
33
+ return;
34
+ }
35
+ if (((_b = attribute.node.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
36
+ var expression = attribute.node.value.expression;
37
+ if (expression.type === 'StringLiteral') {
38
+ if (expression.value === 'expand') {
39
+ expression.value = 'chevron';
40
+ }
41
+ return;
42
+ }
43
+ }
44
+ (0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"after\" (previously \"asideMode\") prop. Need to change \"expand\" value to \"chevron\"."));
45
+ });
46
+ return source.toSource();
47
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ function transformer(file, api, options) {
8
+ var alias = options.alias;
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Calendar', alias).localName;
12
+ if (!localName) {
13
+ return source.toSource();
14
+ }
15
+ (0, codemod_helpers_1.renameProp)(j, source, localName, { onClose: 'onDoneButtonClick' });
16
+ return source.toSource();
17
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ function transformer(file, api, options) {
8
+ var alias = options.alias;
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'CardGrid', alias).localName;
12
+ if (localName) {
13
+ (0, codemod_helpers_1.renameProp)(j, source, localName, { spaced: 'padding' });
14
+ }
15
+ return source.toSource();
16
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ var report_1 = require("../../report");
7
+ exports.parser = 'tsx';
8
+ function transformer(file, api, options) {
9
+ var alias = options.alias;
10
+ var j = api.jscodeshift;
11
+ var source = j(file.source);
12
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'CardScroll', alias).localName;
13
+ if (!localName) {
14
+ return source.toSource();
15
+ }
16
+ var getValueFromAttribute = function (attribute) {
17
+ var _a, _b;
18
+ if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'BooleanLiteral') {
19
+ return attribute.value.value;
20
+ }
21
+ if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
22
+ var expression = attribute.value.expression;
23
+ if (expression.type === 'BooleanLiteral') {
24
+ return expression.value;
25
+ }
26
+ return null;
27
+ }
28
+ return true;
29
+ };
30
+ var addPropPadding = function (attributes) {
31
+ attributes === null || attributes === void 0 ? void 0 : attributes.push(j.jsxAttribute(j.jsxIdentifier('padding')));
32
+ };
33
+ source
34
+ .find(j.JSXElement, {
35
+ openingElement: {
36
+ name: {
37
+ name: localName,
38
+ },
39
+ },
40
+ })
41
+ .forEach(function (path) {
42
+ var attributes = path.node.openingElement.attributes;
43
+ var noSpacesAttr = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'noSpaces'; });
44
+ if (!noSpacesAttr) {
45
+ addPropPadding(attributes);
46
+ return;
47
+ }
48
+ var attrValue = getValueFromAttribute(noSpacesAttr);
49
+ if (attrValue === null) {
50
+ (0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"noSpaces\" prop. Need to change it to \"padding\" prop"));
51
+ return;
52
+ }
53
+ (0, codemod_helpers_1.removeAttribute)(attributes, noSpacesAttr);
54
+ if (!attrValue) {
55
+ addPropPadding(attributes);
56
+ }
57
+ });
58
+ return source.toSource();
59
+ }
@@ -13,34 +13,22 @@ function transformer(file, api, options) {
13
13
  if (!localName) {
14
14
  return source.toSource();
15
15
  }
16
+ (0, codemod_helpers_1.renameProp)(j, source, localName, { subhead: 'overTitle', expandable: 'chevron' });
16
17
  var attributeToReplace = 'mode';
17
18
  var newAttributeName = 'appearance';
18
19
  var modeToAppearance = {
19
20
  primary: 'accent',
20
21
  danger: 'negative',
21
22
  };
22
- var getValueFromAttribute = function (attribute) {
23
- var _a, _b;
24
- if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
25
- return attribute.value.value;
26
- }
27
- if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
28
- var expression = attribute.value.expression;
29
- if (expression.type === 'StringLiteral') {
30
- return expression.value;
31
- }
32
- }
33
- return null;
34
- };
35
23
  source
36
24
  .find(j.JSXElement, { openingElement: { name: { name: localName } } })
37
25
  .find(j.JSXAttribute, { name: { name: attributeToReplace } })
38
26
  .forEach(function (path) {
39
27
  var component = path.node;
40
28
  component.name.name = newAttributeName;
41
- var value = getValueFromAttribute(component);
29
+ var value = (0, codemod_helpers_1.getStringValueFromAttribute)(component);
42
30
  if (!value || !modeToAppearance[value]) {
43
- (0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: need to change 'mode' prop to 'appearance'"));
31
+ (0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: need to change 'mode' prop to 'appearance'."));
44
32
  return;
45
33
  }
46
34
  component.value = j.stringLiteral(modeToAppearance[value]);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ function transformer(file, api, options) {
8
+ var alias = options.alias;
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Cell', alias).localName;
12
+ if (localName) {
13
+ (0, codemod_helpers_1.renameProp)(j, source, localName, {
14
+ subhead: 'overTitle',
15
+ expandable: 'chevron',
16
+ });
17
+ }
18
+ return source.toSource();
19
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ var PROPS_TO_REMOVE = ['autoHideScrollbar', 'autoHideScrollbarDelay'];
8
+ function transformer(file, api, options) {
9
+ var alias = options.alias;
10
+ var j = api.jscodeshift;
11
+ var source = j(file.source);
12
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ChipsSelect', alias).localName;
13
+ if (!localName) {
14
+ return source.toSource();
15
+ }
16
+ (0, codemod_helpers_1.removeProps)(j, api, source, localName, PROPS_TO_REMOVE, function () {
17
+ return "need to remove props ".concat(PROPS_TO_REMOVE.join(', '));
18
+ });
19
+ return source.toSource();
20
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.moveFromChildrenToLabel = void 0;
4
+ var codemod_helpers_1 = require("../../../codemod-helpers");
5
+ var report_1 = require("../../../report");
6
+ var moveFromChildrenToLabel = function (api, source, localName, needToAddHideLabelProps) {
7
+ if (needToAddHideLabelProps === void 0) { needToAddHideLabelProps = false; }
8
+ var j = api.jscodeshift;
9
+ // Находим все JSX элементы с указанным именем
10
+ source
11
+ .find(j.JSXElement)
12
+ .filter(function (path) {
13
+ var elementName = path.node.openingElement.name;
14
+ return elementName.type === 'JSXIdentifier' && elementName.name === localName;
15
+ })
16
+ .forEach(function (path) {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ var element = path.node;
19
+ var openingElement = element.openingElement;
20
+ var existingLabelProp = (_a = openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'label'; });
21
+ // Получаем содержимое из props children
22
+ var childrenProp = (_b = openingElement.attributes) === null || _b === void 0 ? void 0 : _b.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'children'; });
23
+ // Получаем содержимое из обычных children
24
+ var regularChildren = (_c = element.children) === null || _c === void 0 ? void 0 : _c.filter(function (child) { return child.type !== 'JSXText' || child.value.trim() !== ''; });
25
+ var labelValue;
26
+ if (childrenProp && childrenProp.type === 'JSXAttribute') {
27
+ // Если есть проп children
28
+ if (((_d = childrenProp.value) === null || _d === void 0 ? void 0 : _d.type) === 'JSXElement') {
29
+ // Если children содержит JSX элемент, оборачиваем его в Fragment
30
+ labelValue = j.jsxExpressionContainer(j.jsxFragment(j.jsxOpeningFragment(), j.jsxClosingFragment(), [childrenProp.value]));
31
+ }
32
+ else {
33
+ labelValue = childrenProp.value;
34
+ }
35
+ (0, codemod_helpers_1.removeAttribute)(openingElement.attributes, childrenProp);
36
+ }
37
+ else if (regularChildren && regularChildren.length > 0) {
38
+ if (regularChildren.length === 1 && regularChildren[0].type === 'JSXText') {
39
+ var firstChild = regularChildren[0];
40
+ if (firstChild.type === 'JSXText') {
41
+ labelValue = j.jsxExpressionContainer(j.stringLiteral(firstChild.value.trim()));
42
+ }
43
+ }
44
+ else {
45
+ // Оборачиваем все children в Fragment
46
+ labelValue = j.jsxExpressionContainer(j.jsxFragment(j.jsxOpeningFragment(), j.jsxClosingFragment(), regularChildren));
47
+ }
48
+ }
49
+ if (labelValue) {
50
+ if (existingLabelProp) {
51
+ (0, report_1.report)(api, "Manual changes required for ".concat(localName, "'s \"label\" prop. Need to remove \"children\" prop. You can mode \"children\" value to \"label\" prop"));
52
+ return;
53
+ }
54
+ // Очищаем существующие children
55
+ element.children = [];
56
+ // Добавляем проп label
57
+ (_e = openingElement.attributes) === null || _e === void 0 ? void 0 : _e.push(j.jsxAttribute(j.jsxIdentifier('label'), labelValue));
58
+ if (needToAddHideLabelProps) {
59
+ // Добавляем проп hideLabelOnVKCom и hideLabelOnIOS, так как раньше children был скрыт визуально
60
+ // и после того как мы перенесли children в label, визуально ничего не должно измениться
61
+ (_f = openingElement.attributes) === null || _f === void 0 ? void 0 : _f.push(j.jsxAttribute(j.jsxIdentifier('hideLabelOnVKCom')));
62
+ (_g = openingElement.attributes) === null || _g === void 0 ? void 0 : _g.push(j.jsxAttribute(j.jsxIdentifier('hideLabelOnIOS')));
63
+ }
64
+ }
65
+ });
66
+ return source.toSource();
67
+ };
68
+ exports.moveFromChildrenToLabel = moveFromChildrenToLabel;
@@ -13,15 +13,20 @@ var remapSizePropValue = function (_a) {
13
13
  return attributeName === 'size';
14
14
  })
15
15
  .forEach(function (attribute) {
16
- var _a, _b;
16
+ var _a, _b, _c, _d;
17
17
  var nodeToReplaceValue;
18
- if (((_a = attribute.node.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer') {
18
+ if (((_a = attribute.node.value) === null || _a === void 0 ? void 0 : _a.type) !== 'JSXExpressionContainer' &&
19
+ ((_b = attribute.node.value) === null || _b === void 0 ? void 0 : _b.type) !== 'StringLiteral') {
20
+ return;
21
+ }
22
+ if (((_c = attribute.node.value) === null || _c === void 0 ? void 0 : _c.type) === 'JSXExpressionContainer') {
19
23
  var expression = attribute.node.value.expression;
20
- if (expression.type === 'StringLiteral') {
21
- nodeToReplaceValue = expression;
24
+ if (expression.type !== 'StringLiteral') {
25
+ return;
22
26
  }
27
+ nodeToReplaceValue = expression;
23
28
  }
24
- if (((_b = attribute.node.value) === null || _b === void 0 ? void 0 : _b.type) === 'StringLiteral') {
29
+ if (((_d = attribute.node.value) === null || _d === void 0 ? void 0 : _d.type) === 'StringLiteral') {
25
30
  nodeToReplaceValue = attribute.node.value;
26
31
  }
27
32
  if (nodeToReplaceValue) {
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeChildrenFromComponent = void 0;
4
+ var removeChildrenFromComponent = function (api, source, localName) {
5
+ var j = api.jscodeshift;
6
+ source
7
+ .find(j.JSXElement)
8
+ .filter(function (path) {
9
+ var elementName = path.node.openingElement.name;
10
+ return elementName.type === 'JSXIdentifier' && elementName.name === localName;
11
+ })
12
+ .forEach(function (path) {
13
+ var element = path.node;
14
+ element.children = [];
15
+ });
16
+ };
17
+ exports.removeChildrenFromComponent = removeChildrenFromComponent;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ var report_1 = require("../../report");
7
+ exports.parser = 'tsx';
8
+ var CONFIG_PROVIDER_NAME = 'ConfigProvider';
9
+ var CONFIG_PROVIDER_PROPS_NAME = 'ConfigProviderProps';
10
+ var CONFIG_PROVIDER_CONTEXT_NAME = 'ConfigProviderContext';
11
+ var USE_CONFIG_PROVIDER_NAME = 'useConfigProvider';
12
+ function transformer(file, api, options) {
13
+ var alias = options.alias;
14
+ var j = api.jscodeshift;
15
+ var source = j(file.source);
16
+ var configProviderName = (0, codemod_helpers_1.getImportInfo)(j, file, CONFIG_PROVIDER_NAME, alias).localName;
17
+ var configProviderPropsName = (0, codemod_helpers_1.getImportInfo)(j, file, CONFIG_PROVIDER_PROPS_NAME, alias).localName;
18
+ var configProviderContextName = (0, codemod_helpers_1.getImportInfo)(j, file, CONFIG_PROVIDER_CONTEXT_NAME, alias).localName;
19
+ var useConfigProviderName = (0, codemod_helpers_1.getImportInfo)(j, file, USE_CONFIG_PROVIDER_NAME, alias).localName;
20
+ if (!configProviderName &&
21
+ !configProviderPropsName &&
22
+ !configProviderContextName &&
23
+ !useConfigProviderName) {
24
+ return source.toSource();
25
+ }
26
+ if (configProviderName) {
27
+ handleConfigProvider(j, api, source, configProviderName);
28
+ }
29
+ if (configProviderContextName) {
30
+ handleConfigProviderContext(j, api, source, configProviderContextName);
31
+ }
32
+ if (useConfigProviderName) {
33
+ handleUseConfigProvider(j, api, source, useConfigProviderName);
34
+ }
35
+ if (configProviderPropsName) {
36
+ handleConfigProviderProps(j, api, source, configProviderPropsName);
37
+ }
38
+ return source.toSource();
39
+ }
40
+ function handleConfigProviderProps(j, api, source, localName) {
41
+ var showReport = function () {
42
+ (0, report_1.report)(api, ": \"".concat(localName, "\" has been changed. Manual changes required: perhaps need to rename \"appearance\" field to \"colorScheme\" in object."));
43
+ };
44
+ var types = source.find(j.TSTypeReference, {
45
+ typeName: { type: 'Identifier', name: localName },
46
+ });
47
+ if (types.length) {
48
+ showReport();
49
+ }
50
+ }
51
+ function handleUseConfigProvider(j, api, source, localName) {
52
+ var showReport = function () {
53
+ (0, report_1.report)(api, ": \"".concat(localName, "\" has been changed. Manual changes required: perhaps need to rename \"appearance\" field to \"colorScheme\" in result of hook."));
54
+ };
55
+ var identifiers = source.find(j.Identifier, {
56
+ name: localName,
57
+ });
58
+ if (identifiers.length) {
59
+ showReport();
60
+ }
61
+ }
62
+ function handleConfigProvider(j, api, source, localName) {
63
+ var showReport = function () {
64
+ (0, report_1.report)(api, ": \"".concat(localName, "\" has been changed. Manual changes required: perhaps need to rename \"appearance\" field to \"colorScheme\"."));
65
+ };
66
+ source
67
+ .find(j.JSXElement, {
68
+ openingElement: {
69
+ name: {
70
+ name: localName,
71
+ },
72
+ },
73
+ })
74
+ .forEach(function (path) {
75
+ var _a, _b;
76
+ var appearanceAttribute = (_a = path.node.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name && attr.name.name === 'appearance'; });
77
+ if (appearanceAttribute) {
78
+ appearanceAttribute.name = j.jsxIdentifier('colorScheme');
79
+ return;
80
+ }
81
+ var spreadAttribute = (_b = path.node.openingElement.attributes) === null || _b === void 0 ? void 0 : _b.find(function (attr) { return attr.type === 'JSXSpreadAttribute'; });
82
+ if (spreadAttribute) {
83
+ showReport();
84
+ return;
85
+ }
86
+ return;
87
+ });
88
+ }
89
+ function handleConfigProviderContext(j, api, source, localName) {
90
+ var showReport = function () {
91
+ (0, report_1.report)(api, ": \"".concat(localName, "\" has been changed. Manual changes required: perhaps need to rename \"appearance\" field to \"colorScheme\"."));
92
+ };
93
+ source
94
+ .find(j.JSXElement, {
95
+ openingElement: {
96
+ name: {
97
+ object: { name: localName },
98
+ property: { name: 'Provider' },
99
+ },
100
+ },
101
+ })
102
+ .forEach(function (path) {
103
+ var _a, _b;
104
+ var valueAttribute = (_a = path.node.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name && attr.name.name === 'value'; });
105
+ if (!valueAttribute) {
106
+ showReport();
107
+ return;
108
+ }
109
+ var valueExpression = ((_b = valueAttribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer'
110
+ ? valueAttribute.value.expression
111
+ : undefined;
112
+ if (!valueExpression) {
113
+ showReport();
114
+ return;
115
+ }
116
+ if (valueExpression.type === 'Identifier') {
117
+ showReport();
118
+ return;
119
+ }
120
+ if (valueExpression.type === 'ObjectExpression') {
121
+ var appearanceProp = valueExpression.properties.find(function (prop) {
122
+ return prop.type === 'ObjectProperty' &&
123
+ prop.key.type === 'Identifier' &&
124
+ prop.key.name === 'appearance';
125
+ });
126
+ if (!appearanceProp) {
127
+ showReport();
128
+ return;
129
+ }
130
+ appearanceProp.key = j.identifier('colorScheme');
131
+ return;
132
+ }
133
+ showReport();
134
+ return;
135
+ });
136
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ exports.default = transformer;
5
+ var codemod_helpers_1 = require("../../codemod-helpers");
6
+ exports.parser = 'tsx';
7
+ function transformer(file, api, options) {
8
+ var alias = options.alias;
9
+ var j = api.jscodeshift;
10
+ var source = j(file.source);
11
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ContentCard', alias).localName;
12
+ if (localName) {
13
+ (0, codemod_helpers_1.renameProp)(j, source, localName, {
14
+ subtitle: 'overTitle',
15
+ header: 'title',
16
+ text: 'description',
17
+ headerComponent: 'titleComponent',
18
+ });
19
+ }
20
+ return source.toSource();
21
+ }