@atlaskit/codemod-cli 0.14.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.
- package/CHANGELOG.md +72 -53
- package/dist/cjs/main.js +3 -3
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +52 -133
- package/dist/cjs/presets/css-to-design-tokens/lib/colors.js +49 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/declaration.js +29 -0
- package/dist/cjs/presets/css-to-design-tokens/{utils → lib}/legacy-colors.js +13 -17
- package/dist/cjs/presets/css-to-design-tokens/lib/logger.js +18 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/meta.js +157 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/tokens.js +47 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/value.js +80 -0
- package/dist/cjs/presets/index.js +3 -3
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +118 -0
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +58 -0
- package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +45 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +35 -0
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +1 -2
- package/dist/cjs/presets/theme-remove-deprecated-mixins/utils/replacements.js +2 -3
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +2 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +4 -8
- package/dist/cjs/presets/theme-to-design-tokens/utils/css-utils.js +2 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +1 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +4 -7
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/string-utils.js +1 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +3 -5
- package/dist/cjs/sinceRef.js +1 -2
- package/dist/cjs/transforms.js +6 -12
- package/dist/cjs/types.js +3 -5
- package/dist/cjs/utils.js +2 -3
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +52 -116
- package/dist/es2019/presets/css-to-design-tokens/lib/colors.js +34 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/declaration.js +17 -0
- package/dist/es2019/presets/css-to-design-tokens/{utils → lib}/legacy-colors.js +9 -10
- package/dist/es2019/presets/css-to-design-tokens/lib/logger.js +11 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/meta.js +133 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/tokens.js +24 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/value.js +68 -0
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +86 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +44 -0
- package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +19 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +29 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/css-utils.js +2 -2
- package/dist/esm/main.js +3 -3
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +52 -132
- package/dist/esm/presets/css-to-design-tokens/lib/colors.js +38 -0
- package/dist/esm/presets/css-to-design-tokens/lib/declaration.js +19 -0
- package/dist/esm/presets/css-to-design-tokens/{utils → lib}/legacy-colors.js +9 -10
- package/dist/esm/presets/css-to-design-tokens/lib/logger.js +11 -0
- package/dist/esm/presets/css-to-design-tokens/lib/meta.js +146 -0
- package/dist/esm/presets/css-to-design-tokens/lib/tokens.js +40 -0
- package/dist/esm/presets/css-to-design-tokens/lib/value.js +73 -0
- package/dist/esm/presets/index.js +2 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +112 -0
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +52 -0
- package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +38 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +29 -0
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +2 -2
- package/dist/esm/presets/theme-to-design-tokens/utils/css-utils.js +2 -2
- package/dist/types/main.d.ts +0 -1
- package/dist/types/presets/css-to-design-tokens/css-to-design-tokens.d.ts +0 -1
- package/dist/types/presets/css-to-design-tokens/lib/colors.d.ts +6 -0
- package/dist/types/presets/css-to-design-tokens/lib/declaration.d.ts +5 -0
- package/dist/types/presets/css-to-design-tokens/{utils → lib}/legacy-colors.d.ts +1 -1
- package/dist/types/presets/css-to-design-tokens/lib/logger.d.ts +4 -0
- package/dist/types/presets/css-to-design-tokens/lib/meta.d.ts +6 -0
- package/dist/types/presets/css-to-design-tokens/lib/tokens.d.ts +7 -0
- package/dist/types/presets/css-to-design-tokens/lib/value.d.ts +6 -0
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/codemods/next-split-imports.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +14 -0
- package/dist/types-ts4.5/main.d.ts +0 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/css-to-design-tokens.d.ts +0 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/colors.d.ts +6 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/declaration.d.ts +5 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/{utils → lib}/legacy-colors.d.ts +1 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/logger.d.ts +4 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/meta.d.ts +6 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/tokens.d.ts +7 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/value.d.ts +6 -0
- package/dist/types-ts4.5/presets/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-split-imports.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +14 -0
- package/package.json +3 -2
- package/report.api.md +0 -2
- package/tmp/api-report-tmp.d.ts +0 -2
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +0 -53
- package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -33
- package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -46
- package/dist/types/presets/css-to-design-tokens/utils/meta.d.ts +0 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/utils/meta.d.ts +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import designTokens from '@atlaskit/tokens/token-names';
|
|
3
|
+
import { extractCssVarName } from './declaration';
|
|
4
|
+
import { knownVariables, knownRawColors, knownNamedColors } from './legacy-colors';
|
|
5
|
+
var getUniqueWordsFromTokens = Object.keys(designTokens).reduce(function (accum, val) {
|
|
6
|
+
return [].concat(_toConsumableArray(accum), _toConsumableArray(val.split('.')));
|
|
7
|
+
}, []).reduce(function (accum, val) {
|
|
8
|
+
return [].concat(_toConsumableArray(accum), _toConsumableArray(val.split(/(?=[A-Z])/g).map(function (e) {
|
|
9
|
+
return e.toLowerCase();
|
|
10
|
+
})));
|
|
11
|
+
}, []).reduce(function (accum, val) {
|
|
12
|
+
if (!accum.includes(val)) {
|
|
13
|
+
accum.push(val);
|
|
14
|
+
}
|
|
15
|
+
return accum;
|
|
16
|
+
}, []);
|
|
17
|
+
function filterDuplciateFoundations(meta) {
|
|
18
|
+
var foundations = ['text', 'background', 'shadow', 'border'];
|
|
19
|
+
var hasFoundation = false;
|
|
20
|
+
return meta.filter(function (val) {
|
|
21
|
+
if (!hasFoundation && foundations.includes(val)) {
|
|
22
|
+
hasFoundation = true;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (hasFoundation && foundations.includes(val)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
var REPLACEMENTS = {
|
|
32
|
+
':': '',
|
|
33
|
+
',': '',
|
|
34
|
+
texts: 'text',
|
|
35
|
+
error: 'danger',
|
|
36
|
+
invalid: 'danger',
|
|
37
|
+
removed: 'danger',
|
|
38
|
+
removal: 'danger',
|
|
39
|
+
remove: 'danger',
|
|
40
|
+
focus: 'focused',
|
|
41
|
+
valid: 'success',
|
|
42
|
+
successful: 'success',
|
|
43
|
+
risk: 'warning',
|
|
44
|
+
caution: 'warning',
|
|
45
|
+
warn: 'warning',
|
|
46
|
+
primary: 'bold',
|
|
47
|
+
info: 'bold',
|
|
48
|
+
secondary: 'subtle',
|
|
49
|
+
hyperlink: 'link',
|
|
50
|
+
anchor: 'link',
|
|
51
|
+
active: 'pressed',
|
|
52
|
+
hover: 'hovered',
|
|
53
|
+
dragged: 'overlay',
|
|
54
|
+
dragging: 'overlay',
|
|
55
|
+
drag: 'overlay',
|
|
56
|
+
'background-color': 'background',
|
|
57
|
+
color: 'text',
|
|
58
|
+
icons: 'icon',
|
|
59
|
+
arrow: 'icon',
|
|
60
|
+
glyph: 'icon',
|
|
61
|
+
stroke: 'border',
|
|
62
|
+
'border-left': 'border',
|
|
63
|
+
'border-right': 'border',
|
|
64
|
+
'border-top': 'border',
|
|
65
|
+
'border-bottom': 'border',
|
|
66
|
+
'box-shadow': 'shadow'
|
|
67
|
+
};
|
|
68
|
+
var ADDITIONAL_META = {
|
|
69
|
+
grey: 'neutral',
|
|
70
|
+
red: 'danger'
|
|
71
|
+
};
|
|
72
|
+
export function cleanMeta(meta) {
|
|
73
|
+
var cleanMeta = meta.reduce(function (accum, val) {
|
|
74
|
+
return [].concat(_toConsumableArray(accum), _toConsumableArray(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
75
|
+
return e.toLowerCase();
|
|
76
|
+
}) : []));
|
|
77
|
+
}, []).reduce(function (accum, val) {
|
|
78
|
+
if (val in ADDITIONAL_META) {
|
|
79
|
+
accum.push(val, ADDITIONAL_META[val]);
|
|
80
|
+
} else {
|
|
81
|
+
accum.push(val);
|
|
82
|
+
}
|
|
83
|
+
accum.push(val in REPLACEMENTS ? REPLACEMENTS[val] : val);
|
|
84
|
+
return accum;
|
|
85
|
+
}, []).filter(function (val) {
|
|
86
|
+
return getUniqueWordsFromTokens.includes(val);
|
|
87
|
+
}).reduce(function (accum, val) {
|
|
88
|
+
if (!accum.includes(val)) {
|
|
89
|
+
accum.push(val);
|
|
90
|
+
}
|
|
91
|
+
return accum;
|
|
92
|
+
}, []);
|
|
93
|
+
return filterDuplciateFoundations(cleanMeta);
|
|
94
|
+
}
|
|
95
|
+
export function getBaseDeclarationMeta(decl) {
|
|
96
|
+
var parentSelectors = getParentSelectors(decl).split(/\-|\.|\,|\ |\:|\&/).filter(Boolean);
|
|
97
|
+
return [getPropertyMeta(decl.prop)].concat(_toConsumableArray(parentSelectors));
|
|
98
|
+
}
|
|
99
|
+
function getPropertyMeta(prop) {
|
|
100
|
+
if (prop === 'color') {
|
|
101
|
+
return 'text';
|
|
102
|
+
}
|
|
103
|
+
if (prop.startsWith('background')) {
|
|
104
|
+
return 'background';
|
|
105
|
+
}
|
|
106
|
+
if (prop.includes('shadow')) {
|
|
107
|
+
return 'shadow';
|
|
108
|
+
}
|
|
109
|
+
if (prop.includes('border')) {
|
|
110
|
+
return 'border';
|
|
111
|
+
}
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
function isRule(node) {
|
|
115
|
+
return node.type === 'rule';
|
|
116
|
+
}
|
|
117
|
+
function getParentSelectors(node) {
|
|
118
|
+
if (isRule(node)) {
|
|
119
|
+
// @ts-expect-error
|
|
120
|
+
return getParentSelectors(node.parent) + ' ' + node.selector;
|
|
121
|
+
}
|
|
122
|
+
if (node.parent) {
|
|
123
|
+
return getParentSelectors(node.parent);
|
|
124
|
+
}
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
export function getCssVarMeta(cssVariable) {
|
|
128
|
+
var tokenName = extractCssVarName(cssVariable);
|
|
129
|
+
var meta = knownVariables[tokenName];
|
|
130
|
+
if (!meta || meta.length === 0) {
|
|
131
|
+
return tokenName.split('-');
|
|
132
|
+
}
|
|
133
|
+
return meta;
|
|
134
|
+
}
|
|
135
|
+
export function getRawColorMeta(rawColor) {
|
|
136
|
+
var _knownRawColors$clean;
|
|
137
|
+
var cleanColor = rawColor.toLowerCase();
|
|
138
|
+
if (cleanColor.length === 4) {
|
|
139
|
+
cleanColor = cleanColor + cleanColor.substring(cleanColor.indexOf('#') + 1);
|
|
140
|
+
}
|
|
141
|
+
return (_knownRawColors$clean = knownRawColors[cleanColor]) !== null && _knownRawColors$clean !== void 0 ? _knownRawColors$clean : [];
|
|
142
|
+
}
|
|
143
|
+
export function getNamedColorMeta(namedColor) {
|
|
144
|
+
var _knownNamedColors$nam;
|
|
145
|
+
return (_knownNamedColors$nam = knownNamedColors[namedColor]) !== null && _knownNamedColors$nam !== void 0 ? _knownNamedColors$nam : [];
|
|
146
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import designTokens from '@atlaskit/tokens/token-names';
|
|
2
|
+
import { light as rawTokens } from '@atlaskit/tokens/tokens-raw';
|
|
3
|
+
import Search from '../../theme-to-design-tokens/utils/fuzzy-search';
|
|
4
|
+
import { cleanMeta } from './meta';
|
|
5
|
+
var MISSING_TOKEN_NAME = 'MISSING_TOKEN';
|
|
6
|
+
var ACTIVE_TOKENS = rawTokens.filter(function (token) {
|
|
7
|
+
return token.attributes.state === 'active';
|
|
8
|
+
}).map(function (token) {
|
|
9
|
+
return token.name.replace(/\.\[default\]/g, '');
|
|
10
|
+
}).filter(function (token) {
|
|
11
|
+
return !token.includes('UNSAFE') && !token.includes('interaction');
|
|
12
|
+
});
|
|
13
|
+
var COLOR_TOKEN_SEARCH_TYPES = ['text', 'link', 'icon', 'border', 'background', 'blanket', 'skeleton', 'chart', 'surface', 'shadow'];
|
|
14
|
+
var createFuzzySearch = function createFuzzySearch(tokens) {
|
|
15
|
+
return Search(tokens, false);
|
|
16
|
+
};
|
|
17
|
+
function filterTokens(meta) {
|
|
18
|
+
var commonSearchTypes = COLOR_TOKEN_SEARCH_TYPES.filter(function (type) {
|
|
19
|
+
return meta.includes(type);
|
|
20
|
+
});
|
|
21
|
+
return commonSearchTypes.length !== 0 ? ACTIVE_TOKENS.filter(function (token) {
|
|
22
|
+
return commonSearchTypes.some(function (type) {
|
|
23
|
+
return token.startsWith("color.".concat(type)) || token.startsWith("elevation.".concat(type));
|
|
24
|
+
});
|
|
25
|
+
}) : ACTIVE_TOKENS;
|
|
26
|
+
}
|
|
27
|
+
export default function findToken(meta) {
|
|
28
|
+
var filteredTokens = filterTokens(meta);
|
|
29
|
+
var tokenFuzzySearch = createFuzzySearch(filteredTokens);
|
|
30
|
+
var cleanSearchTerms = cleanMeta(meta).join(' ');
|
|
31
|
+
var results = tokenFuzzySearch.get(cleanSearchTerms);
|
|
32
|
+
if (!results) {
|
|
33
|
+
return MISSING_TOKEN_NAME;
|
|
34
|
+
}
|
|
35
|
+
var candidates = results.map(function (result) {
|
|
36
|
+
return result[1];
|
|
37
|
+
});
|
|
38
|
+
var bestCandidate = designTokens[candidates[0]];
|
|
39
|
+
return bestCandidate;
|
|
40
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { extractBetweenParentheses, isGradient, isKnownCssVariable, isLessFunction, isNamedColor, isRawColor } from './colors';
|
|
3
|
+
import { extractCssVarName } from './declaration';
|
|
4
|
+
import { getCssVarMeta, getNamedColorMeta, getRawColorMeta } from './meta';
|
|
5
|
+
import findToken from './tokens';
|
|
6
|
+
import { logger } from './logger';
|
|
7
|
+
export default function parseValue(value) {
|
|
8
|
+
if (isLessFunction(value)) {
|
|
9
|
+
logger.warn('Cannot parse - less function detected, would cause compilation error');
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (isGradient(value)) {
|
|
13
|
+
return {
|
|
14
|
+
getReplacement: function getReplacement() {
|
|
15
|
+
var additionalMeta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
16
|
+
var gradientContent = extractBetweenParentheses(value);
|
|
17
|
+
var values = gradientContent.split(',');
|
|
18
|
+
var replacedValues = values.map(function (val) {
|
|
19
|
+
var parsedValue = parseValue(val.trim());
|
|
20
|
+
return parsedValue ? parsedValue.getReplacement(additionalMeta) : val;
|
|
21
|
+
});
|
|
22
|
+
return value.replace(gradientContent, replacedValues.join(', '));
|
|
23
|
+
},
|
|
24
|
+
getMeta: function getMeta() {
|
|
25
|
+
var BASE_META = [];
|
|
26
|
+
var gradientContent = extractBetweenParentheses(value);
|
|
27
|
+
var values = gradientContent.split(',');
|
|
28
|
+
var metas = values.reduce(function (acc, val) {
|
|
29
|
+
var parsedValue = parseValue(val.trim());
|
|
30
|
+
return parsedValue ? [].concat(_toConsumableArray(acc), _toConsumableArray(parsedValue.getMeta())) : acc;
|
|
31
|
+
}, BASE_META);
|
|
32
|
+
return metas;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (isKnownCssVariable(extractCssVarName(value))) {
|
|
37
|
+
return {
|
|
38
|
+
getReplacement: function getReplacement() {
|
|
39
|
+
var additionalMeta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
40
|
+
var token = findToken([].concat(_toConsumableArray(additionalMeta), _toConsumableArray(this.getMeta())));
|
|
41
|
+
return "var(".concat(token, ", ").concat(value, ")");
|
|
42
|
+
},
|
|
43
|
+
getMeta: function getMeta() {
|
|
44
|
+
return getCssVarMeta(value);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (isRawColor(value)) {
|
|
49
|
+
return {
|
|
50
|
+
getReplacement: function getReplacement() {
|
|
51
|
+
var additionalMeta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
52
|
+
var token = findToken([].concat(_toConsumableArray(additionalMeta), _toConsumableArray(this.getMeta())));
|
|
53
|
+
return "var(".concat(token, ", ").concat(value, ")");
|
|
54
|
+
},
|
|
55
|
+
getMeta: function getMeta() {
|
|
56
|
+
return getRawColorMeta(value);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (isNamedColor(value)) {
|
|
61
|
+
return {
|
|
62
|
+
getReplacement: function getReplacement() {
|
|
63
|
+
var additionalMeta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
64
|
+
var token = findToken([].concat(_toConsumableArray(additionalMeta), _toConsumableArray(this.getMeta())));
|
|
65
|
+
return "var(".concat(token, ", ").concat(value, ")");
|
|
66
|
+
},
|
|
67
|
+
getMeta: function getMeta() {
|
|
68
|
+
return getNamedColorMeta(value);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
@@ -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
|
-
|
|
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;
|
package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
ADDED
|
@@ -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'];
|
|
@@ -332,8 +332,8 @@ function _transformer() {
|
|
|
332
332
|
|
|
333
333
|
// JSX props
|
|
334
334
|
source.find(j.JSXAttribute).forEach(function (path) {
|
|
335
|
-
var _path$value
|
|
336
|
-
if (((_path$value = path.value) === null || _path$value === void 0
|
|
335
|
+
var _path$value;
|
|
336
|
+
if (((_path$value = path.value) === null || _path$value === void 0 || (_path$value = _path$value.value) === null || _path$value === void 0 ? void 0 : _path$value.type) !== 'JSXExpressionContainer') {
|
|
337
337
|
return;
|
|
338
338
|
}
|
|
339
339
|
if (isParentOfToken(j, path)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isColorRelatedProperty } from '../../css-to-design-tokens/lib/declaration';
|
|
2
2
|
export function containsReplaceableCSSDeclarations(input) {
|
|
3
3
|
var cssPattern = /(\S+)\s*:/g;
|
|
4
4
|
var match;
|
|
5
5
|
while ((match = cssPattern.exec(input)) !== null) {
|
|
6
|
-
if (
|
|
6
|
+
if (isColorRelatedProperty(match[1])) {
|
|
7
7
|
return true;
|
|
8
8
|
}
|
|
9
9
|
}
|
package/dist/types/main.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function isKnownCssVariable(value: string): boolean;
|
|
2
|
+
export declare function isRawColor(value: string): boolean;
|
|
3
|
+
export declare function isNamedColor(value: string): boolean;
|
|
4
|
+
export declare function isGradient(value: string): boolean;
|
|
5
|
+
export declare function extractBetweenParentheses(value: string): string;
|
|
6
|
+
export declare function isLessFunction(value: string): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function isColorRelatedProperty(prop: string): boolean;
|
|
2
|
+
export declare function isCssDeclaration(prop: string): boolean;
|
|
3
|
+
export declare function extractCssVarName(prop: string): string;
|
|
4
|
+
export declare function extractLessVarName(prop: string): string;
|
|
5
|
+
export declare function splitCssValue(value: string): RegExpMatchArray | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Declaration } from 'postcss';
|
|
2
|
+
export declare function cleanMeta(meta: string[]): string[];
|
|
3
|
+
export declare function getBaseDeclarationMeta(decl: Declaration): string[];
|
|
4
|
+
export declare function getCssVarMeta(cssVariable: string): string[];
|
|
5
|
+
export declare function getRawColorMeta(rawColor: string): string[];
|
|
6
|
+
export declare function getNamedColorMeta(namedColor: string): string[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import designTokens from '@atlaskit/tokens/token-names';
|
|
2
|
+
type DesignTokensMap = typeof designTokens;
|
|
3
|
+
type DesignTokenJs = keyof DesignTokensMap;
|
|
4
|
+
type DesignTokenCss = DesignTokensMap[DesignTokenJs];
|
|
5
|
+
declare const MISSING_TOKEN_NAME = "MISSING_TOKEN";
|
|
6
|
+
export default function findToken(meta: string[]): DesignTokenCss | typeof MISSING_TOKEN_NAME;
|
|
7
|
+
export {};
|
|
@@ -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,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[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function isKnownCssVariable(value: string): boolean;
|
|
2
|
+
export declare function isRawColor(value: string): boolean;
|
|
3
|
+
export declare function isNamedColor(value: string): boolean;
|
|
4
|
+
export declare function isGradient(value: string): boolean;
|
|
5
|
+
export declare function extractBetweenParentheses(value: string): string;
|
|
6
|
+
export declare function isLessFunction(value: string): boolean;
|