@atlaskit/codemod-cli 0.12.3 → 0.13.1

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 (24) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/presets/index.js +2 -1
  3. package/dist/cjs/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +163 -0
  4. package/dist/cjs/presets/theme-remove-deprecated-mixins/types.js +5 -0
  5. package/dist/cjs/presets/theme-remove-deprecated-mixins/utils/replacements.js +146 -0
  6. package/dist/cjs/version.json +1 -1
  7. package/dist/es2019/presets/index.js +2 -1
  8. package/dist/es2019/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +157 -0
  9. package/dist/es2019/presets/theme-remove-deprecated-mixins/types.js +1 -0
  10. package/dist/es2019/presets/theme-remove-deprecated-mixins/utils/replacements.js +139 -0
  11. package/dist/es2019/version.json +1 -1
  12. package/dist/esm/main.js +1 -1
  13. package/dist/esm/presets/index.js +2 -1
  14. package/dist/esm/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +172 -0
  15. package/dist/esm/presets/theme-remove-deprecated-mixins/types.js +1 -0
  16. package/dist/esm/presets/theme-remove-deprecated-mixins/utils/replacements.js +139 -0
  17. package/dist/esm/version.json +1 -1
  18. package/dist/types/presets/index.d.ts +1 -0
  19. package/dist/types/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.d.ts +2 -0
  20. package/dist/types/presets/theme-remove-deprecated-mixins/utils/replacements.d.ts +8 -0
  21. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  22. package/dist/types-ts4.5/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.d.ts +2 -0
  23. package/dist/types-ts4.5/presets/theme-remove-deprecated-mixins/utils/replacements.d.ts +8 -0
  24. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`61cb5313358`](https://bitbucket.org/atlassian/atlassian-frontend/commits/61cb5313358) - Removing unused dependencies and dev dependencies
8
+
9
+ ## 0.13.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`c528571ef3d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c528571ef3d) - Introduces new codemod "theme-remove-deprecated-mixins" to automate the removal of deprecated color mixins
14
+
3
15
  ## 0.12.3
4
16
 
5
17
  ### Patch Changes
@@ -8,12 +8,13 @@ exports.default = void 0;
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  require("./styled-to-emotion/styled-to-emotion");
10
10
  require("./theme-to-design-tokens/theme-to-design-tokens");
11
+ require("./theme-remove-deprecated-mixins/theme-remove-deprecated-mixins");
11
12
  require("./css-to-design-tokens/css-to-design-tokens");
12
13
  /**
13
14
  * Manually import presets to make sure typescript includes them
14
15
  * in the final bundle
15
16
  */
16
17
 
17
- const presets = ['styled-to-emotion', 'theme-to-design-tokens', 'css-to-design-tokens'].map(preset => _path.default.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
18
+ const presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens'].map(preset => _path.default.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
18
19
  var _default = presets;
19
20
  exports.default = _default;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformer;
7
+ var _utils = require("@codeshift/utils");
8
+ var _replacements = require("./utils/replacements");
9
+ function isDecendantOfType(j, path, type) {
10
+ return j(path).closest(type).length > 0;
11
+ }
12
+ function insertTokenImport(j, source) {
13
+ if ((0, _utils.hasImportDeclaration)(j, source, '@atlaskit/tokens')) {
14
+ return;
15
+ }
16
+ const newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
17
+ source.get().node.program.body.unshift(newImport);
18
+ }
19
+ function insertThemedImport(j, source) {
20
+ if ((0, _utils.hasImportSpecifier)(j, source, 'themed', '@atlaskit/theme/components')) {
21
+ return;
22
+ }
23
+ const newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
24
+ source.get().node.program.body.unshift(newImport);
25
+ }
26
+ function buildToken(j, tokenId, node) {
27
+ const callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
28
+ return callExpr;
29
+ }
30
+ function isDecendantOfTokenMethod(j, path) {
31
+ return j(path).closest(j.CallExpression, {
32
+ callee: {
33
+ name: 'token'
34
+ }
35
+ }).length > 0;
36
+ }
37
+ const isDeprecatedApi = identifierName => Object.keys(_replacements.colorReplacements).includes(identifierName);
38
+ function buildThemedNode(j, tokenId = '', fallbackLight, fallbackDark) {
39
+ return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
40
+ }
41
+ function replaceIdentifiers(j, source, specifier) {
42
+ const importSpecifierLocal = specifier.value.local.name;
43
+ const importSpecifierImported = specifier.value.imported.name;
44
+ source.find(j.Identifier, {
45
+ name: importSpecifierLocal
46
+ }).filter(identifier => !isDecendantOfType(j, identifier, j.ImportDeclaration)).filter(identifier => identifier.parent.value.type !== 'MemberExpression').filter(identifier => !['ArrowFunctionExpression', 'FunctionDeclaration', 'JSXAttribute', 'JSXOpeningElement', 'LogicalExpression', 'ObjectProperty', 'TSFunctionType', 'TSPropertySignature', 'VariableDeclarator'].includes(identifier.parent.value.type)).forEach(identifier => {
47
+ const replacement = _replacements.colorReplacements[importSpecifierImported];
48
+ const isDecendantOfToken = isDecendantOfTokenMethod(j, identifier);
49
+ const isDecendantOfCallExpression = identifier.parent.value.type === 'CallExpression';
50
+ const isDynamicReplacement = !isDecendantOfCallExpression || isDecendantOfCallExpression && identifier.parent.value.arguments.length > 0;
51
+ const tokenParentNode = isDecendantOfToken && j(identifier).closest(j.CallExpression, {
52
+ callee: {
53
+ name: 'token'
54
+ }
55
+ }).get();
56
+ const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
57
+ insertTokenImport(j, source);
58
+ (0, _utils.insertImportSpecifier)(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
59
+
60
+ // Requires themed function
61
+ if (isDynamicReplacement) {
62
+ const themedNode = buildThemedNode(j, tokenId, j.identifier(replacement.importSpecifiers[0]), j.identifier(replacement.importSpecifiers[1]));
63
+ insertThemedImport(j, source);
64
+ (0, _utils.insertImportSpecifier)(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
65
+ if (isDecendantOfToken && isDecendantOfCallExpression) {
66
+ const callExpression = identifier.parent;
67
+ tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
68
+ return;
69
+ }
70
+ if (isDecendantOfToken) {
71
+ tokenParentNode.replace(themedNode);
72
+ return;
73
+ }
74
+ identifier.replace(themedNode);
75
+ return;
76
+ }
77
+ if (!isDecendantOfToken && replacement.tokenId) {
78
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(buildToken(j, replacement.tokenId, j.identifier(replacement.staticReplacement)));
79
+ return;
80
+ }
81
+ if (replacement.tokenId) {
82
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(j.identifier(replacement.staticReplacement));
83
+ return;
84
+ }
85
+ });
86
+ }
87
+ function replaceMemberExpressions(j, source, specifier) {
88
+ source.find(j.MemberExpression, {
89
+ object: {
90
+ name: specifier.value.local.name
91
+ }
92
+ }).find(j.Identifier).filter(identifier => isDeprecatedApi(identifier.value.name)).forEach(identifier => {
93
+ const memberExpression = identifier.parent;
94
+ const replacement = _replacements.colorReplacements[identifier.value.name];
95
+ const isDecendantOfToken = isDecendantOfTokenMethod(j, identifier);
96
+ const isDecendantOfCallExpression = identifier.parent.parent.value.type === 'CallExpression';
97
+ const isDynamicReplacement = !isDecendantOfCallExpression || isDecendantOfCallExpression && identifier.parent.parent.value.arguments.length > 0;
98
+ const tokenParentNode = isDecendantOfToken && j(identifier).closest(j.CallExpression, {
99
+ callee: {
100
+ name: 'token'
101
+ }
102
+ }).get();
103
+ const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
104
+ insertTokenImport(j, source);
105
+
106
+ // Requires themed function
107
+ if (isDynamicReplacement) {
108
+ const themedNode = buildThemedNode(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])), j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[1])));
109
+ insertThemedImport(j, source);
110
+ if (isDecendantOfToken && isDecendantOfCallExpression) {
111
+ const callExpression = identifier.parent.parent;
112
+ tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
113
+ return;
114
+ }
115
+ if (isDecendantOfToken) {
116
+ tokenParentNode.replace(themedNode);
117
+ return;
118
+ }
119
+ memberExpression.replace(themedNode);
120
+ return;
121
+ }
122
+ if (!isDecendantOfToken && replacement.tokenId) {
123
+ (isDecendantOfCallExpression ? identifier.parent.parent : identifier).replace(buildToken(j, replacement.tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.staticReplacement))));
124
+ return;
125
+ }
126
+ if (replacement.tokenId) {
127
+ (isDecendantOfCallExpression ? identifier.parent.parent : identifier).replace(j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.staticReplacement)));
128
+ return;
129
+ }
130
+ });
131
+ }
132
+ function transformer(file, api) {
133
+ const j = api.jscodeshift;
134
+ const source = j(file.source);
135
+ const hasThemeImport = (0, _utils.hasImportDeclaration)(j, source, '@atlaskit/theme');
136
+ const hasThemeColorsImport = (0, _utils.hasImportDeclaration)(j, source, '@atlaskit/theme/colors');
137
+ if (!hasThemeImport && !hasThemeColorsImport) {
138
+ return file.source;
139
+ }
140
+ (0, _utils.getImportDeclaration)(j, source, '@atlaskit/theme').find(j.ImportNamespaceSpecifier).forEach(specifier => {
141
+ replaceMemberExpressions(j, source, specifier);
142
+ });
143
+ (0, _utils.getImportDeclaration)(j, source, '@atlaskit/theme').find(j.ImportSpecifier).forEach(specifier => {
144
+ replaceMemberExpressions(j, source, specifier);
145
+ });
146
+ (0, _utils.getImportDeclaration)(j, source, '@atlaskit/theme/colors').find(j.ImportNamespaceSpecifier).forEach(specifier => {
147
+ replaceMemberExpressions(j, source, specifier);
148
+ });
149
+ (0, _utils.getImportDeclaration)(j, source, '@atlaskit/theme/colors').find(j.ImportSpecifier).filter(specifier => isDeprecatedApi(specifier.value.imported.name)).forEach(specifier => {
150
+ replaceIdentifiers(j, source, specifier);
151
+ }).remove();
152
+
153
+ // Clean-up empty imports
154
+ (0, _utils.getImportDeclaration)(j, source, '@atlaskit/theme/colors').filter(importDec => {
155
+ var _importDec$value$spec;
156
+ return !((_importDec$value$spec = importDec.value.specifiers) !== null && _importDec$value$spec !== void 0 && _importDec$value$spec.length);
157
+ }).remove();
158
+ (0, _utils.getImportDeclaration)(j, source, '@atlaskit/theme').filter(importDec => {
159
+ var _importDec$value$spec2;
160
+ return !((_importDec$value$spec2 = importDec.value.specifiers) !== null && _importDec$value$spec2 !== void 0 && _importDec$value$spec2.length);
161
+ }).remove();
162
+ return source.toSource();
163
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.colorReplacements = void 0;
7
+ const colorReplacements = {
8
+ background: {
9
+ fullReplacement: `themed({ light: token('elevation.surface', N0), dark: token('elevation.surface', DN30) })`,
10
+ staticReplacement: 'N0',
11
+ tokenId: 'elevation.surface',
12
+ importSpecifiers: ['N0', 'DN30']
13
+ },
14
+ backgroundActive: {
15
+ fullReplacement: `themed({ light: token('color.background.selected', B50), dark: token('color.background.selected', B75) })`,
16
+ staticReplacement: 'B50',
17
+ tokenId: 'color.background.selected',
18
+ importSpecifiers: ['B50', 'B75']
19
+ },
20
+ backgroundHover: {
21
+ fullReplacement: `themed({ light: token('color.background.neutral.hovered', N30), dark: token('color.background.neutral.hovered', DN70) })`,
22
+ staticReplacement: 'N30',
23
+ tokenId: 'color.background.neutral.hovered',
24
+ importSpecifiers: ['N30', 'DN70']
25
+ },
26
+ backgroundOnLayer: {
27
+ fullReplacement: `themed({ light: token('elevation.surface.overlay', N0), dark: token('elevation.surface.overlay', DN50) })`,
28
+ staticReplacement: 'N0',
29
+ tokenId: 'elevation.surface.overlay',
30
+ importSpecifiers: ['N0', 'DN50']
31
+ },
32
+ text: {
33
+ fullReplacement: `themed({ light: token('color.text', N900), dark: token('color.text', DN600) })`,
34
+ staticReplacement: 'N900',
35
+ tokenId: 'color.text',
36
+ importSpecifiers: ['N900', 'DN600']
37
+ },
38
+ textHover: {
39
+ fullReplacement: `themed({ light: token('color.text', N800), dark: token('color.text', DN600) })`,
40
+ staticReplacement: 'N800',
41
+ tokenId: 'color.text',
42
+ importSpecifiers: ['N800', 'DN600']
43
+ },
44
+ textActive: {
45
+ fullReplacement: `themed({ light: token('color.text.selected', B400), dark: token('color.text.selected', B400) })`,
46
+ staticReplacement: 'B400',
47
+ tokenId: 'color.text.selected',
48
+ importSpecifiers: ['B400', 'B400']
49
+ },
50
+ subtleText: {
51
+ fullReplacement: `themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })`,
52
+ staticReplacement: 'N200',
53
+ tokenId: 'color.text.subtlest',
54
+ importSpecifiers: ['N200', 'DN300']
55
+ },
56
+ placeholderText: {
57
+ fullReplacement: `themed({ light: token('color.text.subtlest', N100), dark: token('color.text.subtlest', DN200) })`,
58
+ staticReplacement: 'N100',
59
+ tokenId: 'color.text.subtlest',
60
+ importSpecifiers: ['N100', 'DN200']
61
+ },
62
+ heading: {
63
+ fullReplacement: `themed({ light: token('color.text', N800), dark: token('color.text', DN600) })`,
64
+ staticReplacement: 'N800',
65
+ tokenId: 'color.text',
66
+ importSpecifiers: ['N800', 'DN600']
67
+ },
68
+ subtleHeading: {
69
+ fullReplacement: `themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })`,
70
+ staticReplacement: 'N200',
71
+ tokenId: 'color.text.subtlest',
72
+ importSpecifiers: ['N200', 'DN300']
73
+ },
74
+ codeBlock: {
75
+ fullReplacement: `themed({ light: N20, dark: DN50 });`,
76
+ staticReplacement: 'N20',
77
+ importSpecifiers: ['N20', 'DN50']
78
+ },
79
+ link: {
80
+ fullReplacement: `themed({ light: token('color.link', B400), dark: token('color.link', B100) })`,
81
+ staticReplacement: 'B400',
82
+ tokenId: 'color.link',
83
+ importSpecifiers: ['B400', 'B100']
84
+ },
85
+ linkHover: {
86
+ fullReplacement: `themed({ light: token('color.link.pressed', B300), dark: token('color.link.pressed', B200) })`,
87
+ staticReplacement: 'B300',
88
+ tokenId: 'color.link.pressed',
89
+ importSpecifiers: ['B300', 'B200']
90
+ },
91
+ linkActive: {
92
+ fullReplacement: `themed({ light: token('color.link.pressed', B500), dark: token('color.link.pressed', B100) })`,
93
+ staticReplacement: 'B500',
94
+ tokenId: 'color.link.pressed',
95
+ importSpecifiers: ['B500', 'B100']
96
+ },
97
+ linkOutline: {
98
+ fullReplacement: `themed({ light: token('color.border.focused', B100), dark: token('color.border.focused', B200) })`,
99
+ staticReplacement: 'B100',
100
+ tokenId: 'color.border.focused',
101
+ importSpecifiers: ['B100', 'B200']
102
+ },
103
+ primary: {
104
+ fullReplacement: `themed({ light: token('color.background.brand.bold', B400), dark: token('color.background.brand.bold', B100) })`,
105
+ staticReplacement: 'B400',
106
+ tokenId: 'color.background.brand.bold',
107
+ importSpecifiers: ['B400', 'B100']
108
+ },
109
+ blue: {
110
+ fullReplacement: `themed({ light: B400, dark: B100, })`,
111
+ staticReplacement: 'B400',
112
+ importSpecifiers: ['B400', 'B100']
113
+ },
114
+ teal: {
115
+ fullReplacement: `themed({ light: T300, dark: T200 })`,
116
+ staticReplacement: 'T300',
117
+ importSpecifiers: ['T300', 'T200']
118
+ },
119
+ purple: {
120
+ fullReplacement: `themed({ light: P300, dark: P100 })`,
121
+ staticReplacement: 'P300',
122
+ importSpecifiers: ['P300', 'P100']
123
+ },
124
+ red: {
125
+ fullReplacement: `R300`,
126
+ staticReplacement: 'R300',
127
+ importSpecifiers: ['R300']
128
+ },
129
+ yellow: {
130
+ fullReplacement: `Y300`,
131
+ staticReplacement: 'Y300',
132
+ importSpecifiers: ['Y300']
133
+ },
134
+ green: {
135
+ fullReplacement: `G300`,
136
+ staticReplacement: 'G300',
137
+ importSpecifiers: ['G300']
138
+ },
139
+ skeleton: {
140
+ fullReplacement: `token('color.skeleton', N20A)`,
141
+ staticReplacement: 'N20A',
142
+ tokenId: 'color.skeleton',
143
+ importSpecifiers: ['N20A']
144
+ }
145
+ };
146
+ exports.colorReplacements = colorReplacements;
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.12.3"
3
+ "version": "0.13.1"
4
4
  }
@@ -6,6 +6,7 @@ import path from 'path';
6
6
  */
7
7
  import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-to-design-tokens/theme-to-design-tokens';
9
+ import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
9
10
  import './css-to-design-tokens/css-to-design-tokens';
10
- const presets = ['styled-to-emotion', 'theme-to-design-tokens', 'css-to-design-tokens'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
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
12
  export default presets;
@@ -0,0 +1,157 @@
1
+ import { hasImportDeclaration, hasImportSpecifier, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
2
+ import { colorReplacements } from './utils/replacements';
3
+ function isDecendantOfType(j, path, type) {
4
+ return j(path).closest(type).length > 0;
5
+ }
6
+ function insertTokenImport(j, source) {
7
+ if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
8
+ return;
9
+ }
10
+ const newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
11
+ source.get().node.program.body.unshift(newImport);
12
+ }
13
+ function insertThemedImport(j, source) {
14
+ if (hasImportSpecifier(j, source, 'themed', '@atlaskit/theme/components')) {
15
+ return;
16
+ }
17
+ const newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
18
+ source.get().node.program.body.unshift(newImport);
19
+ }
20
+ function buildToken(j, tokenId, node) {
21
+ const callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
22
+ return callExpr;
23
+ }
24
+ function isDecendantOfTokenMethod(j, path) {
25
+ return j(path).closest(j.CallExpression, {
26
+ callee: {
27
+ name: 'token'
28
+ }
29
+ }).length > 0;
30
+ }
31
+ const isDeprecatedApi = identifierName => Object.keys(colorReplacements).includes(identifierName);
32
+ function buildThemedNode(j, tokenId = '', fallbackLight, fallbackDark) {
33
+ return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
34
+ }
35
+ function replaceIdentifiers(j, source, specifier) {
36
+ const importSpecifierLocal = specifier.value.local.name;
37
+ const importSpecifierImported = specifier.value.imported.name;
38
+ source.find(j.Identifier, {
39
+ name: importSpecifierLocal
40
+ }).filter(identifier => !isDecendantOfType(j, identifier, j.ImportDeclaration)).filter(identifier => identifier.parent.value.type !== 'MemberExpression').filter(identifier => !['ArrowFunctionExpression', 'FunctionDeclaration', 'JSXAttribute', 'JSXOpeningElement', 'LogicalExpression', 'ObjectProperty', 'TSFunctionType', 'TSPropertySignature', 'VariableDeclarator'].includes(identifier.parent.value.type)).forEach(identifier => {
41
+ const replacement = colorReplacements[importSpecifierImported];
42
+ const isDecendantOfToken = isDecendantOfTokenMethod(j, identifier);
43
+ const isDecendantOfCallExpression = identifier.parent.value.type === 'CallExpression';
44
+ const isDynamicReplacement = !isDecendantOfCallExpression || isDecendantOfCallExpression && identifier.parent.value.arguments.length > 0;
45
+ const tokenParentNode = isDecendantOfToken && j(identifier).closest(j.CallExpression, {
46
+ callee: {
47
+ name: 'token'
48
+ }
49
+ }).get();
50
+ const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
51
+ insertTokenImport(j, source);
52
+ insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
53
+
54
+ // Requires themed function
55
+ if (isDynamicReplacement) {
56
+ const themedNode = buildThemedNode(j, tokenId, j.identifier(replacement.importSpecifiers[0]), j.identifier(replacement.importSpecifiers[1]));
57
+ insertThemedImport(j, source);
58
+ insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
59
+ if (isDecendantOfToken && isDecendantOfCallExpression) {
60
+ const callExpression = identifier.parent;
61
+ tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
62
+ return;
63
+ }
64
+ if (isDecendantOfToken) {
65
+ tokenParentNode.replace(themedNode);
66
+ return;
67
+ }
68
+ identifier.replace(themedNode);
69
+ return;
70
+ }
71
+ if (!isDecendantOfToken && replacement.tokenId) {
72
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(buildToken(j, replacement.tokenId, j.identifier(replacement.staticReplacement)));
73
+ return;
74
+ }
75
+ if (replacement.tokenId) {
76
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(j.identifier(replacement.staticReplacement));
77
+ return;
78
+ }
79
+ });
80
+ }
81
+ function replaceMemberExpressions(j, source, specifier) {
82
+ source.find(j.MemberExpression, {
83
+ object: {
84
+ name: specifier.value.local.name
85
+ }
86
+ }).find(j.Identifier).filter(identifier => isDeprecatedApi(identifier.value.name)).forEach(identifier => {
87
+ const memberExpression = identifier.parent;
88
+ const replacement = colorReplacements[identifier.value.name];
89
+ const isDecendantOfToken = isDecendantOfTokenMethod(j, identifier);
90
+ const isDecendantOfCallExpression = identifier.parent.parent.value.type === 'CallExpression';
91
+ const isDynamicReplacement = !isDecendantOfCallExpression || isDecendantOfCallExpression && identifier.parent.parent.value.arguments.length > 0;
92
+ const tokenParentNode = isDecendantOfToken && j(identifier).closest(j.CallExpression, {
93
+ callee: {
94
+ name: 'token'
95
+ }
96
+ }).get();
97
+ const tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
98
+ insertTokenImport(j, source);
99
+
100
+ // Requires themed function
101
+ if (isDynamicReplacement) {
102
+ const themedNode = buildThemedNode(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])), j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[1])));
103
+ insertThemedImport(j, source);
104
+ if (isDecendantOfToken && isDecendantOfCallExpression) {
105
+ const callExpression = identifier.parent.parent;
106
+ tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
107
+ return;
108
+ }
109
+ if (isDecendantOfToken) {
110
+ tokenParentNode.replace(themedNode);
111
+ return;
112
+ }
113
+ memberExpression.replace(themedNode);
114
+ return;
115
+ }
116
+ if (!isDecendantOfToken && replacement.tokenId) {
117
+ (isDecendantOfCallExpression ? identifier.parent.parent : identifier).replace(buildToken(j, replacement.tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.staticReplacement))));
118
+ return;
119
+ }
120
+ if (replacement.tokenId) {
121
+ (isDecendantOfCallExpression ? identifier.parent.parent : identifier).replace(j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.staticReplacement)));
122
+ return;
123
+ }
124
+ });
125
+ }
126
+ export default function transformer(file, api) {
127
+ const j = api.jscodeshift;
128
+ const source = j(file.source);
129
+ const hasThemeImport = hasImportDeclaration(j, source, '@atlaskit/theme');
130
+ const hasThemeColorsImport = hasImportDeclaration(j, source, '@atlaskit/theme/colors');
131
+ if (!hasThemeImport && !hasThemeColorsImport) {
132
+ return file.source;
133
+ }
134
+ getImportDeclaration(j, source, '@atlaskit/theme').find(j.ImportNamespaceSpecifier).forEach(specifier => {
135
+ replaceMemberExpressions(j, source, specifier);
136
+ });
137
+ getImportDeclaration(j, source, '@atlaskit/theme').find(j.ImportSpecifier).forEach(specifier => {
138
+ replaceMemberExpressions(j, source, specifier);
139
+ });
140
+ getImportDeclaration(j, source, '@atlaskit/theme/colors').find(j.ImportNamespaceSpecifier).forEach(specifier => {
141
+ replaceMemberExpressions(j, source, specifier);
142
+ });
143
+ getImportDeclaration(j, source, '@atlaskit/theme/colors').find(j.ImportSpecifier).filter(specifier => isDeprecatedApi(specifier.value.imported.name)).forEach(specifier => {
144
+ replaceIdentifiers(j, source, specifier);
145
+ }).remove();
146
+
147
+ // Clean-up empty imports
148
+ getImportDeclaration(j, source, '@atlaskit/theme/colors').filter(importDec => {
149
+ var _importDec$value$spec;
150
+ return !((_importDec$value$spec = importDec.value.specifiers) !== null && _importDec$value$spec !== void 0 && _importDec$value$spec.length);
151
+ }).remove();
152
+ getImportDeclaration(j, source, '@atlaskit/theme').filter(importDec => {
153
+ var _importDec$value$spec2;
154
+ return !((_importDec$value$spec2 = importDec.value.specifiers) !== null && _importDec$value$spec2 !== void 0 && _importDec$value$spec2.length);
155
+ }).remove();
156
+ return source.toSource();
157
+ }
@@ -0,0 +1,139 @@
1
+ export const colorReplacements = {
2
+ background: {
3
+ fullReplacement: `themed({ light: token('elevation.surface', N0), dark: token('elevation.surface', DN30) })`,
4
+ staticReplacement: 'N0',
5
+ tokenId: 'elevation.surface',
6
+ importSpecifiers: ['N0', 'DN30']
7
+ },
8
+ backgroundActive: {
9
+ fullReplacement: `themed({ light: token('color.background.selected', B50), dark: token('color.background.selected', B75) })`,
10
+ staticReplacement: 'B50',
11
+ tokenId: 'color.background.selected',
12
+ importSpecifiers: ['B50', 'B75']
13
+ },
14
+ backgroundHover: {
15
+ fullReplacement: `themed({ light: token('color.background.neutral.hovered', N30), dark: token('color.background.neutral.hovered', DN70) })`,
16
+ staticReplacement: 'N30',
17
+ tokenId: 'color.background.neutral.hovered',
18
+ importSpecifiers: ['N30', 'DN70']
19
+ },
20
+ backgroundOnLayer: {
21
+ fullReplacement: `themed({ light: token('elevation.surface.overlay', N0), dark: token('elevation.surface.overlay', DN50) })`,
22
+ staticReplacement: 'N0',
23
+ tokenId: 'elevation.surface.overlay',
24
+ importSpecifiers: ['N0', 'DN50']
25
+ },
26
+ text: {
27
+ fullReplacement: `themed({ light: token('color.text', N900), dark: token('color.text', DN600) })`,
28
+ staticReplacement: 'N900',
29
+ tokenId: 'color.text',
30
+ importSpecifiers: ['N900', 'DN600']
31
+ },
32
+ textHover: {
33
+ fullReplacement: `themed({ light: token('color.text', N800), dark: token('color.text', DN600) })`,
34
+ staticReplacement: 'N800',
35
+ tokenId: 'color.text',
36
+ importSpecifiers: ['N800', 'DN600']
37
+ },
38
+ textActive: {
39
+ fullReplacement: `themed({ light: token('color.text.selected', B400), dark: token('color.text.selected', B400) })`,
40
+ staticReplacement: 'B400',
41
+ tokenId: 'color.text.selected',
42
+ importSpecifiers: ['B400', 'B400']
43
+ },
44
+ subtleText: {
45
+ fullReplacement: `themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })`,
46
+ staticReplacement: 'N200',
47
+ tokenId: 'color.text.subtlest',
48
+ importSpecifiers: ['N200', 'DN300']
49
+ },
50
+ placeholderText: {
51
+ fullReplacement: `themed({ light: token('color.text.subtlest', N100), dark: token('color.text.subtlest', DN200) })`,
52
+ staticReplacement: 'N100',
53
+ tokenId: 'color.text.subtlest',
54
+ importSpecifiers: ['N100', 'DN200']
55
+ },
56
+ heading: {
57
+ fullReplacement: `themed({ light: token('color.text', N800), dark: token('color.text', DN600) })`,
58
+ staticReplacement: 'N800',
59
+ tokenId: 'color.text',
60
+ importSpecifiers: ['N800', 'DN600']
61
+ },
62
+ subtleHeading: {
63
+ fullReplacement: `themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })`,
64
+ staticReplacement: 'N200',
65
+ tokenId: 'color.text.subtlest',
66
+ importSpecifiers: ['N200', 'DN300']
67
+ },
68
+ codeBlock: {
69
+ fullReplacement: `themed({ light: N20, dark: DN50 });`,
70
+ staticReplacement: 'N20',
71
+ importSpecifiers: ['N20', 'DN50']
72
+ },
73
+ link: {
74
+ fullReplacement: `themed({ light: token('color.link', B400), dark: token('color.link', B100) })`,
75
+ staticReplacement: 'B400',
76
+ tokenId: 'color.link',
77
+ importSpecifiers: ['B400', 'B100']
78
+ },
79
+ linkHover: {
80
+ fullReplacement: `themed({ light: token('color.link.pressed', B300), dark: token('color.link.pressed', B200) })`,
81
+ staticReplacement: 'B300',
82
+ tokenId: 'color.link.pressed',
83
+ importSpecifiers: ['B300', 'B200']
84
+ },
85
+ linkActive: {
86
+ fullReplacement: `themed({ light: token('color.link.pressed', B500), dark: token('color.link.pressed', B100) })`,
87
+ staticReplacement: 'B500',
88
+ tokenId: 'color.link.pressed',
89
+ importSpecifiers: ['B500', 'B100']
90
+ },
91
+ linkOutline: {
92
+ fullReplacement: `themed({ light: token('color.border.focused', B100), dark: token('color.border.focused', B200) })`,
93
+ staticReplacement: 'B100',
94
+ tokenId: 'color.border.focused',
95
+ importSpecifiers: ['B100', 'B200']
96
+ },
97
+ primary: {
98
+ fullReplacement: `themed({ light: token('color.background.brand.bold', B400), dark: token('color.background.brand.bold', B100) })`,
99
+ staticReplacement: 'B400',
100
+ tokenId: 'color.background.brand.bold',
101
+ importSpecifiers: ['B400', 'B100']
102
+ },
103
+ blue: {
104
+ fullReplacement: `themed({ light: B400, dark: B100, })`,
105
+ staticReplacement: 'B400',
106
+ importSpecifiers: ['B400', 'B100']
107
+ },
108
+ teal: {
109
+ fullReplacement: `themed({ light: T300, dark: T200 })`,
110
+ staticReplacement: 'T300',
111
+ importSpecifiers: ['T300', 'T200']
112
+ },
113
+ purple: {
114
+ fullReplacement: `themed({ light: P300, dark: P100 })`,
115
+ staticReplacement: 'P300',
116
+ importSpecifiers: ['P300', 'P100']
117
+ },
118
+ red: {
119
+ fullReplacement: `R300`,
120
+ staticReplacement: 'R300',
121
+ importSpecifiers: ['R300']
122
+ },
123
+ yellow: {
124
+ fullReplacement: `Y300`,
125
+ staticReplacement: 'Y300',
126
+ importSpecifiers: ['Y300']
127
+ },
128
+ green: {
129
+ fullReplacement: `G300`,
130
+ staticReplacement: 'G300',
131
+ importSpecifiers: ['G300']
132
+ },
133
+ skeleton: {
134
+ fullReplacement: `token('color.skeleton', N20A)`,
135
+ staticReplacement: 'N20A',
136
+ tokenId: 'color.skeleton',
137
+ importSpecifiers: ['N20A']
138
+ }
139
+ };
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.12.3"
3
+ "version": "0.13.1"
4
4
  }
package/dist/esm/main.js CHANGED
@@ -289,7 +289,7 @@ function _main() {
289
289
  case 4:
290
290
  _yield$parseArgs = _context5.sent;
291
291
  packages = _yield$parseArgs.packages;
292
- _process$env$_PACKAGE = "0.12.3", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
292
+ _process$env$_PACKAGE = "0.13.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
293
293
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
294
294
  if (packages && packages.length > 0) {
295
295
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -6,8 +6,9 @@ import path from 'path';
6
6
  */
7
7
  import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-to-design-tokens/theme-to-design-tokens';
9
+ import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
9
10
  import './css-to-design-tokens/css-to-design-tokens';
10
- var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'css-to-design-tokens'].map(function (preset) {
11
+ var presets = ['styled-to-emotion', 'theme-to-design-tokens', 'theme-remove-deprecated-mixins', 'css-to-design-tokens'].map(function (preset) {
11
12
  return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
12
13
  });
13
14
  export default presets;
@@ -0,0 +1,172 @@
1
+ import { hasImportDeclaration, hasImportSpecifier, getImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
2
+ import { colorReplacements } from './utils/replacements';
3
+ function isDecendantOfType(j, path, type) {
4
+ return j(path).closest(type).length > 0;
5
+ }
6
+ function insertTokenImport(j, source) {
7
+ if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
8
+ return;
9
+ }
10
+ var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
11
+ source.get().node.program.body.unshift(newImport);
12
+ }
13
+ function insertThemedImport(j, source) {
14
+ if (hasImportSpecifier(j, source, 'themed', '@atlaskit/theme/components')) {
15
+ return;
16
+ }
17
+ var newImport = j.importDeclaration([j.importSpecifier(j.identifier('themed'))], j.stringLiteral('@atlaskit/theme/components'));
18
+ source.get().node.program.body.unshift(newImport);
19
+ }
20
+ function buildToken(j, tokenId, node) {
21
+ var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
22
+ return callExpr;
23
+ }
24
+ function isDecendantOfTokenMethod(j, path) {
25
+ return j(path).closest(j.CallExpression, {
26
+ callee: {
27
+ name: 'token'
28
+ }
29
+ }).length > 0;
30
+ }
31
+ var isDeprecatedApi = function isDeprecatedApi(identifierName) {
32
+ return Object.keys(colorReplacements).includes(identifierName);
33
+ };
34
+ function buildThemedNode(j) {
35
+ var tokenId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
36
+ var fallbackLight = arguments.length > 2 ? arguments[2] : undefined;
37
+ var fallbackDark = arguments.length > 3 ? arguments[3] : undefined;
38
+ return j.callExpression(j.identifier('themed'), [j.objectExpression([j.objectProperty(j.identifier('light'), tokenId ? buildToken(j, tokenId, fallbackLight) : fallbackLight), j.objectProperty(j.identifier('dark'), tokenId ? buildToken(j, tokenId, fallbackDark) : fallbackDark)])]);
39
+ }
40
+ function replaceIdentifiers(j, source, specifier) {
41
+ var importSpecifierLocal = specifier.value.local.name;
42
+ var importSpecifierImported = specifier.value.imported.name;
43
+ source.find(j.Identifier, {
44
+ name: importSpecifierLocal
45
+ }).filter(function (identifier) {
46
+ return !isDecendantOfType(j, identifier, j.ImportDeclaration);
47
+ }).filter(function (identifier) {
48
+ return identifier.parent.value.type !== 'MemberExpression';
49
+ }).filter(function (identifier) {
50
+ return !['ArrowFunctionExpression', 'FunctionDeclaration', 'JSXAttribute', 'JSXOpeningElement', 'LogicalExpression', 'ObjectProperty', 'TSFunctionType', 'TSPropertySignature', 'VariableDeclarator'].includes(identifier.parent.value.type);
51
+ }).forEach(function (identifier) {
52
+ var replacement = colorReplacements[importSpecifierImported];
53
+ var isDecendantOfToken = isDecendantOfTokenMethod(j, identifier);
54
+ var isDecendantOfCallExpression = identifier.parent.value.type === 'CallExpression';
55
+ var isDynamicReplacement = !isDecendantOfCallExpression || isDecendantOfCallExpression && identifier.parent.value.arguments.length > 0;
56
+ var tokenParentNode = isDecendantOfToken && j(identifier).closest(j.CallExpression, {
57
+ callee: {
58
+ name: 'token'
59
+ }
60
+ }).get();
61
+ var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
62
+ insertTokenImport(j, source);
63
+ insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[0])), '@atlaskit/theme/colors');
64
+
65
+ // Requires themed function
66
+ if (isDynamicReplacement) {
67
+ var themedNode = buildThemedNode(j, tokenId, j.identifier(replacement.importSpecifiers[0]), j.identifier(replacement.importSpecifiers[1]));
68
+ insertThemedImport(j, source);
69
+ insertImportSpecifier(j, source, j.importSpecifier(j.identifier(replacement.importSpecifiers[1])), '@atlaskit/theme/colors');
70
+ if (isDecendantOfToken && isDecendantOfCallExpression) {
71
+ var callExpression = identifier.parent;
72
+ tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
73
+ return;
74
+ }
75
+ if (isDecendantOfToken) {
76
+ tokenParentNode.replace(themedNode);
77
+ return;
78
+ }
79
+ identifier.replace(themedNode);
80
+ return;
81
+ }
82
+ if (!isDecendantOfToken && replacement.tokenId) {
83
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(buildToken(j, replacement.tokenId, j.identifier(replacement.staticReplacement)));
84
+ return;
85
+ }
86
+ if (replacement.tokenId) {
87
+ (isDecendantOfCallExpression ? identifier.parent : identifier).replace(j.identifier(replacement.staticReplacement));
88
+ return;
89
+ }
90
+ });
91
+ }
92
+ function replaceMemberExpressions(j, source, specifier) {
93
+ source.find(j.MemberExpression, {
94
+ object: {
95
+ name: specifier.value.local.name
96
+ }
97
+ }).find(j.Identifier).filter(function (identifier) {
98
+ return isDeprecatedApi(identifier.value.name);
99
+ }).forEach(function (identifier) {
100
+ var memberExpression = identifier.parent;
101
+ var replacement = colorReplacements[identifier.value.name];
102
+ var isDecendantOfToken = isDecendantOfTokenMethod(j, identifier);
103
+ var isDecendantOfCallExpression = identifier.parent.parent.value.type === 'CallExpression';
104
+ var isDynamicReplacement = !isDecendantOfCallExpression || isDecendantOfCallExpression && identifier.parent.parent.value.arguments.length > 0;
105
+ var tokenParentNode = isDecendantOfToken && j(identifier).closest(j.CallExpression, {
106
+ callee: {
107
+ name: 'token'
108
+ }
109
+ }).get();
110
+ var tokenId = isDecendantOfToken ? tokenParentNode.value.arguments[0].value : replacement.tokenId;
111
+ insertTokenImport(j, source);
112
+
113
+ // Requires themed function
114
+ if (isDynamicReplacement) {
115
+ var themedNode = buildThemedNode(j, tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[0])), j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.importSpecifiers[1])));
116
+ insertThemedImport(j, source);
117
+ if (isDecendantOfToken && isDecendantOfCallExpression) {
118
+ var callExpression = identifier.parent.parent;
119
+ tokenParentNode.replace(j.callExpression(themedNode, callExpression.value.arguments));
120
+ return;
121
+ }
122
+ if (isDecendantOfToken) {
123
+ tokenParentNode.replace(themedNode);
124
+ return;
125
+ }
126
+ memberExpression.replace(themedNode);
127
+ return;
128
+ }
129
+ if (!isDecendantOfToken && replacement.tokenId) {
130
+ (isDecendantOfCallExpression ? identifier.parent.parent : identifier).replace(buildToken(j, replacement.tokenId, j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.staticReplacement))));
131
+ return;
132
+ }
133
+ if (replacement.tokenId) {
134
+ (isDecendantOfCallExpression ? identifier.parent.parent : identifier).replace(j.memberExpression(j.identifier(memberExpression.value.object.name), j.identifier(replacement.staticReplacement)));
135
+ return;
136
+ }
137
+ });
138
+ }
139
+ export default function transformer(file, api) {
140
+ var j = api.jscodeshift;
141
+ var source = j(file.source);
142
+ var hasThemeImport = hasImportDeclaration(j, source, '@atlaskit/theme');
143
+ var hasThemeColorsImport = hasImportDeclaration(j, source, '@atlaskit/theme/colors');
144
+ if (!hasThemeImport && !hasThemeColorsImport) {
145
+ return file.source;
146
+ }
147
+ getImportDeclaration(j, source, '@atlaskit/theme').find(j.ImportNamespaceSpecifier).forEach(function (specifier) {
148
+ replaceMemberExpressions(j, source, specifier);
149
+ });
150
+ getImportDeclaration(j, source, '@atlaskit/theme').find(j.ImportSpecifier).forEach(function (specifier) {
151
+ replaceMemberExpressions(j, source, specifier);
152
+ });
153
+ getImportDeclaration(j, source, '@atlaskit/theme/colors').find(j.ImportNamespaceSpecifier).forEach(function (specifier) {
154
+ replaceMemberExpressions(j, source, specifier);
155
+ });
156
+ getImportDeclaration(j, source, '@atlaskit/theme/colors').find(j.ImportSpecifier).filter(function (specifier) {
157
+ return isDeprecatedApi(specifier.value.imported.name);
158
+ }).forEach(function (specifier) {
159
+ replaceIdentifiers(j, source, specifier);
160
+ }).remove();
161
+
162
+ // Clean-up empty imports
163
+ getImportDeclaration(j, source, '@atlaskit/theme/colors').filter(function (importDec) {
164
+ var _importDec$value$spec;
165
+ return !((_importDec$value$spec = importDec.value.specifiers) !== null && _importDec$value$spec !== void 0 && _importDec$value$spec.length);
166
+ }).remove();
167
+ getImportDeclaration(j, source, '@atlaskit/theme').filter(function (importDec) {
168
+ var _importDec$value$spec2;
169
+ return !((_importDec$value$spec2 = importDec.value.specifiers) !== null && _importDec$value$spec2 !== void 0 && _importDec$value$spec2.length);
170
+ }).remove();
171
+ return source.toSource();
172
+ }
@@ -0,0 +1,139 @@
1
+ export var colorReplacements = {
2
+ background: {
3
+ fullReplacement: "themed({ light: token('elevation.surface', N0), dark: token('elevation.surface', DN30) })",
4
+ staticReplacement: 'N0',
5
+ tokenId: 'elevation.surface',
6
+ importSpecifiers: ['N0', 'DN30']
7
+ },
8
+ backgroundActive: {
9
+ fullReplacement: "themed({ light: token('color.background.selected', B50), dark: token('color.background.selected', B75) })",
10
+ staticReplacement: 'B50',
11
+ tokenId: 'color.background.selected',
12
+ importSpecifiers: ['B50', 'B75']
13
+ },
14
+ backgroundHover: {
15
+ fullReplacement: "themed({ light: token('color.background.neutral.hovered', N30), dark: token('color.background.neutral.hovered', DN70) })",
16
+ staticReplacement: 'N30',
17
+ tokenId: 'color.background.neutral.hovered',
18
+ importSpecifiers: ['N30', 'DN70']
19
+ },
20
+ backgroundOnLayer: {
21
+ fullReplacement: "themed({ light: token('elevation.surface.overlay', N0), dark: token('elevation.surface.overlay', DN50) })",
22
+ staticReplacement: 'N0',
23
+ tokenId: 'elevation.surface.overlay',
24
+ importSpecifiers: ['N0', 'DN50']
25
+ },
26
+ text: {
27
+ fullReplacement: "themed({ light: token('color.text', N900), dark: token('color.text', DN600) })",
28
+ staticReplacement: 'N900',
29
+ tokenId: 'color.text',
30
+ importSpecifiers: ['N900', 'DN600']
31
+ },
32
+ textHover: {
33
+ fullReplacement: "themed({ light: token('color.text', N800), dark: token('color.text', DN600) })",
34
+ staticReplacement: 'N800',
35
+ tokenId: 'color.text',
36
+ importSpecifiers: ['N800', 'DN600']
37
+ },
38
+ textActive: {
39
+ fullReplacement: "themed({ light: token('color.text.selected', B400), dark: token('color.text.selected', B400) })",
40
+ staticReplacement: 'B400',
41
+ tokenId: 'color.text.selected',
42
+ importSpecifiers: ['B400', 'B400']
43
+ },
44
+ subtleText: {
45
+ fullReplacement: "themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })",
46
+ staticReplacement: 'N200',
47
+ tokenId: 'color.text.subtlest',
48
+ importSpecifiers: ['N200', 'DN300']
49
+ },
50
+ placeholderText: {
51
+ fullReplacement: "themed({ light: token('color.text.subtlest', N100), dark: token('color.text.subtlest', DN200) })",
52
+ staticReplacement: 'N100',
53
+ tokenId: 'color.text.subtlest',
54
+ importSpecifiers: ['N100', 'DN200']
55
+ },
56
+ heading: {
57
+ fullReplacement: "themed({ light: token('color.text', N800), dark: token('color.text', DN600) })",
58
+ staticReplacement: 'N800',
59
+ tokenId: 'color.text',
60
+ importSpecifiers: ['N800', 'DN600']
61
+ },
62
+ subtleHeading: {
63
+ fullReplacement: "themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })",
64
+ staticReplacement: 'N200',
65
+ tokenId: 'color.text.subtlest',
66
+ importSpecifiers: ['N200', 'DN300']
67
+ },
68
+ codeBlock: {
69
+ fullReplacement: "themed({ light: N20, dark: DN50 });",
70
+ staticReplacement: 'N20',
71
+ importSpecifiers: ['N20', 'DN50']
72
+ },
73
+ link: {
74
+ fullReplacement: "themed({ light: token('color.link', B400), dark: token('color.link', B100) })",
75
+ staticReplacement: 'B400',
76
+ tokenId: 'color.link',
77
+ importSpecifiers: ['B400', 'B100']
78
+ },
79
+ linkHover: {
80
+ fullReplacement: "themed({ light: token('color.link.pressed', B300), dark: token('color.link.pressed', B200) })",
81
+ staticReplacement: 'B300',
82
+ tokenId: 'color.link.pressed',
83
+ importSpecifiers: ['B300', 'B200']
84
+ },
85
+ linkActive: {
86
+ fullReplacement: "themed({ light: token('color.link.pressed', B500), dark: token('color.link.pressed', B100) })",
87
+ staticReplacement: 'B500',
88
+ tokenId: 'color.link.pressed',
89
+ importSpecifiers: ['B500', 'B100']
90
+ },
91
+ linkOutline: {
92
+ fullReplacement: "themed({ light: token('color.border.focused', B100), dark: token('color.border.focused', B200) })",
93
+ staticReplacement: 'B100',
94
+ tokenId: 'color.border.focused',
95
+ importSpecifiers: ['B100', 'B200']
96
+ },
97
+ primary: {
98
+ fullReplacement: "themed({ light: token('color.background.brand.bold', B400), dark: token('color.background.brand.bold', B100) })",
99
+ staticReplacement: 'B400',
100
+ tokenId: 'color.background.brand.bold',
101
+ importSpecifiers: ['B400', 'B100']
102
+ },
103
+ blue: {
104
+ fullReplacement: "themed({ light: B400, dark: B100, })",
105
+ staticReplacement: 'B400',
106
+ importSpecifiers: ['B400', 'B100']
107
+ },
108
+ teal: {
109
+ fullReplacement: "themed({ light: T300, dark: T200 })",
110
+ staticReplacement: 'T300',
111
+ importSpecifiers: ['T300', 'T200']
112
+ },
113
+ purple: {
114
+ fullReplacement: "themed({ light: P300, dark: P100 })",
115
+ staticReplacement: 'P300',
116
+ importSpecifiers: ['P300', 'P100']
117
+ },
118
+ red: {
119
+ fullReplacement: "R300",
120
+ staticReplacement: 'R300',
121
+ importSpecifiers: ['R300']
122
+ },
123
+ yellow: {
124
+ fullReplacement: "Y300",
125
+ staticReplacement: 'Y300',
126
+ importSpecifiers: ['Y300']
127
+ },
128
+ green: {
129
+ fullReplacement: "G300",
130
+ staticReplacement: 'G300',
131
+ importSpecifiers: ['G300']
132
+ },
133
+ skeleton: {
134
+ fullReplacement: "token('color.skeleton', N20A)",
135
+ staticReplacement: 'N20A',
136
+ tokenId: 'color.skeleton',
137
+ importSpecifiers: ['N20A']
138
+ }
139
+ };
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.12.3"
3
+ "version": "0.13.1"
4
4
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-to-design-tokens/theme-to-design-tokens';
7
+ import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
7
8
  import './css-to-design-tokens/css-to-design-tokens';
8
9
  declare const presets: string[];
9
10
  export default presets;
@@ -0,0 +1,2 @@
1
+ import { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;
@@ -0,0 +1,8 @@
1
+ interface ColorReplacements {
2
+ fullReplacement: string;
3
+ staticReplacement: string;
4
+ tokenId?: string;
5
+ importSpecifiers: string[];
6
+ }
7
+ export declare const colorReplacements: Record<string, ColorReplacements>;
8
+ export {};
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-to-design-tokens/theme-to-design-tokens';
7
+ import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
7
8
  import './css-to-design-tokens/css-to-design-tokens';
8
9
  declare const presets: string[];
9
10
  export default presets;
@@ -0,0 +1,2 @@
1
+ import { API, FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;
@@ -0,0 +1,8 @@
1
+ interface ColorReplacements {
2
+ fullReplacement: string;
3
+ staticReplacement: string;
4
+ tokenId?: string;
5
+ importSpecifiers: string[];
6
+ }
7
+ export declare const colorReplacements: Record<string, ColorReplacements>;
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.12.3",
3
+ "version": "0.13.1",
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,8 +32,9 @@
32
32
  "codemod-cli": "./bin/codemod-cli.js"
33
33
  },
34
34
  "dependencies": {
35
- "@atlaskit/tokens": "^1.4.0",
35
+ "@atlaskit/tokens": "^1.5.0",
36
36
  "@babel/runtime": "^7.0.0",
37
+ "@codeshift/utils": "^0.2.1",
37
38
  "@types/jscodeshift": "^0.11.0",
38
39
  "chalk": "^4.1.2",
39
40
  "enquirer": "^2.3.4",
@@ -47,7 +48,6 @@
47
48
  "simple-git": "^3.16.0"
48
49
  },
49
50
  "devDependencies": {
50
- "@atlaskit/docs": "*",
51
51
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
52
52
  "ts-node": "^10.9.1",
53
53
  "typescript": "~4.9.5"