@atlaskit/codemod-cli 0.11.4 → 0.12.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 +17 -0
- package/dist/cjs/cli.js +72 -75
- package/dist/cjs/filepath.js +29 -83
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/main.js +165 -441
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +44 -135
- package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -4
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +6 -29
- package/dist/cjs/presets/index.js +2 -9
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +13 -25
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +34 -82
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +14 -41
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +0 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +9 -28
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +44 -106
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +2 -22
- package/dist/cjs/sinceRef.js +36 -92
- package/dist/cjs/transforms.js +27 -72
- package/dist/cjs/types.js +2 -45
- package/dist/cjs/utils.js +7 -20
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/filepath.js +7 -5
- package/dist/es2019/main.js +17 -51
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +19 -51
- package/dist/es2019/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
- package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -6
- package/dist/es2019/presets/index.js +1 -1
- package/dist/es2019/presets/styled-to-emotion/styled-to-emotion.js +1 -4
- package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -14
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
- package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +2 -7
- package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
- package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +0 -1
- package/dist/es2019/sinceRef.js +2 -11
- package/dist/es2019/transforms.js +3 -13
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/utils.js +1 -12
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cli.js +53 -57
- package/dist/esm/filepath.js +51 -63
- package/dist/esm/main.js +221 -322
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +33 -71
- package/dist/esm/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
- package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -6
- package/dist/esm/presets/index.js +1 -1
- package/dist/esm/presets/styled-to-emotion/styled-to-emotion.js +1 -4
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -15
- package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
- package/dist/esm/presets/theme-to-design-tokens/utils/color.js +2 -7
- package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
- package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +0 -1
- package/dist/esm/sinceRef.js +49 -65
- package/dist/esm/transforms.js +4 -14
- package/dist/esm/types.js +1 -11
- package/dist/esm/utils.js +1 -12
- package/dist/esm/version.json +1 -1
- package/package.json +2 -2
- package/tmp/api-report-tmp.d.ts +0 -66
|
@@ -2,8 +2,8 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
-
import postcss from 'postcss';
|
|
6
|
-
|
|
5
|
+
import postcss from 'postcss';
|
|
6
|
+
// @ts-ignore
|
|
7
7
|
import lessSyntax from 'postcss-less';
|
|
8
8
|
import { light as rawTokens } from '@atlaskit/tokens/tokens-raw';
|
|
9
9
|
import designTokens from '@atlaskit/tokens/token-names';
|
|
@@ -18,88 +18,68 @@ var tokens = rawTokens.filter(function (t) {
|
|
|
18
18
|
return !t.includes('UNSAFE') && !t.includes('interaction');
|
|
19
19
|
});
|
|
20
20
|
var search = Search(tokens, false);
|
|
21
|
-
|
|
22
21
|
function isRule(node) {
|
|
23
22
|
return node.type === 'rule';
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
function getParentSelectors(node) {
|
|
27
25
|
if (isRule(node)) {
|
|
28
26
|
// @ts-expect-error
|
|
29
27
|
return getParentSelectors(node.parent) + ' ' + node.selector;
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
if (node.parent) {
|
|
33
30
|
return getParentSelectors(node.parent);
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
return '';
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
function stripVar(prop) {
|
|
40
35
|
return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
function stripLessVar(prop) {
|
|
44
38
|
return prop.substring(1);
|
|
45
39
|
}
|
|
46
|
-
|
|
47
40
|
function isColorProperty(prop) {
|
|
48
41
|
return prop === 'color' || prop === 'background' || prop === 'background-color' || prop === 'box-shadow' || prop === 'border' || prop === 'border-left' || prop === 'border-right' || prop === 'border-top' || prop === 'border-bottom' || prop === 'border-color';
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
function getDeclarationMeta(decl) {
|
|
52
44
|
if (decl.prop === 'color') {
|
|
53
45
|
return 'text';
|
|
54
46
|
}
|
|
55
|
-
|
|
56
47
|
if (decl.prop.startsWith('background')) {
|
|
57
48
|
return 'background';
|
|
58
49
|
}
|
|
59
|
-
|
|
60
50
|
if (decl.prop.includes('shadow')) {
|
|
61
51
|
return 'shadow';
|
|
62
52
|
}
|
|
63
|
-
|
|
64
53
|
if (decl.prop.includes('border')) {
|
|
65
54
|
return 'border';
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
return '';
|
|
69
57
|
}
|
|
70
|
-
|
|
71
58
|
function isDesignToken(tokenName) {
|
|
72
59
|
return Boolean(Object.entries(designTokens).find(function (_ref) {
|
|
73
60
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
_ = _ref2[0],
|
|
62
|
+
value = _ref2[1];
|
|
77
63
|
return tokenName === value;
|
|
78
64
|
}));
|
|
79
65
|
}
|
|
80
|
-
|
|
81
66
|
function getMetaFromCssVar(tokenName) {
|
|
82
67
|
var meta = knownVariables[tokenName];
|
|
83
|
-
|
|
84
68
|
if (!meta || meta.length === 0) {
|
|
85
69
|
return tokenName.split('-');
|
|
86
70
|
}
|
|
87
|
-
|
|
88
71
|
return meta;
|
|
89
72
|
}
|
|
90
|
-
|
|
91
73
|
function getMetaFromRawColor(rawColor) {
|
|
92
74
|
var cleanColor = rawColor.toLowerCase();
|
|
93
|
-
|
|
94
75
|
if (cleanColor.length === 4) {
|
|
95
76
|
cleanColor = cleanColor + cleanColor.substring(cleanColor.indexOf('#') + 1);
|
|
96
77
|
}
|
|
97
|
-
|
|
98
78
|
return knownRawColors[cleanColor];
|
|
99
|
-
}
|
|
100
|
-
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
101
|
-
|
|
79
|
+
}
|
|
102
80
|
|
|
81
|
+
// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
|
|
82
|
+
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
103
83
|
var plugin = function plugin() {
|
|
104
84
|
var processed = Symbol('processed');
|
|
105
85
|
return {
|
|
@@ -109,106 +89,88 @@ var plugin = function plugin() {
|
|
|
109
89
|
if (decl[processed]) {
|
|
110
90
|
return;
|
|
111
91
|
}
|
|
112
|
-
|
|
113
92
|
if (!isColorProperty(decl.prop)) {
|
|
114
93
|
return;
|
|
115
94
|
}
|
|
116
|
-
|
|
117
95
|
var searchTerms = [getDeclarationMeta(decl)].concat(_toConsumableArray(getParentSelectors(decl).split(/\-|\.|\,|\ |\:|\&/).filter(function (el) {
|
|
118
96
|
return !!el;
|
|
119
97
|
})));
|
|
120
98
|
var match;
|
|
121
99
|
var cssVarRe = /var\([^\)]+\)/g;
|
|
122
100
|
var lessVarRe = /@[a-zA-Z0-9-]+/g;
|
|
123
|
-
var rawColorRe = /(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\d{1,3}%?(,\s?\d{1,3}%?){2},\s?(1|0|0?\.\d+)\)|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\))/i;
|
|
101
|
+
var rawColorRe = /(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\d{1,3}%?(,\s?\d{1,3}%?){2},\s?(1|0|0?\.\d+)\)|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\))/i;
|
|
124
102
|
|
|
103
|
+
// CSS variables
|
|
125
104
|
var cssVarMatch = decl.value.match(cssVarRe);
|
|
126
|
-
|
|
127
105
|
if (cssVarMatch) {
|
|
128
106
|
var _getMetaFromCssVar;
|
|
129
|
-
|
|
130
107
|
match = cssVarMatch[0];
|
|
131
|
-
|
|
132
108
|
if (isDesignToken(stripVar(match))) {
|
|
133
109
|
return;
|
|
134
110
|
}
|
|
135
|
-
|
|
136
111
|
searchTerms.push.apply(searchTerms, _toConsumableArray((_getMetaFromCssVar = getMetaFromCssVar(stripVar(match))) !== null && _getMetaFromCssVar !== void 0 ? _getMetaFromCssVar : []));
|
|
137
|
-
}
|
|
138
|
-
|
|
112
|
+
}
|
|
139
113
|
|
|
114
|
+
// Less variables
|
|
140
115
|
var lassVarMatch = decl.value.match(lessVarRe);
|
|
141
|
-
|
|
142
116
|
if (lassVarMatch) {
|
|
143
117
|
var _getMetaFromCssVar2;
|
|
144
|
-
|
|
145
118
|
match = lassVarMatch[0];
|
|
146
119
|
searchTerms.push.apply(searchTerms, _toConsumableArray((_getMetaFromCssVar2 = getMetaFromCssVar("--".concat(stripLessVar(match)))) !== null && _getMetaFromCssVar2 !== void 0 ? _getMetaFromCssVar2 : []));
|
|
147
|
-
}
|
|
148
|
-
|
|
120
|
+
}
|
|
149
121
|
|
|
122
|
+
// Raw colors
|
|
150
123
|
var rawColorMatch = decl.value.match(rawColorRe);
|
|
151
|
-
|
|
152
124
|
if (rawColorMatch) {
|
|
153
125
|
var _getMetaFromRawColor;
|
|
154
|
-
|
|
155
126
|
match = rawColorMatch[0];
|
|
156
127
|
searchTerms.push.apply(searchTerms, _toConsumableArray((_getMetaFromRawColor = getMetaFromRawColor(match)) !== null && _getMetaFromRawColor !== void 0 ? _getMetaFromRawColor : []));
|
|
157
|
-
}
|
|
158
|
-
|
|
128
|
+
}
|
|
159
129
|
|
|
130
|
+
// Named colors
|
|
160
131
|
if (knownColors.hasOwnProperty(decl.value)) {
|
|
161
132
|
var _knownColors$decl$val;
|
|
162
|
-
|
|
163
133
|
match = decl.value;
|
|
164
134
|
searchTerms.push.apply(searchTerms, _toConsumableArray((_knownColors$decl$val = knownColors[decl.value.toLowerCase()]) !== null && _knownColors$decl$val !== void 0 ? _knownColors$decl$val : []));
|
|
165
135
|
}
|
|
166
|
-
|
|
167
136
|
if (!match) {
|
|
168
137
|
console.warn("Unable to find match for declaration: ".concat(decl.prop, ": ").concat(decl.value));
|
|
169
138
|
return;
|
|
170
139
|
}
|
|
171
|
-
|
|
172
140
|
var cleanSearchTerms = cleanMeta(searchTerms).join(' ');
|
|
173
141
|
var results = search.get(cleanSearchTerms);
|
|
174
|
-
var
|
|
142
|
+
var candidates = results.map(function (result) {
|
|
175
143
|
return result[1];
|
|
176
|
-
})
|
|
177
|
-
|
|
144
|
+
});
|
|
145
|
+
var replacement = candidates.length ? designTokens[candidates[0]] : 'MISSING_TOKEN';
|
|
178
146
|
if (decl.prop === 'box-shadow') {
|
|
179
|
-
decl.value = "var(".concat(
|
|
147
|
+
decl.value = "var(".concat(replacement, ", ").concat(decl.value, ")");
|
|
180
148
|
} else {
|
|
181
|
-
decl.value = decl.value.split(match).join("var(".concat(
|
|
182
|
-
}
|
|
183
|
-
|
|
149
|
+
decl.value = decl.value.split(match).join("var(".concat(replacement, ", ").concat(match, ")"));
|
|
150
|
+
}
|
|
184
151
|
|
|
152
|
+
// @ts-expect-error
|
|
185
153
|
decl[processed] = true;
|
|
186
154
|
}
|
|
187
155
|
};
|
|
188
156
|
};
|
|
189
|
-
|
|
190
157
|
export default function transformer(_x) {
|
|
191
158
|
return _transformer.apply(this, arguments);
|
|
192
159
|
}
|
|
193
|
-
|
|
194
160
|
function _transformer() {
|
|
195
161
|
_transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file) {
|
|
196
162
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
197
|
-
while (1) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
case 3:
|
|
209
|
-
case "end":
|
|
210
|
-
return _context.stop();
|
|
211
|
-
}
|
|
163
|
+
while (1) switch (_context.prev = _context.next) {
|
|
164
|
+
case 0:
|
|
165
|
+
_context.next = 2;
|
|
166
|
+
return postcss([plugin()]).process(file.source, {
|
|
167
|
+
syntax: lessSyntax
|
|
168
|
+
}).css;
|
|
169
|
+
case 2:
|
|
170
|
+
return _context.abrupt("return", _context.sent);
|
|
171
|
+
case 3:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context.stop();
|
|
212
174
|
}
|
|
213
175
|
}, _callee);
|
|
214
176
|
}));
|
|
@@ -150,7 +150,6 @@ export var knownVariables = {
|
|
|
150
150
|
'--adg3-color-green-light': ['accent', 'subtler', 'green'],
|
|
151
151
|
'--adg3-color-green-dark': ['accent', 'bolder', 'green'],
|
|
152
152
|
'--adg3-color-N20-transparent': [],
|
|
153
|
-
|
|
154
153
|
/* Alias variables */
|
|
155
154
|
'--jpo-theme-color': ['brand'],
|
|
156
155
|
'--jpo-text-default-color': ['text'],
|
|
@@ -10,10 +10,8 @@ var getUniqueWordsFromTokens = Object.keys(designTokens).reduce(function (accum,
|
|
|
10
10
|
if (!accum.includes(val)) {
|
|
11
11
|
accum.push(val);
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
return accum;
|
|
15
14
|
}, []);
|
|
16
|
-
|
|
17
15
|
function filterDuplciateFoundations(meta) {
|
|
18
16
|
var foundations = ['text', 'background', 'shadow', 'border'];
|
|
19
17
|
var hasFoundation = false;
|
|
@@ -22,15 +20,12 @@ function filterDuplciateFoundations(meta) {
|
|
|
22
20
|
hasFoundation = true;
|
|
23
21
|
return true;
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
if (hasFoundation && foundations.includes(val)) {
|
|
27
24
|
return false;
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
return true;
|
|
31
27
|
});
|
|
32
28
|
}
|
|
33
|
-
|
|
34
29
|
export function cleanMeta(meta) {
|
|
35
30
|
var cleanMeta = meta.reduce(function (accum, val) {
|
|
36
31
|
return [].concat(_toConsumableArray(accum), _toConsumableArray(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
@@ -45,7 +40,6 @@ export function cleanMeta(meta) {
|
|
|
45
40
|
if (!accum.includes(val)) {
|
|
46
41
|
accum.push(val);
|
|
47
42
|
}
|
|
48
|
-
|
|
49
43
|
return accum;
|
|
50
44
|
}, []);
|
|
51
45
|
return filterDuplciateFoundations(cleanMeta);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Manually import presets to make sure typescript includes them
|
|
4
5
|
* in the final bundle
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
import './styled-to-emotion/styled-to-emotion';
|
|
8
8
|
import './theme-to-design-tokens/theme-to-design-tokens';
|
|
9
9
|
import './css-to-design-tokens/css-to-design-tokens';
|
|
@@ -8,14 +8,12 @@ function buildCoreImportDeclaration(j, path) {
|
|
|
8
8
|
});
|
|
9
9
|
return specifiers.length ? j.importDeclaration(specifiers, j.literal('@emotion/core')) : null;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
function buildStyledImportDeclaration(j, path) {
|
|
13
12
|
var specifier = j(path).find(j.ImportDefaultSpecifier).filter(function (specifier) {
|
|
14
13
|
return specifier.value.local.name === 'styled';
|
|
15
14
|
});
|
|
16
15
|
return specifier && specifier.length ? j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.get(0).node.local.name))], j.literal('@emotion/styled')) : null;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
function buildThemingImportDeclaration(j, path) {
|
|
20
18
|
var themingExports = ['ThemeProvider', 'withTheme'];
|
|
21
19
|
var specifiers = [];
|
|
@@ -26,11 +24,10 @@ function buildThemingImportDeclaration(j, path) {
|
|
|
26
24
|
});
|
|
27
25
|
return specifiers && specifiers.length ? j.importDeclaration(specifiers, j.literal('emotion-theming')) : null;
|
|
28
26
|
}
|
|
27
|
+
|
|
29
28
|
/**
|
|
30
29
|
* Converts all imports of `styled-components` to `@emotion/styled`
|
|
31
30
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
31
|
export default function transformer(fileInfo, _ref, options) {
|
|
35
32
|
var j = _ref.jscodeshift;
|
|
36
33
|
var source = j(fileInfo.source).find(j.ImportDeclaration).filter(function (path) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
|
|
3
2
|
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
4
|
import { isDecendantOfToken, isDecendantOfType } from './utils/ast';
|
|
5
5
|
import { cleanMeta, getMetaFromAncestors } from './utils/ast-meta';
|
|
6
6
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from './utils/color';
|
|
@@ -8,13 +8,11 @@ import Search from './utils/fuzzy-search';
|
|
|
8
8
|
import { legacyColorMetaMap } from './utils/legacy-colors';
|
|
9
9
|
import { tokens } from './utils/tokens';
|
|
10
10
|
var search = Search(tokens, false);
|
|
11
|
-
|
|
12
11
|
function hasImportDeclaration(j, source, sourcePath) {
|
|
13
12
|
return !!source.find(j.ImportDeclaration).filter(function (path) {
|
|
14
13
|
return path.node.source.value === sourcePath;
|
|
15
14
|
}).length;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
function hasImportSpecifier(j, source, specifier, sourcePath) {
|
|
19
17
|
return !!source.find(j.ImportDeclaration).filter(function (path) {
|
|
20
18
|
return path.node.source.value === sourcePath;
|
|
@@ -24,43 +22,37 @@ function hasImportSpecifier(j, source, specifier, sourcePath) {
|
|
|
24
22
|
}
|
|
25
23
|
}).length;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
function insertTokenImport(j, source) {
|
|
29
26
|
if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
|
|
30
27
|
return;
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
34
30
|
source.get().node.program.body.unshift(newImport);
|
|
35
31
|
}
|
|
36
|
-
|
|
37
32
|
function buildToken(j, tokenId, node) {
|
|
38
33
|
var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
39
34
|
return callExpr;
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
function getTokenFromNode(j, path) {
|
|
43
37
|
var baseMeta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
44
38
|
var foundMeta = getMetaFromAncestors(j, path);
|
|
45
39
|
var meta = cleanMeta([].concat(_toConsumableArray(foundMeta), _toConsumableArray(baseMeta)));
|
|
46
40
|
var results = search.get(meta.join(' '));
|
|
47
|
-
var tokenId = ['
|
|
48
|
-
|
|
41
|
+
var tokenId = ['MISSING_TOKEN'];
|
|
49
42
|
if (results) {
|
|
50
43
|
tokenId = results.map(function (result) {
|
|
51
44
|
return result[1];
|
|
52
45
|
});
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
return tokenId[0];
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
export default function transformer(file, api) {
|
|
59
50
|
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
60
51
|
var j = api.jscodeshift;
|
|
61
52
|
var source = j(file.source);
|
|
62
53
|
var transformed = false;
|
|
63
|
-
source
|
|
54
|
+
source
|
|
55
|
+
// Handle colors.N100
|
|
64
56
|
.find(j.MemberExpression).filter(function (path) {
|
|
65
57
|
return path.value.object.type === 'Identifier' && path.value.object.name === 'colors' && path.value.property.type === 'Identifier' && isLegacyColor(path.value.property.name);
|
|
66
58
|
}).filter(function (path) {
|
|
@@ -111,7 +103,6 @@ export default function transformer(file, api) {
|
|
|
111
103
|
return !isDecendantOfToken(j, path);
|
|
112
104
|
}).forEach(function (path) {
|
|
113
105
|
var _path$value, _path$value$value;
|
|
114
|
-
|
|
115
106
|
debug && console.log('file:', file.path);
|
|
116
107
|
insertTokenImport(j, source);
|
|
117
108
|
var value = path === null || path === void 0 ? void 0 : (_path$value = path.value) === null || _path$value === void 0 ? void 0 : (_path$value$value = _path$value.value) === null || _path$value$value === void 0 ? void 0 : _path$value$value.toString();
|
|
@@ -121,10 +112,8 @@ export default function transformer(file, api) {
|
|
|
121
112
|
j(path).replaceWith(isDecendantOfType(j, path, j.JSXAttribute) ? j.jsxExpressionContainer(tokenNode) : tokenNode);
|
|
122
113
|
transformed = true;
|
|
123
114
|
});
|
|
124
|
-
|
|
125
115
|
if (transformed) {
|
|
126
116
|
return source.toSource();
|
|
127
117
|
}
|
|
128
|
-
|
|
129
118
|
return file.source;
|
|
130
119
|
}
|
|
@@ -4,19 +4,15 @@ export function getMetaFromAncestors(j, path) {
|
|
|
4
4
|
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
5
5
|
var parent = path.parentPath;
|
|
6
6
|
var grandParent = parent && parent.parentPath;
|
|
7
|
-
|
|
8
7
|
if (parent && parent.value.type === 'ObjectProperty') {
|
|
9
8
|
var value = '';
|
|
10
|
-
|
|
11
9
|
if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
|
|
12
10
|
value = parent.value.key.value.toString();
|
|
13
11
|
} else {
|
|
14
12
|
value = parent.value.key.name;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
meta.push(value);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
21
17
|
var expressionIndex = grandParent.value.expressions.findIndex(function (exp) {
|
|
22
18
|
return exp.name === path.value.name;
|
|
@@ -27,10 +23,10 @@ export function getMetaFromAncestors(j, path) {
|
|
|
27
23
|
}).pop().split(/:/g)[0].trim();
|
|
28
24
|
grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
|
|
29
25
|
return q.value.cooked;
|
|
30
|
-
})
|
|
26
|
+
})
|
|
27
|
+
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
31
28
|
.reverse().some(function (str) {
|
|
32
29
|
var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
33
|
-
|
|
34
30
|
if (result) {
|
|
35
31
|
meta.push(result[0]);
|
|
36
32
|
return true;
|
|
@@ -38,21 +34,17 @@ export function getMetaFromAncestors(j, path) {
|
|
|
38
34
|
});
|
|
39
35
|
meta.push(propertyName);
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
if (parent && parent.value.type === 'JSXAttribute') {
|
|
43
38
|
if (!['css', 'styles', 'style'].includes(parent.value.name.name)) {
|
|
44
39
|
meta.push(parent.value.name.name);
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
49
43
|
meta.push(parent.value.id.name);
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
if (parent) {
|
|
53
46
|
return getMetaFromAncestors(j, parent, meta);
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
return meta;
|
|
57
49
|
}
|
|
58
50
|
export function cleanMeta(meta) {
|
|
@@ -69,7 +61,6 @@ export function cleanMeta(meta) {
|
|
|
69
61
|
if (!accum.includes(val)) {
|
|
70
62
|
accum.push(val);
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
return accum;
|
|
74
65
|
}, []);
|
|
75
66
|
}
|
|
@@ -8,32 +8,27 @@ export var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
|
8
8
|
};
|
|
9
9
|
export var includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
10
10
|
var value = raw.toLowerCase();
|
|
11
|
-
|
|
12
11
|
if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
|
|
13
12
|
return true;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
for (var i = 0; i < namedColors.length; i++) {
|
|
17
15
|
if (value.includes("".concat(namedColors[i], ";"))) {
|
|
18
16
|
return true;
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
return false;
|
|
23
20
|
};
|
|
24
21
|
export var isHardCodedColor = function isHardCodedColor(value) {
|
|
25
22
|
if (namedColors.includes(value.toLowerCase())) {
|
|
26
23
|
return true;
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
|
|
30
26
|
return true;
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
if (value.startsWith('#') && (
|
|
29
|
+
// short hex, hex, or hex with alpha
|
|
34
30
|
value.length === 4 || value.length === 7 || value.length === 9)) {
|
|
35
31
|
return true;
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
return false;
|
|
39
34
|
};
|