@atlaskit/codemod-cli 0.15.0 → 0.16.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 (29) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/main.js +1 -1
  3. package/dist/cjs/presets/index.js +2 -1
  4. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +118 -0
  5. package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +58 -0
  6. package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +45 -0
  7. package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +35 -0
  8. package/dist/es2019/presets/index.js +2 -1
  9. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +86 -0
  10. package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +44 -0
  11. package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +19 -0
  12. package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +29 -0
  13. package/dist/esm/main.js +1 -1
  14. package/dist/esm/presets/index.js +2 -1
  15. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +112 -0
  16. package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +52 -0
  17. package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +38 -0
  18. package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +29 -0
  19. package/dist/types/presets/index.d.ts +1 -0
  20. package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +3 -0
  21. package/dist/types/presets/migrate-to-new-buttons/codemods/next-split-imports.d.ts +3 -0
  22. package/dist/types/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -0
  23. package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +14 -0
  24. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  25. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +3 -0
  26. package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-split-imports.d.ts +3 -0
  27. package/dist/types-ts4.5/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -0
  28. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +14 -0
  29. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#41699](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41699) [`436fa9358ae`](https://bitbucket.org/atlassian/atlassian-frontend/commits/436fa9358ae) - Introduces new codemod “migrate-to-new-buttons” to automate the new button migration.
8
+
3
9
  ## 0.15.0
4
10
 
5
11
  ### Minor Changes
package/dist/cjs/main.js CHANGED
@@ -298,7 +298,7 @@ function _main() {
298
298
  case 4:
299
299
  _yield$parseArgs = _context5.sent;
300
300
  packages = _yield$parseArgs.packages;
301
- _process$env$_PACKAGE = "0.15.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.16.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
302
302
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
303
303
  if (packages && packages.length > 0) {
304
304
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -10,12 +10,13 @@ require("./styled-to-emotion/styled-to-emotion");
10
10
  require("./theme-to-design-tokens/theme-to-design-tokens");
11
11
  require("./theme-remove-deprecated-mixins/theme-remove-deprecated-mixins");
12
12
  require("./css-to-design-tokens/css-to-design-tokens");
13
+ require("./migrate-to-new-buttons/migrate-to-new-buttons");
13
14
  /**
14
15
  * Manually import presets to make sure typescript includes them
15
16
  * in the final bundle
16
17
  */
17
18
 
18
- var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens'].map(function (preset) {
19
+ var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens', 'migrate-to-new-buttons'].map(function (preset) {
19
20
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
20
21
  });
21
22
  var _default = exports.default = presets;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _constants = require("../utils/constants");
8
+ var transformer = function transformer(file, api) {
9
+ var j = api.jscodeshift;
10
+ var fileSource = j(file.source);
11
+ var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
12
+ return path.node.source.value === _constants.entryPointsMapping.Button || path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
13
+ });
14
+ if (!buttonImports.length) {
15
+ return fileSource.toSource();
16
+ }
17
+ var defaultButtonImport = buttonImports.find(j.Specifier).filter(function (path) {
18
+ return path.node.type === 'ImportDefaultSpecifier';
19
+ });
20
+ if (defaultButtonImport.length === 0) {
21
+ return fileSource.toSource();
22
+ }
23
+ var specifierIdentifier = defaultButtonImport.get(0).node.local.name;
24
+ var attributes = fileSource.find(j.JSXElement).filter(function (path) {
25
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
26
+ }).find(j.JSXAttribute);
27
+ var hasCustomComponent = attributes.filter(function (attribute) {
28
+ return attribute.node.name.name === 'component';
29
+ }).length > 0;
30
+ var hasCssProp = attributes.filter(function (attribute) {
31
+ return attribute.node.name.name === 'css';
32
+ }).length > 0;
33
+ if (hasCustomComponent || hasCssProp) {
34
+ return fileSource.toSource(_constants.PRINT_SETTINGS);
35
+ }
36
+ var checkIfVariantAlreadyImported = function checkIfVariantAlreadyImported(variant) {
37
+ return fileSource.find(j.ImportDeclaration).filter(function (path) {
38
+ return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT;
39
+ }).find(j.ImportSpecifier).filter(function (path) {
40
+ return path.node.imported.name === variant;
41
+ }).length > 0;
42
+ };
43
+ var generateNewElement = function generateNewElement(variant, element) {
44
+ var attributes = element.openingElement.attributes;
45
+ if (variant === _constants.NEW_BUTTON_VARIANTS.icon.as) {
46
+ var attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
47
+ return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
48
+ });
49
+ if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
50
+ attr[0].name.name = 'icon';
51
+ }
52
+ }
53
+ // self closing if it's an icon button or icon link button
54
+ var isSelfClosing = variant === _constants.NEW_BUTTON_VARIANTS.icon.as || variant === _constants.NEW_BUTTON_VARIANTS.linkIcon.as;
55
+ return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
56
+ };
57
+ var hasLinkIconButton = checkIfVariantAlreadyImported(_constants.NEW_BUTTON_VARIANTS.linkIcon.import);
58
+ var hasLinkButton = checkIfVariantAlreadyImported(_constants.NEW_BUTTON_VARIANTS.link.import);
59
+ var hasIconButton = checkIfVariantAlreadyImported(_constants.NEW_BUTTON_VARIANTS.icon.import);
60
+ var allButtons = fileSource.find(j.JSXElement).filter(function (path) {
61
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
62
+ });
63
+ allButtons.forEach(function (element) {
64
+ var _element$value$childr, _element$value$childr2;
65
+ var attributes = element.value.openingElement.attributes;
66
+ if (!attributes) {
67
+ return;
68
+ }
69
+ var buttonAttributes = attributes.map(function (node) {
70
+ return node.type === 'JSXAttribute' && node.name.name;
71
+ });
72
+ var hasHref = buttonAttributes.includes('href');
73
+ var hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
74
+ var isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
75
+ var isLinkButton = hasHref && !isLinkIconButton;
76
+ var isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
77
+ if (isLinkIconButton) {
78
+ hasLinkIconButton = true;
79
+ j(element).replaceWith(generateNewElement(_constants.NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
80
+ }
81
+ if (isIconButton) {
82
+ hasIconButton = true;
83
+ j(element).replaceWith(generateNewElement(_constants.NEW_BUTTON_VARIANTS.icon.as, element.value));
84
+ }
85
+ if (isLinkButton) {
86
+ hasLinkButton = true;
87
+ j(element).replaceWith(generateNewElement(_constants.NEW_BUTTON_VARIANTS.link.as, element.value));
88
+ }
89
+ });
90
+ var specifiers = [];
91
+ if (hasLinkButton) {
92
+ specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.link.import), j.identifier(_constants.NEW_BUTTON_VARIANTS.link.as)));
93
+ }
94
+ if (hasIconButton) {
95
+ specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.icon.import), j.identifier(_constants.NEW_BUTTON_VARIANTS.icon.as)));
96
+ }
97
+ if (hasLinkIconButton) {
98
+ specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.linkIcon.import), j.identifier(_constants.NEW_BUTTON_VARIANTS.linkIcon.as)));
99
+ }
100
+ var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
101
+ return path.node.source.value === _constants.NEW_BUTTON_ENTRY_POINT || path.node.source.value === _constants.entryPointsMapping.Button;
102
+ });
103
+ var leftButtons = fileSource.find(j.JSXElement).filter(function (path) {
104
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
105
+ }).length > 0 || fileSource.find(j.CallExpression).filter(function (path) {
106
+ return path.node.arguments.map(function (argument) {
107
+ return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
108
+ }).includes(specifierIdentifier);
109
+ }).length > 0;
110
+ if (specifiers.length || leftButtons) {
111
+ if (leftButtons) {
112
+ specifiers.push(j.importSpecifier(j.identifier(_constants.NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
113
+ }
114
+ oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(_constants.NEW_BUTTON_ENTRY_POINT)));
115
+ }
116
+ return fileSource.toSource(_constants.PRINT_SETTINGS);
117
+ };
118
+ var _default = exports.default = transformer;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _constants = require("../utils/constants");
8
+ var transformer = function transformer(file, api) {
9
+ var j = api.jscodeshift;
10
+ var fileSource = j(file.source);
11
+ var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
12
+ var _path$node$source$val;
13
+ return (_path$node$source$val = path.node.source.value) === null || _path$node$source$val === void 0 ? void 0 : _path$node$source$val.includes('@atlaskit/button');
14
+ });
15
+ if (!buttonImports.length || buttonImports.every(function (node) {
16
+ return node.node.source.value !== '@atlaskit/button';
17
+ })) {
18
+ return fileSource.toSource(_constants.PRINT_SETTINGS);
19
+ }
20
+ buttonImports.forEach(function (node) {
21
+ var specifiers = node.node.specifiers;
22
+ var defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(function (specifier) {
23
+ return specifier.type === 'ImportDefaultSpecifier';
24
+ });
25
+ if (defaultSpecifier && defaultSpecifier.local) {
26
+ var defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(_constants.entryPointsMapping.Button));
27
+ j(node).insertAfter(defaultButtonImport);
28
+ }
29
+ var defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
30
+ return specifier.importKind === 'type';
31
+ });
32
+ if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
33
+ var typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
34
+ j(node).insertAfter(typeImport);
35
+ }
36
+ var valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
37
+ return specifier.type === 'ImportSpecifier';
38
+ });
39
+ var otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
40
+ return _constants.BUTTON_TYPES.includes(specifier.imported.name);
41
+ });
42
+ if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
43
+ var _typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
44
+ j(node).insertAfter(_typeImport);
45
+ }
46
+ if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
47
+ valueSpecifiers.forEach(function (specifier) {
48
+ if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && _constants.entryPointsMapping[specifier.imported.name]) {
49
+ var newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(_constants.entryPointsMapping[specifier.imported.name]));
50
+ j(node).insertAfter(newImport);
51
+ }
52
+ });
53
+ }
54
+ j(node).remove();
55
+ });
56
+ return fileSource.toSource(_constants.PRINT_SETTINGS);
57
+ };
58
+ var _default = exports.default = transformer;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _nextSplitImports = _interopRequireDefault(require("./codemods/next-split-imports"));
12
+ var _nextMigrateToNewButtonVariants = _interopRequireDefault(require("./codemods/next-migrate-to-new-button-variants"));
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function transformer(_x, _x2) {
16
+ return _transformer.apply(this, arguments);
17
+ }
18
+ function _transformer() {
19
+ _transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
20
+ var transformers, src;
21
+ return _regenerator.default.wrap(function _callee$(_context) {
22
+ while (1) switch (_context.prev = _context.next) {
23
+ case 0:
24
+ transformers = [_nextSplitImports.default, _nextMigrateToNewButtonVariants.default];
25
+ src = file.source;
26
+ transformers.forEach(function (transformer) {
27
+ if (typeof src === 'undefined') {
28
+ return;
29
+ }
30
+ var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
31
+ source: src
32
+ }), api);
33
+ if (nextSrc) {
34
+ src = nextSrc;
35
+ }
36
+ });
37
+ return _context.abrupt("return", src);
38
+ case 4:
39
+ case "end":
40
+ return _context.stop();
41
+ }
42
+ }, _callee);
43
+ }));
44
+ return _transformer.apply(this, arguments);
45
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.entryPointsMapping = exports.PRINT_SETTINGS = exports.NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_ENTRY_POINT = exports.BUTTON_TYPES = void 0;
7
+ var PRINT_SETTINGS = exports.PRINT_SETTINGS = {
8
+ quote: 'single'
9
+ };
10
+ var NEW_BUTTON_VARIANTS = exports.NEW_BUTTON_VARIANTS = {
11
+ default: {
12
+ import: 'UNSAFE_BUTTON',
13
+ as: 'Button'
14
+ },
15
+ link: {
16
+ import: 'UNSAFE_LINK_BUTTON',
17
+ as: 'LinkButton'
18
+ },
19
+ icon: {
20
+ import: 'UNSAFE_ICON_BUTTON',
21
+ as: 'IconButton'
22
+ },
23
+ linkIcon: {
24
+ import: 'UNSAFE_LINK_ICON_BUTTON',
25
+ as: 'LinkIconButton'
26
+ }
27
+ };
28
+ var NEW_BUTTON_ENTRY_POINT = exports.NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
29
+ var entryPointsMapping = exports.entryPointsMapping = {
30
+ Button: '@atlaskit/button/standard-button',
31
+ LoadingButton: '@atlaskit/button/loading-button',
32
+ ButtonGroup: '@atlaskit/button/button-group',
33
+ CustomThemeButton: '@atlaskit/button/custom-theme-button'
34
+ };
35
+ var BUTTON_TYPES = exports.BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
@@ -8,5 +8,6 @@ import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-to-design-tokens/theme-to-design-tokens';
9
9
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
10
10
  import './css-to-design-tokens/css-to-design-tokens';
11
- const presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
11
+ import './migrate-to-new-buttons/migrate-to-new-buttons';
12
+ const presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens', 'migrate-to-new-buttons'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
12
13
  export default presets;
@@ -0,0 +1,86 @@
1
+ import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
2
+ const transformer = (file, api) => {
3
+ const j = api.jscodeshift;
4
+ const fileSource = j(file.source);
5
+ const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
6
+ if (!buttonImports.length) {
7
+ return fileSource.toSource();
8
+ }
9
+ const defaultButtonImport = buttonImports.find(j.Specifier).filter(path => path.node.type === 'ImportDefaultSpecifier');
10
+ if (defaultButtonImport.length === 0) {
11
+ return fileSource.toSource();
12
+ }
13
+ const specifierIdentifier = defaultButtonImport.get(0).node.local.name;
14
+ const attributes = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier).find(j.JSXAttribute);
15
+ const hasCustomComponent = attributes.filter(attribute => attribute.node.name.name === 'component').length > 0;
16
+ const hasCssProp = attributes.filter(attribute => attribute.node.name.name === 'css').length > 0;
17
+ if (hasCustomComponent || hasCssProp) {
18
+ return fileSource.toSource(PRINT_SETTINGS);
19
+ }
20
+ const checkIfVariantAlreadyImported = variant => fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT).find(j.ImportSpecifier).filter(path => path.node.imported.name === variant).length > 0;
21
+ const generateNewElement = (variant, element) => {
22
+ const {
23
+ attributes
24
+ } = element.openingElement;
25
+ if (variant === NEW_BUTTON_VARIANTS.icon.as) {
26
+ const attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter'));
27
+ if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
28
+ attr[0].name.name = 'icon';
29
+ }
30
+ }
31
+ // self closing if it's an icon button or icon link button
32
+ const isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
33
+ return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
34
+ };
35
+ let hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import);
36
+ let hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import);
37
+ let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import);
38
+ const allButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier);
39
+ allButtons.forEach(element => {
40
+ var _element$value$childr, _element$value$childr2;
41
+ const {
42
+ attributes
43
+ } = element.value.openingElement;
44
+ if (!attributes) {
45
+ return;
46
+ }
47
+ const buttonAttributes = attributes.map(node => node.type === 'JSXAttribute' && node.name.name);
48
+ const hasHref = buttonAttributes.includes('href');
49
+ const hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
50
+ const isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
51
+ const isLinkButton = hasHref && !isLinkIconButton;
52
+ const isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
53
+ if (isLinkIconButton) {
54
+ hasLinkIconButton = true;
55
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
56
+ }
57
+ if (isIconButton) {
58
+ hasIconButton = true;
59
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value));
60
+ }
61
+ if (isLinkButton) {
62
+ hasLinkButton = true;
63
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value));
64
+ }
65
+ });
66
+ const specifiers = [];
67
+ if (hasLinkButton) {
68
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.link.import), j.identifier(NEW_BUTTON_VARIANTS.link.as)));
69
+ }
70
+ if (hasIconButton) {
71
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.icon.import), j.identifier(NEW_BUTTON_VARIANTS.icon.as)));
72
+ }
73
+ if (hasLinkIconButton) {
74
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.linkIcon.import), j.identifier(NEW_BUTTON_VARIANTS.linkIcon.as)));
75
+ }
76
+ const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button);
77
+ const leftButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier).length > 0 || fileSource.find(j.CallExpression).filter(path => path.node.arguments.map(argument => argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name)).includes(specifierIdentifier)).length > 0;
78
+ if (specifiers.length || leftButtons) {
79
+ if (leftButtons) {
80
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
81
+ }
82
+ oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
83
+ }
84
+ return fileSource.toSource(PRINT_SETTINGS);
85
+ };
86
+ export default transformer;
@@ -0,0 +1,44 @@
1
+ import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES } from '../utils/constants';
2
+ const transformer = (file, api) => {
3
+ const j = api.jscodeshift;
4
+ const fileSource = j(file.source);
5
+ const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => {
6
+ var _path$node$source$val;
7
+ return (_path$node$source$val = path.node.source.value) === null || _path$node$source$val === void 0 ? void 0 : _path$node$source$val.includes('@atlaskit/button');
8
+ });
9
+ if (!buttonImports.length || buttonImports.every(node => node.node.source.value !== '@atlaskit/button')) {
10
+ return fileSource.toSource(PRINT_SETTINGS);
11
+ }
12
+ buttonImports.forEach(node => {
13
+ const {
14
+ specifiers
15
+ } = node.node;
16
+ const defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(specifier => specifier.type === 'ImportDefaultSpecifier');
17
+ if (defaultSpecifier && defaultSpecifier.local) {
18
+ const defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
19
+ j(node).insertAfter(defaultButtonImport);
20
+ }
21
+ const defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.importKind === 'type');
22
+ if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
23
+ const typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
24
+ j(node).insertAfter(typeImport);
25
+ }
26
+ const valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.type === 'ImportSpecifier');
27
+ const otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(specifier => BUTTON_TYPES.includes(specifier.imported.name));
28
+ if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
29
+ const typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
30
+ j(node).insertAfter(typeImport);
31
+ }
32
+ if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
33
+ valueSpecifiers.forEach(specifier => {
34
+ if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && entryPointsMapping[specifier.imported.name]) {
35
+ const newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(entryPointsMapping[specifier.imported.name]));
36
+ j(node).insertAfter(newImport);
37
+ }
38
+ });
39
+ }
40
+ j(node).remove();
41
+ });
42
+ return fileSource.toSource(PRINT_SETTINGS);
43
+ };
44
+ export default transformer;
@@ -0,0 +1,19 @@
1
+ import splitImportsTransformer from './codemods/next-split-imports';
2
+ import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
3
+ export default async function transformer(file, api) {
4
+ const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer];
5
+ let src = file.source;
6
+ transformers.forEach(transformer => {
7
+ if (typeof src === 'undefined') {
8
+ return;
9
+ }
10
+ const nextSrc = transformer({
11
+ ...file,
12
+ source: src
13
+ }, api);
14
+ if (nextSrc) {
15
+ src = nextSrc;
16
+ }
17
+ });
18
+ return src;
19
+ }
@@ -0,0 +1,29 @@
1
+ export const PRINT_SETTINGS = {
2
+ quote: 'single'
3
+ };
4
+ export const NEW_BUTTON_VARIANTS = {
5
+ default: {
6
+ import: 'UNSAFE_BUTTON',
7
+ as: 'Button'
8
+ },
9
+ link: {
10
+ import: 'UNSAFE_LINK_BUTTON',
11
+ as: 'LinkButton'
12
+ },
13
+ icon: {
14
+ import: 'UNSAFE_ICON_BUTTON',
15
+ as: 'IconButton'
16
+ },
17
+ linkIcon: {
18
+ import: 'UNSAFE_LINK_ICON_BUTTON',
19
+ as: 'LinkIconButton'
20
+ }
21
+ };
22
+ export const NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
23
+ export const entryPointsMapping = {
24
+ Button: '@atlaskit/button/standard-button',
25
+ LoadingButton: '@atlaskit/button/loading-button',
26
+ ButtonGroup: '@atlaskit/button/button-group',
27
+ CustomThemeButton: '@atlaskit/button/custom-theme-button'
28
+ };
29
+ export const BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
package/dist/esm/main.js CHANGED
@@ -291,7 +291,7 @@ function _main() {
291
291
  case 4:
292
292
  _yield$parseArgs = _context5.sent;
293
293
  packages = _yield$parseArgs.packages;
294
- _process$env$_PACKAGE = "0.15.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
294
+ _process$env$_PACKAGE = "0.16.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
295
295
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
296
296
  if (packages && packages.length > 0) {
297
297
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -8,7 +8,8 @@ import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-to-design-tokens/theme-to-design-tokens';
9
9
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
10
10
  import './css-to-design-tokens/css-to-design-tokens';
11
- var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens'].map(function (preset) {
11
+ import './migrate-to-new-buttons/migrate-to-new-buttons';
12
+ var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens', 'migrate-to-new-buttons'].map(function (preset) {
12
13
  return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
13
14
  });
14
15
  export default presets;
@@ -0,0 +1,112 @@
1
+ import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
2
+ var transformer = function transformer(file, api) {
3
+ var j = api.jscodeshift;
4
+ var fileSource = j(file.source);
5
+ var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
6
+ return path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT;
7
+ });
8
+ if (!buttonImports.length) {
9
+ return fileSource.toSource();
10
+ }
11
+ var defaultButtonImport = buttonImports.find(j.Specifier).filter(function (path) {
12
+ return path.node.type === 'ImportDefaultSpecifier';
13
+ });
14
+ if (defaultButtonImport.length === 0) {
15
+ return fileSource.toSource();
16
+ }
17
+ var specifierIdentifier = defaultButtonImport.get(0).node.local.name;
18
+ var attributes = fileSource.find(j.JSXElement).filter(function (path) {
19
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
20
+ }).find(j.JSXAttribute);
21
+ var hasCustomComponent = attributes.filter(function (attribute) {
22
+ return attribute.node.name.name === 'component';
23
+ }).length > 0;
24
+ var hasCssProp = attributes.filter(function (attribute) {
25
+ return attribute.node.name.name === 'css';
26
+ }).length > 0;
27
+ if (hasCustomComponent || hasCssProp) {
28
+ return fileSource.toSource(PRINT_SETTINGS);
29
+ }
30
+ var checkIfVariantAlreadyImported = function checkIfVariantAlreadyImported(variant) {
31
+ return fileSource.find(j.ImportDeclaration).filter(function (path) {
32
+ return path.node.source.value === NEW_BUTTON_ENTRY_POINT;
33
+ }).find(j.ImportSpecifier).filter(function (path) {
34
+ return path.node.imported.name === variant;
35
+ }).length > 0;
36
+ };
37
+ var generateNewElement = function generateNewElement(variant, element) {
38
+ var attributes = element.openingElement.attributes;
39
+ if (variant === NEW_BUTTON_VARIANTS.icon.as) {
40
+ var attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attribute) {
41
+ return attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter');
42
+ });
43
+ if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
44
+ attr[0].name.name = 'icon';
45
+ }
46
+ }
47
+ // self closing if it's an icon button or icon link button
48
+ var isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
49
+ return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
50
+ };
51
+ var hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import);
52
+ var hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import);
53
+ var hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import);
54
+ var allButtons = fileSource.find(j.JSXElement).filter(function (path) {
55
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
56
+ });
57
+ allButtons.forEach(function (element) {
58
+ var _element$value$childr, _element$value$childr2;
59
+ var attributes = element.value.openingElement.attributes;
60
+ if (!attributes) {
61
+ return;
62
+ }
63
+ var buttonAttributes = attributes.map(function (node) {
64
+ return node.type === 'JSXAttribute' && node.name.name;
65
+ });
66
+ var hasHref = buttonAttributes.includes('href');
67
+ var hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
68
+ var isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
69
+ var isLinkButton = hasHref && !isLinkIconButton;
70
+ var isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
71
+ if (isLinkIconButton) {
72
+ hasLinkIconButton = true;
73
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
74
+ }
75
+ if (isIconButton) {
76
+ hasIconButton = true;
77
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value));
78
+ }
79
+ if (isLinkButton) {
80
+ hasLinkButton = true;
81
+ j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value));
82
+ }
83
+ });
84
+ var specifiers = [];
85
+ if (hasLinkButton) {
86
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.link.import), j.identifier(NEW_BUTTON_VARIANTS.link.as)));
87
+ }
88
+ if (hasIconButton) {
89
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.icon.import), j.identifier(NEW_BUTTON_VARIANTS.icon.as)));
90
+ }
91
+ if (hasLinkIconButton) {
92
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.linkIcon.import), j.identifier(NEW_BUTTON_VARIANTS.linkIcon.as)));
93
+ }
94
+ var oldButtonImport = fileSource.find(j.ImportDeclaration).filter(function (path) {
95
+ return path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button;
96
+ });
97
+ var leftButtons = fileSource.find(j.JSXElement).filter(function (path) {
98
+ return path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier;
99
+ }).length > 0 || fileSource.find(j.CallExpression).filter(function (path) {
100
+ return path.node.arguments.map(function (argument) {
101
+ return argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name);
102
+ }).includes(specifierIdentifier);
103
+ }).length > 0;
104
+ if (specifiers.length || leftButtons) {
105
+ if (leftButtons) {
106
+ specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
107
+ }
108
+ oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
109
+ }
110
+ return fileSource.toSource(PRINT_SETTINGS);
111
+ };
112
+ export default transformer;
@@ -0,0 +1,52 @@
1
+ import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES } from '../utils/constants';
2
+ var transformer = function transformer(file, api) {
3
+ var j = api.jscodeshift;
4
+ var fileSource = j(file.source);
5
+ var buttonImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
6
+ var _path$node$source$val;
7
+ return (_path$node$source$val = path.node.source.value) === null || _path$node$source$val === void 0 ? void 0 : _path$node$source$val.includes('@atlaskit/button');
8
+ });
9
+ if (!buttonImports.length || buttonImports.every(function (node) {
10
+ return node.node.source.value !== '@atlaskit/button';
11
+ })) {
12
+ return fileSource.toSource(PRINT_SETTINGS);
13
+ }
14
+ buttonImports.forEach(function (node) {
15
+ var specifiers = node.node.specifiers;
16
+ var defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(function (specifier) {
17
+ return specifier.type === 'ImportDefaultSpecifier';
18
+ });
19
+ if (defaultSpecifier && defaultSpecifier.local) {
20
+ var defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
21
+ j(node).insertAfter(defaultButtonImport);
22
+ }
23
+ var defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
24
+ return specifier.importKind === 'type';
25
+ });
26
+ if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
27
+ var typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
28
+ j(node).insertAfter(typeImport);
29
+ }
30
+ var valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(function (specifier) {
31
+ return specifier.type === 'ImportSpecifier';
32
+ });
33
+ var otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(function (specifier) {
34
+ return BUTTON_TYPES.includes(specifier.imported.name);
35
+ });
36
+ if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
37
+ var _typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
38
+ j(node).insertAfter(_typeImport);
39
+ }
40
+ if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
41
+ valueSpecifiers.forEach(function (specifier) {
42
+ if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && entryPointsMapping[specifier.imported.name]) {
43
+ var newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(entryPointsMapping[specifier.imported.name]));
44
+ j(node).insertAfter(newImport);
45
+ }
46
+ });
47
+ }
48
+ j(node).remove();
49
+ });
50
+ return fileSource.toSource(PRINT_SETTINGS);
51
+ };
52
+ export default transformer;
@@ -0,0 +1,38 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ import splitImportsTransformer from './codemods/next-split-imports';
7
+ import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
8
+ export default function transformer(_x, _x2) {
9
+ return _transformer.apply(this, arguments);
10
+ }
11
+ function _transformer() {
12
+ _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api) {
13
+ var transformers, src;
14
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
15
+ while (1) switch (_context.prev = _context.next) {
16
+ case 0:
17
+ transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer];
18
+ src = file.source;
19
+ transformers.forEach(function (transformer) {
20
+ if (typeof src === 'undefined') {
21
+ return;
22
+ }
23
+ var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
24
+ source: src
25
+ }), api);
26
+ if (nextSrc) {
27
+ src = nextSrc;
28
+ }
29
+ });
30
+ return _context.abrupt("return", src);
31
+ case 4:
32
+ case "end":
33
+ return _context.stop();
34
+ }
35
+ }, _callee);
36
+ }));
37
+ return _transformer.apply(this, arguments);
38
+ }
@@ -0,0 +1,29 @@
1
+ export var PRINT_SETTINGS = {
2
+ quote: 'single'
3
+ };
4
+ export var NEW_BUTTON_VARIANTS = {
5
+ default: {
6
+ import: 'UNSAFE_BUTTON',
7
+ as: 'Button'
8
+ },
9
+ link: {
10
+ import: 'UNSAFE_LINK_BUTTON',
11
+ as: 'LinkButton'
12
+ },
13
+ icon: {
14
+ import: 'UNSAFE_ICON_BUTTON',
15
+ as: 'IconButton'
16
+ },
17
+ linkIcon: {
18
+ import: 'UNSAFE_LINK_ICON_BUTTON',
19
+ as: 'LinkIconButton'
20
+ }
21
+ };
22
+ export var NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
23
+ export var entryPointsMapping = {
24
+ Button: '@atlaskit/button/standard-button',
25
+ LoadingButton: '@atlaskit/button/loading-button',
26
+ ButtonGroup: '@atlaskit/button/button-group',
27
+ CustomThemeButton: '@atlaskit/button/custom-theme-button'
28
+ };
29
+ export var BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
@@ -6,5 +6,6 @@ import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-to-design-tokens/theme-to-design-tokens';
7
7
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
8
8
  import './css-to-design-tokens/css-to-design-tokens';
9
+ import './migrate-to-new-buttons/migrate-to-new-buttons';
9
10
  declare const presets: string[];
10
11
  export default presets;
@@ -0,0 +1,3 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API) => string;
3
+ export default transformer;
@@ -0,0 +1,3 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API) => string;
3
+ export default transformer;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): Promise<string>;
@@ -0,0 +1,14 @@
1
+ export declare const PRINT_SETTINGS: {
2
+ quote: "single";
3
+ };
4
+ export declare const NEW_BUTTON_VARIANTS: {
5
+ [key: string]: {
6
+ import: string;
7
+ as: string;
8
+ };
9
+ };
10
+ export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/unsafe";
11
+ export declare const entryPointsMapping: {
12
+ [key: string]: string;
13
+ };
14
+ export declare const BUTTON_TYPES: string[];
@@ -6,5 +6,6 @@ import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-to-design-tokens/theme-to-design-tokens';
7
7
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
8
8
  import './css-to-design-tokens/css-to-design-tokens';
9
+ import './migrate-to-new-buttons/migrate-to-new-buttons';
9
10
  declare const presets: string[];
10
11
  export default presets;
@@ -0,0 +1,3 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API) => string;
3
+ export default transformer;
@@ -0,0 +1,3 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ declare const transformer: (file: FileInfo, api: API) => string;
3
+ export default transformer;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): Promise<string>;
@@ -0,0 +1,14 @@
1
+ export declare const PRINT_SETTINGS: {
2
+ quote: "single";
3
+ };
4
+ export declare const NEW_BUTTON_VARIANTS: {
5
+ [key: string]: {
6
+ import: string;
7
+ as: string;
8
+ };
9
+ };
10
+ export declare const NEW_BUTTON_ENTRY_POINT = "@atlaskit/button/unsafe";
11
+ export declare const entryPointsMapping: {
12
+ [key: string]: string;
13
+ };
14
+ export declare const BUTTON_TYPES: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,7 +32,7 @@
32
32
  "codemod-cli": "./bin/codemod-cli.js"
33
33
  },
34
34
  "dependencies": {
35
- "@atlaskit/tokens": "^1.25.0",
35
+ "@atlaskit/tokens": "^1.28.0",
36
36
  "@babel/runtime": "^7.0.0",
37
37
  "@codeshift/utils": "^0.2.4",
38
38
  "@types/jscodeshift": "^0.11.0",
@@ -49,6 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
52
+ "@types/glob": "^7.1.3",
52
53
  "ts-node": "^10.9.1",
53
54
  "typescript": "~4.9.5"
54
55
  },