@atlaskit/codemod-cli 0.9.7 → 0.10.2

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.
@@ -0,0 +1,217 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import postcss from 'postcss'; // @ts-ignore
6
+
7
+ import lessSyntax from 'postcss-less';
8
+ import designTokens from '@atlaskit/tokens/token-names';
9
+ import renameMapping from '@atlaskit/tokens/rename-mapping';
10
+ import Search from '../theme-to-design-tokens/utils/fuzzy-search';
11
+ import { knownVariables, knownColors, knownRawColors } from './utils/legacy-colors';
12
+ import { cleanMeta } from './utils/meta';
13
+ var tokens = Object.keys(designTokens).filter(function (t) {
14
+ return !t.includes('UNSAFE') && !t.includes('interaction');
15
+ }).filter(function (t) {
16
+ return !renameMapping.find(function (_ref) {
17
+ var path = _ref.path;
18
+ return t === path.replace(/\.[default]\g/, '');
19
+ });
20
+ });
21
+ var search = Search(tokens, false);
22
+
23
+ function isRule(node) {
24
+ return node.type === 'rule';
25
+ }
26
+
27
+ function getParentSelectors(node) {
28
+ if (isRule(node)) {
29
+ // @ts-expect-error
30
+ return getParentSelectors(node.parent) + ' ' + node.selector;
31
+ }
32
+
33
+ if (node.parent) {
34
+ return getParentSelectors(node.parent);
35
+ }
36
+
37
+ return '';
38
+ }
39
+
40
+ function stripVar(prop) {
41
+ return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
42
+ }
43
+
44
+ function stripLessVar(prop) {
45
+ return prop.substring(1);
46
+ }
47
+
48
+ function isColorProperty(prop) {
49
+ 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';
50
+ }
51
+
52
+ function getDeclarationMeta(decl) {
53
+ if (decl.prop === 'color') {
54
+ return 'text';
55
+ }
56
+
57
+ if (decl.prop.startsWith('background')) {
58
+ return 'background';
59
+ }
60
+
61
+ if (decl.prop.includes('shadow')) {
62
+ return 'shadow';
63
+ }
64
+
65
+ if (decl.prop.includes('border')) {
66
+ return 'border';
67
+ }
68
+
69
+ return '';
70
+ }
71
+
72
+ function isDesignToken(tokenName) {
73
+ return Boolean(Object.entries(designTokens).find(function (_ref2) {
74
+ var _ref3 = _slicedToArray(_ref2, 2),
75
+ _ = _ref3[0],
76
+ value = _ref3[1];
77
+
78
+ return tokenName === value;
79
+ }));
80
+ }
81
+
82
+ function getMetaFromCssVar(tokenName) {
83
+ var meta = knownVariables[tokenName];
84
+
85
+ if (!meta || meta.length === 0) {
86
+ return tokenName.split('-');
87
+ }
88
+
89
+ return meta;
90
+ }
91
+
92
+ function getMetaFromRawColor(rawColor) {
93
+ var cleanColor = rawColor.toLowerCase();
94
+
95
+ if (cleanColor.length === 4) {
96
+ cleanColor = cleanColor + cleanColor.substring(cleanColor.indexOf('#') + 1);
97
+ }
98
+
99
+ return knownRawColors[cleanColor];
100
+ } // https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
101
+ // https://astexplorer.net/#/2uBU1BLuJ1
102
+
103
+
104
+ var plugin = function plugin() {
105
+ var processed = Symbol('processed');
106
+ return {
107
+ postcssPlugin: 'UsingTokens',
108
+ Declaration: function Declaration(decl) {
109
+ // @ts-expect-error
110
+ if (decl[processed]) {
111
+ return;
112
+ }
113
+
114
+ if (!isColorProperty(decl.prop)) {
115
+ return;
116
+ }
117
+
118
+ var searchTerms = [getDeclarationMeta(decl)].concat(_toConsumableArray(getParentSelectors(decl).split(/\-|\.|\,|\ |\:|\&/).filter(function (el) {
119
+ return !!el;
120
+ })));
121
+ var match;
122
+ var cssVarRe = /var\([^\)]+\)/g;
123
+ var lessVarRe = /@[a-zA-Z0-9-]+/g;
124
+ 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; // CSS variables
125
+
126
+ var cssVarMatch = decl.value.match(cssVarRe);
127
+
128
+ if (cssVarMatch) {
129
+ var _getMetaFromCssVar;
130
+
131
+ match = cssVarMatch[0];
132
+
133
+ if (isDesignToken(stripVar(match))) {
134
+ return;
135
+ }
136
+
137
+ searchTerms.push.apply(searchTerms, _toConsumableArray((_getMetaFromCssVar = getMetaFromCssVar(stripVar(match))) !== null && _getMetaFromCssVar !== void 0 ? _getMetaFromCssVar : []));
138
+ } // Less variables
139
+
140
+
141
+ var lassVarMatch = decl.value.match(lessVarRe);
142
+
143
+ if (lassVarMatch) {
144
+ var _getMetaFromCssVar2;
145
+
146
+ match = lassVarMatch[0];
147
+ searchTerms.push.apply(searchTerms, _toConsumableArray((_getMetaFromCssVar2 = getMetaFromCssVar("--".concat(stripLessVar(match)))) !== null && _getMetaFromCssVar2 !== void 0 ? _getMetaFromCssVar2 : []));
148
+ } // Raw colors
149
+
150
+
151
+ var rawColorMatch = decl.value.match(rawColorRe);
152
+
153
+ if (rawColorMatch) {
154
+ var _getMetaFromRawColor;
155
+
156
+ match = rawColorMatch[0];
157
+ searchTerms.push.apply(searchTerms, _toConsumableArray((_getMetaFromRawColor = getMetaFromRawColor(match)) !== null && _getMetaFromRawColor !== void 0 ? _getMetaFromRawColor : []));
158
+ } // Named colors
159
+
160
+
161
+ if (knownColors.hasOwnProperty(decl.value)) {
162
+ var _knownColors$decl$val;
163
+
164
+ match = decl.value;
165
+ searchTerms.push.apply(searchTerms, _toConsumableArray((_knownColors$decl$val = knownColors[decl.value.toLowerCase()]) !== null && _knownColors$decl$val !== void 0 ? _knownColors$decl$val : []));
166
+ }
167
+
168
+ if (!match) {
169
+ console.warn("Unable to find match for declaration: ".concat(decl.prop, ": ").concat(decl.value));
170
+ return;
171
+ }
172
+
173
+ var cleanSearchTerms = cleanMeta(searchTerms).join(' ');
174
+ var results = search.get(cleanSearchTerms);
175
+ var replacement = results ? results.map(function (result) {
176
+ return result[1];
177
+ }) : ['utility.UNSAFE_util.MISSING_TOKEN'];
178
+
179
+ if (decl.prop === 'box-shadow') {
180
+ decl.value = "var(".concat(designTokens[replacement[0]], ", ").concat(decl.value, ")");
181
+ } else {
182
+ decl.value = decl.value.split(match).join("var(".concat(designTokens[replacement[0]], ", ").concat(match, ")"));
183
+ } // @ts-expect-error
184
+
185
+
186
+ decl[processed] = true;
187
+ }
188
+ };
189
+ };
190
+
191
+ export default function transformer(_x) {
192
+ return _transformer.apply(this, arguments);
193
+ }
194
+
195
+ function _transformer() {
196
+ _transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file) {
197
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
198
+ while (1) {
199
+ switch (_context.prev = _context.next) {
200
+ case 0:
201
+ _context.next = 2;
202
+ return postcss([plugin()]).process(file.source, {
203
+ syntax: lessSyntax
204
+ }).css;
205
+
206
+ case 2:
207
+ return _context.abrupt("return", _context.sent);
208
+
209
+ case 3:
210
+ case "end":
211
+ return _context.stop();
212
+ }
213
+ }
214
+ }, _callee);
215
+ }));
216
+ return _transformer.apply(this, arguments);
217
+ }
@@ -0,0 +1,334 @@
1
+ export var knownVariables = {
2
+ '--adg3-color-R50': ['danger'],
3
+ '--adg3-color-R75': ['danger'],
4
+ '--adg3-color-R100': ['danger'],
5
+ '--adg3-color-R200': ['danger'],
6
+ '--adg3-color-R300': ['danger'],
7
+ '--adg3-color-R400': ['danger'],
8
+ '--adg3-color-R500': ['danger'],
9
+ '--adg3-color-Y50': ['warning'],
10
+ '--adg3-color-Y75': ['warning'],
11
+ '--adg3-color-Y100': ['warning'],
12
+ '--adg3-color-Y200': ['warning'],
13
+ '--adg3-color-Y300': ['warning'],
14
+ '--adg3-color-Y400': ['warning'],
15
+ '--adg3-color-Y500': ['warning'],
16
+ '--adg3-color-G50': ['success'],
17
+ '--adg3-color-G75': ['success'],
18
+ '--adg3-color-G100': ['success'],
19
+ '--adg3-color-G200': ['success'],
20
+ '--adg3-color-G300': ['success'],
21
+ '--adg3-color-G400': ['success'],
22
+ '--adg3-color-G500': ['success'],
23
+ '--adg3-color-B50': ['brand'],
24
+ '--adg3-color-B75': ['brand'],
25
+ '--adg3-color-B100': ['brand'],
26
+ '--adg3-color-B200': ['brand'],
27
+ '--adg3-color-B300': ['brand'],
28
+ '--adg3-color-B400': ['brand'],
29
+ '--adg3-color-B500': ['brand'],
30
+ '--adg3-color-P50': ['discovery'],
31
+ '--adg3-color-P75': ['discovery'],
32
+ '--adg3-color-P100': ['discovery'],
33
+ '--adg3-color-P200': ['discovery'],
34
+ '--adg3-color-P300': ['discovery'],
35
+ '--adg3-color-P400': ['discovery'],
36
+ '--adg3-color-P500': ['discovery'],
37
+ '--adg3-color-T50': ['accent', 'teal'],
38
+ '--adg3-color-T75': ['accent', 'teal'],
39
+ '--adg3-color-T100': ['accent', 'teal'],
40
+ '--adg3-color-T200': ['accent', 'teal'],
41
+ '--adg3-color-T300': ['accent', 'teal'],
42
+ '--adg3-color-T400': ['accent', 'teal'],
43
+ '--adg3-color-T500': ['accent', 'teal'],
44
+ '--adg3-color-N0': ['inverse'],
45
+ '--adg3-color-N10': [],
46
+ '--adg3-color-N20': [],
47
+ '--adg3-color-N30': [],
48
+ '--adg3-color-N40': [],
49
+ '--adg3-color-N50': [],
50
+ '--adg3-color-N60': [],
51
+ '--adg3-color-N70': [],
52
+ '--adg3-color-N80': [],
53
+ '--adg3-color-N90': [],
54
+ '--adg3-color-N100': [],
55
+ '--adg3-color-N200': ['text', 'subtlest'],
56
+ '--adg3-color-N300': [],
57
+ '--adg3-color-N400': ['text', 'subtle'],
58
+ '--adg3-color-N500': [],
59
+ '--adg3-color-N600': [],
60
+ '--adg3-color-N700': ['text'],
61
+ '--adg3-color-N800': ['text'],
62
+ '--adg3-color-N900': ['text'],
63
+ '--adg3-color-N10A': [],
64
+ '--adg3-color-N20A': [],
65
+ '--adg3-color-N30A': [],
66
+ '--adg3-color-N40A': [],
67
+ '--adg3-color-N50A': [],
68
+ '--adg3-color-N60A': [],
69
+ '--adg3-color-N70A': [],
70
+ '--adg3-color-N80A': [],
71
+ '--adg3-color-N90A': [],
72
+ '--adg3-color-N100A': [],
73
+ '--adg3-color-N200A': [],
74
+ '--adg3-color-N300A': [],
75
+ '--adg3-color-N400A': [],
76
+ '--adg3-color-N500A': [],
77
+ '--adg3-color-N600A': [],
78
+ '--adg3-color-N700A': [],
79
+ '--adg3-color-N800A': [],
80
+ '--adg3-color-DN900': [],
81
+ '--adg3-color-DN800': [],
82
+ '--adg3-color-DN700': [],
83
+ '--adg3-color-DN600': [],
84
+ '--adg3-color-DN500': [],
85
+ '--adg3-color-DN400': [],
86
+ '--adg3-color-DN300': [],
87
+ '--adg3-color-DN200': [],
88
+ '--adg3-color-DN100': [],
89
+ '--adg3-color-DN90': [],
90
+ '--adg3-color-DN80': [],
91
+ '--adg3-color-DN70': [],
92
+ '--adg3-color-DN60': [],
93
+ '--adg3-color-DN50': [],
94
+ '--adg3-color-DN40': [],
95
+ '--adg3-color-DN30': [],
96
+ '--adg3-color-DN20': [],
97
+ '--adg3-color-DN10': [],
98
+ '--adg3-color-DN0': [],
99
+ '--adg3-color-DN800A': [],
100
+ '--adg3-color-DN700A': [],
101
+ '--adg3-color-DN600A': [],
102
+ '--adg3-color-DN500A': [],
103
+ '--adg3-color-DN400A': [],
104
+ '--adg3-color-DN300A': [],
105
+ '--adg3-color-DN200A': [],
106
+ '--adg3-color-DN100A': [],
107
+ '--adg3-color-DN90A': [],
108
+ '--adg3-color-DN80A': [],
109
+ '--adg3-color-DN70A': [],
110
+ '--adg3-color-DN60A': [],
111
+ '--adg3-color-DN50A': [],
112
+ '--adg3-color-DN40A': [],
113
+ '--adg3-color-DN30A': [],
114
+ '--adg3-color-DN20A': [],
115
+ '--adg3-color-DN10A': [],
116
+ '--adg3-color-background-light': ['elevation', 'surface'],
117
+ '--adg3-color-background-dark': ['elevation', 'surface'],
118
+ '--adg3-color-text-light': ['text'],
119
+ '--adg3-color-text-dark': ['text'],
120
+ '--adg3-color-subtleText-light': ['text', 'subtle'],
121
+ '--adg3-color-subtleText-dark': ['text', 'subtle'],
122
+ '--adg3-color-placeholderText-light': ['text', 'subtlest'],
123
+ '--adg3-color-placeholderText-dark': ['text', 'subtlest'],
124
+ '--adg3-color-heading-light': ['text'],
125
+ '--adg3-color-heading-dark': ['text'],
126
+ '--adg3-color-subtleHeading-light': ['text', 'subtle'],
127
+ '--adg3-color-subtleHeading-dark': ['text', 'subtle'],
128
+ '--adg3-color-codeBlock-light': ['elevation', 'surface', 'sunken'],
129
+ '--adg3-color-codeBlock-dark': ['elevation', 'surface', 'sunken'],
130
+ '--adg3-color-link-light': ['link'],
131
+ '--adg3-color-link-dark': ['link'],
132
+ '--adg3-color-linkHover-light': ['link'],
133
+ '--adg3-color-linkHover-dark': ['link'],
134
+ '--adg3-color-linkActive-light': ['link', 'pressed'],
135
+ '--adg3-color-linkActive-dark': ['link', 'pressed'],
136
+ '--adg3-color-linkOutline-light': ['link', 'focused'],
137
+ '--adg3-color-linkOutline-dark': ['link', 'focused'],
138
+ '--adg3-color-primary-light': ['brand'],
139
+ '--adg3-color-primary-dark': ['brand'],
140
+ '--adg3-color-blue-light': ['accent', 'subtler', 'blue'],
141
+ '--adg3-color-blue-dark': ['accent', 'bolder', 'blue'],
142
+ '--adg3-color-teal-light': ['accent', 'subtler', 'teal'],
143
+ '--adg3-color-teal-dark': ['accent', 'bolder', 'teal'],
144
+ '--adg3-color-purple-light': ['accent', 'subtler', 'purple'],
145
+ '--adg3-color-purple-dark': ['accent', 'bolder', 'purple'],
146
+ '--adg3-color-red-light': ['accent', 'subtler', 'red'],
147
+ '--adg3-color-red-dark': ['accent', 'bolder', 'red'],
148
+ '--adg3-color-yellow-light': ['accent', 'subtler', 'yellow'],
149
+ '--adg3-color-yellow-dark': ['accent', 'bolder', 'yellow'],
150
+ '--adg3-color-green-light': ['accent', 'subtler', 'green'],
151
+ '--adg3-color-green-dark': ['accent', 'bolder', 'green'],
152
+ '--adg3-color-N20-transparent': [],
153
+
154
+ /* Alias variables */
155
+ '--jpo-theme-color': ['brand'],
156
+ '--jpo-text-default-color': ['text'],
157
+ '--jpo-text-secondary-color': ['text', 'subtle'],
158
+ '--jpo-text-muted-color': ['text', 'disabled'],
159
+ '--jpo-text-error-color': ['text', 'danger'],
160
+ '--jpo-bg-default-color': ['elevation', 'surface'],
161
+ '--jpo-bg-reverse-color': ['background', 'inverse'],
162
+ '--jpo-bg-warning-color': ['background', 'warning', 'subtle'],
163
+ '--jpo-bg-dark-color': ['background', 'netural', 'bold'],
164
+ '--jpo-border-default-color': ['border'],
165
+ '--jpo-border-secondary-color': ['border', 'subtle']
166
+ };
167
+ export var knownColors = {
168
+ aliceblue: ['blue'],
169
+ antiquewhite: [],
170
+ aqua: ['teal'],
171
+ aquamarine: ['teal'],
172
+ azure: ['teal', 'subtlest'],
173
+ beige: [],
174
+ bisque: [],
175
+ black: [],
176
+ blanchedalmond: [],
177
+ blue: ['blue'],
178
+ blueviolet: ['blue'],
179
+ brown: [],
180
+ burlywood: [],
181
+ cadetblue: ['blue'],
182
+ chartreuse: [],
183
+ chocolate: [],
184
+ coral: [],
185
+ cornflowerblue: ['blue'],
186
+ cornsilk: [],
187
+ crimson: ['accent', 'red'],
188
+ cyan: ['accent', 'teal', 'subtle'],
189
+ darkblue: ['accent', 'blue', 'bold'],
190
+ darkcyan: ['accent', 'teal', 'bold'],
191
+ darkgoldenrod: [],
192
+ darkgray: [],
193
+ darkgrey: [],
194
+ darkgreen: ['green'],
195
+ darkkhaki: [],
196
+ darkmagenta: ['magenta', 'bold'],
197
+ darkolivegreen: ['green'],
198
+ darkorange: [],
199
+ darkorchid: [],
200
+ darkred: ['accent', 'red', 'bold'],
201
+ darksalmon: [],
202
+ darkseagreen: ['green'],
203
+ darkslateblue: [],
204
+ darkslategray: [],
205
+ darkslategrey: [],
206
+ darkturquoise: ['teal', 'bold'],
207
+ darkviolet: ['purple', 'bold'],
208
+ deeppink: ['magenta'],
209
+ deepskyblue: ['blue'],
210
+ dimgray: [],
211
+ dimgrey: [],
212
+ dodgerblue: [],
213
+ firebrick: ['red', 'bold'],
214
+ floralwhite: [],
215
+ forestgreen: ['green'],
216
+ fuchsia: ['magenta', 'subtle'],
217
+ gainsboro: [],
218
+ ghostwhite: [],
219
+ gold: ['yellow'],
220
+ goldenrod: [],
221
+ gray: [],
222
+ grey: [],
223
+ green: ['green'],
224
+ greenyellow: [],
225
+ honeydew: [],
226
+ hotpink: ['magenta'],
227
+ indianred: [],
228
+ indigo: ['purple'],
229
+ ivory: [],
230
+ khaki: [],
231
+ lavender: ['purple'],
232
+ lavenderblush: ['purple'],
233
+ lawngreen: ['green'],
234
+ lemonchiffon: [],
235
+ lightblue: [],
236
+ lightcoral: [],
237
+ lightcyan: [],
238
+ lightgoldenrodyellow: [],
239
+ lightgray: [],
240
+ lightgrey: [],
241
+ lightgreen: ['green'],
242
+ lightpink: ['magenta'],
243
+ lightsalmon: ['pink', 'subtler'],
244
+ lightseagreen: ['green'],
245
+ lightskyblue: ['blue'],
246
+ lightslategray: [],
247
+ lightslategrey: [],
248
+ lightsteelblue: ['blue'],
249
+ lightyellow: [],
250
+ lime: ['green', 'subtler'],
251
+ limegreen: ['green'],
252
+ linen: [],
253
+ magenta: ['magenta'],
254
+ maroon: [],
255
+ mediumaquamarine: [],
256
+ mediumblue: [],
257
+ mediumorchid: [],
258
+ mediumpurple: [],
259
+ mediumseagreen: ['green'],
260
+ mediumslateblue: [],
261
+ mediumspringgreen: ['green'],
262
+ mediumturquoise: [],
263
+ mediumvioletred: [],
264
+ midnightblue: [],
265
+ mintcream: [],
266
+ mistyrose: [],
267
+ moccasin: [],
268
+ navajowhite: [],
269
+ navy: ['blue', 'bold'],
270
+ oldlace: [],
271
+ olive: [],
272
+ olivedrab: [],
273
+ orange: [],
274
+ orangered: [],
275
+ orchid: ['purple'],
276
+ palegoldenrod: [],
277
+ palegreen: ['green'],
278
+ paleturquoise: [],
279
+ palevioletred: [],
280
+ papayawhip: [],
281
+ peachpuff: [],
282
+ peru: [],
283
+ pink: ['magenta'],
284
+ plum: [],
285
+ powderblue: ['blue', 'subtle'],
286
+ purple: ['purple'],
287
+ red: ['accent', 'red', 'subtle'],
288
+ rosybrown: [],
289
+ royalblue: [],
290
+ saddlebrown: [],
291
+ salmon: [],
292
+ sandybrown: [],
293
+ seagreen: ['green'],
294
+ seashell: [],
295
+ sienna: [],
296
+ silver: [],
297
+ skyblue: ['blue', 'subtlest'],
298
+ slateblue: [],
299
+ slategray: [],
300
+ slategrey: [],
301
+ snow: [],
302
+ springgreen: ['green'],
303
+ steelblue: ['blue'],
304
+ tan: [],
305
+ teal: ['accent', 'teal'],
306
+ thistle: [],
307
+ tomato: ['red'],
308
+ turquoise: [],
309
+ violet: ['purple'],
310
+ wheat: [],
311
+ white: ['elevation', 'surface'],
312
+ whitesmoke: [],
313
+ yellow: ['yellow'],
314
+ yellowgreen: ['yellow']
315
+ };
316
+ export var knownRawColors = {
317
+ '#000000': ['text'],
318
+ '#cccccc': ['border'],
319
+ '#aaaaaa': ['border'],
320
+ '#bbbbbb': ['border'],
321
+ '#ffffff': ['elevation', 'surface'],
322
+ '#f0f0f0': ['elevation', 'surface'],
323
+ '#eeeeee': ['elevation', 'surface', 'sunken'],
324
+ '#ff0000': ['danger'],
325
+ '#d04437': ['danger'],
326
+ '#c00c00': ['danger'],
327
+ '#5243aa': ['discovery'],
328
+ '#ffc712': ['warning'],
329
+ '#292929': ['text'],
330
+ '#00f00f': ['brand'],
331
+ '#3b73af': ['brand'],
332
+ '#326ca6': ['brand'],
333
+ '#0052cc': ['brand']
334
+ };
@@ -0,0 +1,52 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import designTokens from '@atlaskit/tokens/token-names';
3
+ var getUniqueWordsFromTokens = Object.keys(designTokens).reduce(function (accum, val) {
4
+ return [].concat(_toConsumableArray(accum), _toConsumableArray(val.split('.')));
5
+ }, []).reduce(function (accum, val) {
6
+ return [].concat(_toConsumableArray(accum), _toConsumableArray(val.split(/(?=[A-Z])/g).map(function (e) {
7
+ return e.toLowerCase();
8
+ })));
9
+ }, []).reduce(function (accum, val) {
10
+ if (!accum.includes(val)) {
11
+ accum.push(val);
12
+ }
13
+
14
+ return accum;
15
+ }, []);
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
+
26
+ if (hasFoundation && foundations.includes(val)) {
27
+ return false;
28
+ }
29
+
30
+ return true;
31
+ });
32
+ }
33
+
34
+ export function cleanMeta(meta) {
35
+ var cleanMeta = meta.reduce(function (accum, val) {
36
+ return [].concat(_toConsumableArray(accum), _toConsumableArray(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
37
+ return e.toLowerCase();
38
+ }) : []));
39
+ }, []).reduce(function (accum, val) {
40
+ 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'));
41
+ return accum;
42
+ }, []).filter(function (val) {
43
+ return getUniqueWordsFromTokens.includes(val);
44
+ }).reduce(function (accum, val) {
45
+ if (!accum.includes(val)) {
46
+ accum.push(val);
47
+ }
48
+
49
+ return accum;
50
+ }, []);
51
+ return filterDuplciateFoundations(cleanMeta);
52
+ }
@@ -6,7 +6,8 @@ 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
- var presets = ['styled-to-emotion', 'theme-to-design-tokens'].map(function (preset) {
9
+ 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) {
10
11
  return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
11
12
  });
12
13
  export default presets;
@@ -1,5 +1,5 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import simpleGit from 'simple-git';
4
4
  import { ValidationError } from './types';
5
5
  var packageRegex = /"(@(?:atlaskit|atlassian|atlassiansox)\/.*)": "(.*)"/;
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.9.7"
3
+ "version": "0.10.2"
4
4
  }
@@ -0,0 +1,2 @@
1
+ import { FileInfo } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo): Promise<string>;
@@ -0,0 +1,3 @@
1
+ export declare const knownVariables: Record<string, string[]>;
2
+ export declare const knownColors: Record<string, string[]>;
3
+ export declare const knownRawColors: Record<string, string[]>;
@@ -0,0 +1 @@
1
+ export declare function cleanMeta(meta: string[]): string[];
@@ -4,5 +4,6 @@
4
4
  */
5
5
  import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-to-design-tokens/theme-to-design-tokens';
7
+ import './css-to-design-tokens/css-to-design-tokens';
7
8
  declare const presets: string[];
8
9
  export default presets;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.9.7",
3
+ "version": "0.10.2",
4
4
  "description": "A cli for distributing codemods for atlassian-frontend components and services",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -26,13 +26,14 @@
26
26
  "dependencies": {
27
27
  "@atlaskit/tokens": "^0.10.0",
28
28
  "@babel/runtime": "^7.0.0",
29
- "@types/chalk": "^2.2.0",
30
29
  "@types/jscodeshift": "^0.11.0",
31
- "chalk": "^2.1.0",
30
+ "chalk": "^4.1.2",
32
31
  "enquirer": "^2.3.4",
33
32
  "glob": "^7.1.2",
34
33
  "jscodeshift": "^0.13.0",
35
34
  "meow": "^8.1.1",
35
+ "postcss": "^8.4.7",
36
+ "postcss-less": "^6.0.0",
36
37
  "projector-spawn": "^1.0.1",
37
38
  "semver": "^7.3.0",
38
39
  "simple-git": "^3.5.0"
@@ -41,7 +42,8 @@
41
42
  "@atlaskit/docs": "*",
42
43
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
43
44
  "ts-node": "^10.0.0",
44
- "typescript": "4.2.4"
45
+ "typescript": "4.3.5"
45
46
  },
47
+ "homepage": "https://atlaskit.atlassian.com/packages/monorepo-tooling/codemod-cli",
46
48
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
47
49
  }