@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
|
@@ -1,237 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = transformer;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
-
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
-
|
|
18
8
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
19
|
-
|
|
20
9
|
var _postcssLess = _interopRequireDefault(require("postcss-less"));
|
|
21
|
-
|
|
22
10
|
var _tokensRaw = require("@atlaskit/tokens/tokens-raw");
|
|
23
|
-
|
|
24
11
|
var _tokenNames = _interopRequireDefault(require("@atlaskit/tokens/token-names"));
|
|
25
|
-
|
|
26
12
|
var _fuzzySearch = _interopRequireDefault(require("../theme-to-design-tokens/utils/fuzzy-search"));
|
|
27
|
-
|
|
28
13
|
var _legacyColors = require("./utils/legacy-colors");
|
|
29
|
-
|
|
30
14
|
var _meta = require("./utils/meta");
|
|
31
|
-
|
|
32
15
|
// @ts-ignore
|
|
33
|
-
var tokens = _tokensRaw.light.filter(function (t) {
|
|
34
|
-
return t.attributes.state === 'active';
|
|
35
|
-
}).map(function (t) {
|
|
36
|
-
return t.name.replace(/\.\[default\]/g, '');
|
|
37
|
-
}).filter(function (t) {
|
|
38
|
-
return !t.includes('UNSAFE') && !t.includes('interaction');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
var search = (0, _fuzzySearch.default)(tokens, false);
|
|
42
16
|
|
|
17
|
+
const tokens = _tokensRaw.light.filter(t => t.attributes.state === 'active').map(t => t.name.replace(/\.\[default\]/g, '')).filter(t => !t.includes('UNSAFE') && !t.includes('interaction'));
|
|
18
|
+
const search = (0, _fuzzySearch.default)(tokens, false);
|
|
43
19
|
function isRule(node) {
|
|
44
20
|
return node.type === 'rule';
|
|
45
21
|
}
|
|
46
|
-
|
|
47
22
|
function getParentSelectors(node) {
|
|
48
23
|
if (isRule(node)) {
|
|
49
24
|
// @ts-expect-error
|
|
50
25
|
return getParentSelectors(node.parent) + ' ' + node.selector;
|
|
51
26
|
}
|
|
52
|
-
|
|
53
27
|
if (node.parent) {
|
|
54
28
|
return getParentSelectors(node.parent);
|
|
55
29
|
}
|
|
56
|
-
|
|
57
30
|
return '';
|
|
58
31
|
}
|
|
59
|
-
|
|
60
32
|
function stripVar(prop) {
|
|
61
33
|
return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
|
|
62
34
|
}
|
|
63
|
-
|
|
64
35
|
function stripLessVar(prop) {
|
|
65
36
|
return prop.substring(1);
|
|
66
37
|
}
|
|
67
|
-
|
|
68
38
|
function isColorProperty(prop) {
|
|
69
39
|
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';
|
|
70
40
|
}
|
|
71
|
-
|
|
72
41
|
function getDeclarationMeta(decl) {
|
|
73
42
|
if (decl.prop === 'color') {
|
|
74
43
|
return 'text';
|
|
75
44
|
}
|
|
76
|
-
|
|
77
45
|
if (decl.prop.startsWith('background')) {
|
|
78
46
|
return 'background';
|
|
79
47
|
}
|
|
80
|
-
|
|
81
48
|
if (decl.prop.includes('shadow')) {
|
|
82
49
|
return 'shadow';
|
|
83
50
|
}
|
|
84
|
-
|
|
85
51
|
if (decl.prop.includes('border')) {
|
|
86
52
|
return 'border';
|
|
87
53
|
}
|
|
88
|
-
|
|
89
54
|
return '';
|
|
90
55
|
}
|
|
91
|
-
|
|
92
56
|
function isDesignToken(tokenName) {
|
|
93
|
-
return Boolean(Object.entries(_tokenNames.default).find(
|
|
94
|
-
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
95
|
-
_ = _ref2[0],
|
|
96
|
-
value = _ref2[1];
|
|
97
|
-
|
|
98
|
-
return tokenName === value;
|
|
99
|
-
}));
|
|
57
|
+
return Boolean(Object.entries(_tokenNames.default).find(([_, value]) => tokenName === value));
|
|
100
58
|
}
|
|
101
|
-
|
|
102
59
|
function getMetaFromCssVar(tokenName) {
|
|
103
|
-
|
|
104
|
-
|
|
60
|
+
const meta = _legacyColors.knownVariables[tokenName];
|
|
105
61
|
if (!meta || meta.length === 0) {
|
|
106
62
|
return tokenName.split('-');
|
|
107
63
|
}
|
|
108
|
-
|
|
109
64
|
return meta;
|
|
110
65
|
}
|
|
111
|
-
|
|
112
66
|
function getMetaFromRawColor(rawColor) {
|
|
113
|
-
|
|
114
|
-
|
|
67
|
+
let cleanColor = rawColor.toLowerCase();
|
|
115
68
|
if (cleanColor.length === 4) {
|
|
116
69
|
cleanColor = cleanColor + cleanColor.substring(cleanColor.indexOf('#') + 1);
|
|
117
70
|
}
|
|
118
|
-
|
|
119
71
|
return _legacyColors.knownRawColors[cleanColor];
|
|
120
|
-
}
|
|
121
|
-
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
122
|
-
|
|
72
|
+
}
|
|
123
73
|
|
|
124
|
-
|
|
125
|
-
|
|
74
|
+
// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
|
|
75
|
+
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
76
|
+
const plugin = () => {
|
|
77
|
+
const processed = Symbol('processed');
|
|
126
78
|
return {
|
|
127
79
|
postcssPlugin: 'UsingTokens',
|
|
128
|
-
Declaration:
|
|
80
|
+
Declaration: decl => {
|
|
129
81
|
// @ts-expect-error
|
|
130
82
|
if (decl[processed]) {
|
|
131
83
|
return;
|
|
132
84
|
}
|
|
133
|
-
|
|
134
85
|
if (!isColorProperty(decl.prop)) {
|
|
135
86
|
return;
|
|
136
87
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var cssVarMatch = decl.value.match(cssVarRe);
|
|
147
|
-
|
|
88
|
+
const searchTerms = [getDeclarationMeta(decl), ...getParentSelectors(decl).split(/\-|\.|\,|\ |\:|\&/).filter(el => !!el)];
|
|
89
|
+
let match;
|
|
90
|
+
const cssVarRe = /var\([^\)]+\)/g;
|
|
91
|
+
const lessVarRe = /@[a-zA-Z0-9-]+/g;
|
|
92
|
+
const 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;
|
|
93
|
+
|
|
94
|
+
// CSS variables
|
|
95
|
+
const cssVarMatch = decl.value.match(cssVarRe);
|
|
148
96
|
if (cssVarMatch) {
|
|
149
|
-
var _getMetaFromCssVar;
|
|
150
|
-
|
|
151
97
|
match = cssVarMatch[0];
|
|
152
|
-
|
|
153
98
|
if (isDesignToken(stripVar(match))) {
|
|
154
99
|
return;
|
|
155
100
|
}
|
|
101
|
+
searchTerms.push(...(getMetaFromCssVar(stripVar(match)) ?? []));
|
|
102
|
+
}
|
|
156
103
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var lassVarMatch = decl.value.match(lessVarRe);
|
|
162
|
-
|
|
104
|
+
// Less variables
|
|
105
|
+
const lassVarMatch = decl.value.match(lessVarRe);
|
|
163
106
|
if (lassVarMatch) {
|
|
164
|
-
var _getMetaFromCssVar2;
|
|
165
|
-
|
|
166
107
|
match = lassVarMatch[0];
|
|
167
|
-
searchTerms.push
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var rawColorMatch = decl.value.match(rawColorRe);
|
|
108
|
+
searchTerms.push(...(getMetaFromCssVar(`--${stripLessVar(match)}`) ?? []));
|
|
109
|
+
}
|
|
172
110
|
|
|
111
|
+
// Raw colors
|
|
112
|
+
const rawColorMatch = decl.value.match(rawColorRe);
|
|
173
113
|
if (rawColorMatch) {
|
|
174
|
-
var _getMetaFromRawColor;
|
|
175
|
-
|
|
176
114
|
match = rawColorMatch[0];
|
|
177
|
-
searchTerms.push
|
|
178
|
-
}
|
|
179
|
-
|
|
115
|
+
searchTerms.push(...(getMetaFromRawColor(match) ?? []));
|
|
116
|
+
}
|
|
180
117
|
|
|
118
|
+
// Named colors
|
|
181
119
|
if (_legacyColors.knownColors.hasOwnProperty(decl.value)) {
|
|
182
|
-
var _knownColors$decl$val;
|
|
183
|
-
|
|
184
120
|
match = decl.value;
|
|
185
|
-
searchTerms.push
|
|
121
|
+
searchTerms.push(...(_legacyColors.knownColors[decl.value.toLowerCase()] ?? []));
|
|
186
122
|
}
|
|
187
|
-
|
|
188
123
|
if (!match) {
|
|
189
|
-
console.warn(
|
|
124
|
+
console.warn(`Unable to find match for declaration: ${decl.prop}: ${decl.value}`);
|
|
190
125
|
return;
|
|
191
126
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return result[1];
|
|
197
|
-
}) : ['utility.UNSAFE_util.MISSING_TOKEN'];
|
|
198
|
-
|
|
127
|
+
const cleanSearchTerms = (0, _meta.cleanMeta)(searchTerms).join(' ');
|
|
128
|
+
const results = search.get(cleanSearchTerms);
|
|
129
|
+
const candidates = results.map(result => result[1]);
|
|
130
|
+
const replacement = candidates.length ? _tokenNames.default[candidates[0]] : 'MISSING_TOKEN';
|
|
199
131
|
if (decl.prop === 'box-shadow') {
|
|
200
|
-
decl.value =
|
|
132
|
+
decl.value = `var(${replacement}, ${decl.value})`;
|
|
201
133
|
} else {
|
|
202
|
-
decl.value = decl.value.split(match).join(
|
|
203
|
-
}
|
|
204
|
-
|
|
134
|
+
decl.value = decl.value.split(match).join(`var(${replacement}, ${match})`);
|
|
135
|
+
}
|
|
205
136
|
|
|
137
|
+
// @ts-expect-error
|
|
206
138
|
decl[processed] = true;
|
|
207
139
|
}
|
|
208
140
|
};
|
|
209
141
|
};
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function _transformer() {
|
|
216
|
-
_transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file) {
|
|
217
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
218
|
-
while (1) {
|
|
219
|
-
switch (_context.prev = _context.next) {
|
|
220
|
-
case 0:
|
|
221
|
-
_context.next = 2;
|
|
222
|
-
return (0, _postcss.default)([plugin()]).process(file.source, {
|
|
223
|
-
syntax: _postcssLess.default
|
|
224
|
-
}).css;
|
|
225
|
-
|
|
226
|
-
case 2:
|
|
227
|
-
return _context.abrupt("return", _context.sent);
|
|
228
|
-
|
|
229
|
-
case 3:
|
|
230
|
-
case "end":
|
|
231
|
-
return _context.stop();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}, _callee);
|
|
235
|
-
}));
|
|
236
|
-
return _transformer.apply(this, arguments);
|
|
142
|
+
async function transformer(file) {
|
|
143
|
+
return await (0, _postcss.default)([plugin()]).process(file.source, {
|
|
144
|
+
syntax: _postcssLess.default
|
|
145
|
+
}).css;
|
|
237
146
|
}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.knownVariables = exports.knownRawColors = exports.knownColors = void 0;
|
|
7
|
-
|
|
7
|
+
const knownVariables = {
|
|
8
8
|
'--adg3-color-R50': ['danger'],
|
|
9
9
|
'--adg3-color-R75': ['danger'],
|
|
10
10
|
'--adg3-color-R100': ['danger'],
|
|
@@ -156,7 +156,6 @@ var knownVariables = {
|
|
|
156
156
|
'--adg3-color-green-light': ['accent', 'subtler', 'green'],
|
|
157
157
|
'--adg3-color-green-dark': ['accent', 'bolder', 'green'],
|
|
158
158
|
'--adg3-color-N20-transparent': [],
|
|
159
|
-
|
|
160
159
|
/* Alias variables */
|
|
161
160
|
'--jpo-theme-color': ['brand'],
|
|
162
161
|
'--jpo-text-default-color': ['text'],
|
|
@@ -171,7 +170,7 @@ var knownVariables = {
|
|
|
171
170
|
'--jpo-border-secondary-color': ['border', 'subtle']
|
|
172
171
|
};
|
|
173
172
|
exports.knownVariables = knownVariables;
|
|
174
|
-
|
|
173
|
+
const knownColors = {
|
|
175
174
|
aliceblue: ['blue'],
|
|
176
175
|
antiquewhite: [],
|
|
177
176
|
aqua: ['teal'],
|
|
@@ -321,7 +320,7 @@ var knownColors = {
|
|
|
321
320
|
yellowgreen: ['yellow']
|
|
322
321
|
};
|
|
323
322
|
exports.knownColors = knownColors;
|
|
324
|
-
|
|
323
|
+
const knownRawColors = {
|
|
325
324
|
'#000000': ['text'],
|
|
326
325
|
'#cccccc': ['border'],
|
|
327
326
|
'#aaaaaa': ['border'],
|
|
@@ -1,62 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.cleanMeta = cleanMeta;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
8
|
var _tokenNames = _interopRequireDefault(require("@atlaskit/tokens/token-names"));
|
|
13
|
-
|
|
14
|
-
var getUniqueWordsFromTokens = Object.keys(_tokenNames.default).reduce(function (accum, val) {
|
|
15
|
-
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(val.split('.')));
|
|
16
|
-
}, []).reduce(function (accum, val) {
|
|
17
|
-
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(val.split(/(?=[A-Z])/g).map(function (e) {
|
|
18
|
-
return e.toLowerCase();
|
|
19
|
-
})));
|
|
20
|
-
}, []).reduce(function (accum, val) {
|
|
9
|
+
const getUniqueWordsFromTokens = Object.keys(_tokenNames.default).reduce((accum, val) => [...accum, ...val.split('.')], []).reduce((accum, val) => [...accum, ...val.split(/(?=[A-Z])/g).map(e => e.toLowerCase())], []).reduce((accum, val) => {
|
|
21
10
|
if (!accum.includes(val)) {
|
|
22
11
|
accum.push(val);
|
|
23
12
|
}
|
|
24
|
-
|
|
25
13
|
return accum;
|
|
26
14
|
}, []);
|
|
27
|
-
|
|
28
15
|
function filterDuplciateFoundations(meta) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return meta.filter(
|
|
16
|
+
const foundations = ['text', 'background', 'shadow', 'border'];
|
|
17
|
+
let hasFoundation = false;
|
|
18
|
+
return meta.filter(val => {
|
|
32
19
|
if (!hasFoundation && foundations.includes(val)) {
|
|
33
20
|
hasFoundation = true;
|
|
34
21
|
return true;
|
|
35
22
|
}
|
|
36
|
-
|
|
37
23
|
if (hasFoundation && foundations.includes(val)) {
|
|
38
24
|
return false;
|
|
39
25
|
}
|
|
40
|
-
|
|
41
26
|
return true;
|
|
42
27
|
});
|
|
43
28
|
}
|
|
44
|
-
|
|
45
29
|
function cleanMeta(meta) {
|
|
46
|
-
|
|
47
|
-
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
48
|
-
return e.toLowerCase();
|
|
49
|
-
}) : []));
|
|
50
|
-
}, []).reduce(function (accum, val) {
|
|
30
|
+
const cleanMeta = meta.reduce((accum, val) => [...accum, ...(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(e => e.toLowerCase()) : [])], []).reduce((accum, val) => {
|
|
51
31
|
accum.push(val.replace(/:/g, '').replace(/,/g, '').replace('grey', 'neutral').replace('texts', 'text').replace('red', 'danger').replace('error', 'danger').replace('invalid', 'danger').replace('removed', 'danger').replace('removal', 'danger').replace('remove', 'danger').replace('focus', 'focused').replace('valid', 'success').replace('successful', 'success').replace('risk', 'warning').replace('caution', 'warning').replace('warn', 'warning').replace('primary', 'bold').replace('info', 'bold').replace('secondary', 'subtle').replace('hyperlink', 'link').replace('anchor', 'link').replace('active', 'pressed').replace('hover', 'hovered').replace('dragged', 'overlay').replace('dragging', 'overlay').replace('drag', 'overlay').replace('background-color', 'background').replace('color', 'text').replace('icons', 'icon').replace('arrow', 'icon').replace('glyph', 'icon').replace('stroke', 'border').replace('border-left', 'border').replace('border-right', 'border').replace('border-top', 'border').replace('border-bottom', 'border').replace('box-shadow', 'shadow'));
|
|
52
32
|
return accum;
|
|
53
|
-
}, []).filter(
|
|
54
|
-
return getUniqueWordsFromTokens.includes(val);
|
|
55
|
-
}).reduce(function (accum, val) {
|
|
33
|
+
}, []).filter(val => getUniqueWordsFromTokens.includes(val)).reduce((accum, val) => {
|
|
56
34
|
if (!accum.includes(val)) {
|
|
57
35
|
accum.push(val);
|
|
58
36
|
}
|
|
59
|
-
|
|
60
37
|
return accum;
|
|
61
38
|
}, []);
|
|
62
39
|
return filterDuplciateFoundations(cleanMeta);
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
9
|
require("./styled-to-emotion/styled-to-emotion");
|
|
13
|
-
|
|
14
10
|
require("./theme-to-design-tokens/theme-to-design-tokens");
|
|
15
|
-
|
|
16
11
|
require("./css-to-design-tokens/css-to-design-tokens");
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* Manually import presets to make sure typescript includes them
|
|
20
14
|
* in the final bundle
|
|
21
15
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
16
|
+
|
|
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)`));
|
|
25
18
|
var _default = presets;
|
|
26
19
|
exports.default = _default;
|
|
@@ -5,51 +5,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = transformer;
|
|
7
7
|
exports.parser = void 0;
|
|
8
|
-
|
|
9
8
|
function buildCoreImportDeclaration(j, path) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
j(path).find(j.ImportSpecifier).filter(
|
|
13
|
-
return coreExports.includes(specifier.value.imported.name);
|
|
14
|
-
}).forEach(function (specifier) {
|
|
9
|
+
const coreExports = ['css', 'keyframes'];
|
|
10
|
+
const specifiers = [];
|
|
11
|
+
j(path).find(j.ImportSpecifier).filter(specifier => coreExports.includes(specifier.value.imported.name)).forEach(specifier => {
|
|
15
12
|
specifiers.push(j.importSpecifier(j.identifier(specifier.value.imported.name)));
|
|
16
13
|
});
|
|
17
14
|
return specifiers.length ? j.importDeclaration(specifiers, j.literal('@emotion/core')) : null;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
function buildStyledImportDeclaration(j, path) {
|
|
21
|
-
|
|
22
|
-
return specifier.value.local.name === 'styled';
|
|
23
|
-
});
|
|
17
|
+
const specifier = j(path).find(j.ImportDefaultSpecifier).filter(specifier => specifier.value.local.name === 'styled');
|
|
24
18
|
return specifier && specifier.length ? j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.get(0).node.local.name))], j.literal('@emotion/styled')) : null;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
function buildThemingImportDeclaration(j, path) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
j(path).find(j.ImportSpecifier).filter(
|
|
31
|
-
return themingExports.includes(specifier.value.imported.name);
|
|
32
|
-
}).forEach(function (specifier) {
|
|
21
|
+
const themingExports = ['ThemeProvider', 'withTheme'];
|
|
22
|
+
const specifiers = [];
|
|
23
|
+
j(path).find(j.ImportSpecifier).filter(specifier => themingExports.includes(specifier.value.imported.name)).forEach(specifier => {
|
|
33
24
|
specifiers.push(j.importSpecifier(j.identifier(specifier.value.imported.name)));
|
|
34
25
|
});
|
|
35
26
|
return specifiers && specifiers.length ? j.importDeclaration(specifiers, j.literal('emotion-theming')) : null;
|
|
36
27
|
}
|
|
28
|
+
|
|
37
29
|
/**
|
|
38
30
|
* Converts all imports of `styled-components` to `@emotion/styled`
|
|
39
31
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var source = j(fileInfo.source).find(j.ImportDeclaration).filter(function (path) {
|
|
45
|
-
return path.node.source.value === 'styled-components';
|
|
46
|
-
}).forEach(function (path) {
|
|
32
|
+
function transformer(fileInfo, {
|
|
33
|
+
jscodeshift: j
|
|
34
|
+
}, options) {
|
|
35
|
+
const source = j(fileInfo.source).find(j.ImportDeclaration).filter(path => path.node.source.value === 'styled-components').forEach(path => {
|
|
47
36
|
j(path).replaceWith([buildCoreImportDeclaration(j, path), buildStyledImportDeclaration(j, path), buildThemingImportDeclaration(j, path)]);
|
|
48
37
|
}).toSource(options.printOptions || {
|
|
49
38
|
quote: 'single'
|
|
50
39
|
});
|
|
51
40
|
return source;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
|
-
var parser = 'tsx';
|
|
42
|
+
const parser = 'tsx';
|
|
55
43
|
exports.parser = parser;
|