@atlaskit/codemod-cli 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +12 -2
  3. package/dist/cjs/main.js +3 -3
  4. package/dist/cjs/presets/index.js +4 -2
  5. package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +181 -0
  6. package/dist/cjs/presets/theme-to-design-tokens/types.js +5 -0
  7. package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +104 -0
  8. package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +19 -0
  9. package/dist/cjs/presets/theme-to-design-tokens/utils/color-difference.js +174 -0
  10. package/dist/cjs/presets/theme-to-design-tokens/utils/color-palette-tokens-map.js +129 -0
  11. package/dist/cjs/presets/theme-to-design-tokens/utils/color-to-token.js +88 -0
  12. package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +59 -0
  13. package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +348 -0
  14. package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +81 -0
  15. package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +8 -0
  16. package/dist/cjs/types.js +4 -2
  17. package/dist/cjs/version.json +1 -1
  18. package/dist/es2019/presets/index.js +2 -1
  19. package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +137 -0
  20. package/dist/es2019/presets/theme-to-design-tokens/types.js +1 -0
  21. package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +70 -0
  22. package/dist/es2019/presets/theme-to-design-tokens/utils/ast.js +10 -0
  23. package/dist/es2019/presets/theme-to-design-tokens/utils/color-difference.js +150 -0
  24. package/dist/es2019/presets/theme-to-design-tokens/utils/color-palette-tokens-map.js +122 -0
  25. package/dist/es2019/presets/theme-to-design-tokens/utils/color-to-token.js +75 -0
  26. package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +35 -0
  27. package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +336 -0
  28. package/dist/es2019/presets/theme-to-design-tokens/utils/legacy-colors.js +72 -0
  29. package/dist/es2019/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
  30. package/dist/es2019/version.json +1 -1
  31. package/dist/esm/main.js +3 -3
  32. package/dist/esm/presets/index.js +3 -2
  33. package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +165 -0
  34. package/dist/esm/presets/theme-to-design-tokens/types.js +1 -0
  35. package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +88 -0
  36. package/dist/esm/presets/theme-to-design-tokens/utils/ast.js +10 -0
  37. package/dist/esm/presets/theme-to-design-tokens/utils/color-difference.js +160 -0
  38. package/dist/esm/presets/theme-to-design-tokens/utils/color-palette-tokens-map.js +122 -0
  39. package/dist/esm/presets/theme-to-design-tokens/utils/color-to-token.js +78 -0
  40. package/dist/esm/presets/theme-to-design-tokens/utils/color.js +39 -0
  41. package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +340 -0
  42. package/dist/esm/presets/theme-to-design-tokens/utils/legacy-colors.js +72 -0
  43. package/dist/esm/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
  44. package/dist/esm/types.js +3 -2
  45. package/dist/esm/version.json +1 -1
  46. package/dist/types/presets/index.d.ts +1 -0
  47. package/dist/types/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +2 -0
  48. package/dist/types/presets/theme-to-design-tokens/types.d.ts +2 -0
  49. package/dist/types/presets/theme-to-design-tokens/utils/ast-meta.d.ts +4 -0
  50. package/dist/types/presets/theme-to-design-tokens/utils/ast.d.ts +3 -0
  51. package/dist/types/presets/theme-to-design-tokens/utils/color-difference.d.ts +66 -0
  52. package/dist/types/presets/theme-to-design-tokens/utils/color-palette-tokens-map.d.ts +21 -0
  53. package/dist/types/presets/theme-to-design-tokens/utils/color-to-token.d.ts +12 -0
  54. package/dist/types/presets/theme-to-design-tokens/utils/color.d.ts +4 -0
  55. package/dist/types/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +5 -0
  56. package/dist/types/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +3 -0
  57. package/dist/types/presets/theme-to-design-tokens/utils/named-colors.d.ts +1 -0
  58. package/package.json +3 -1
@@ -0,0 +1,336 @@
1
+ /* eslint-disable */
2
+
3
+ /**
4
+ * Fuzzy search ripped from the internet.
5
+ */
6
+ const FuzzySet = function (arr = [], useLevenshtein, gramSizeLower = 2, gramSizeUpper = 3) {
7
+ var fuzzyset = {
8
+ gramSizeLower: gramSizeLower,
9
+ gramSizeUpper: gramSizeUpper,
10
+ useLevenshtein: typeof useLevenshtein !== 'boolean' ? true : useLevenshtein,
11
+ exactSet: {},
12
+ matchDict: {},
13
+ items: {}
14
+ };
15
+
16
+ var levenshtein = function (str1, str2) {
17
+ var current = [];
18
+ var prev;
19
+ var value;
20
+
21
+ for (var i = 0; i <= str2.length; i++) {
22
+ for (var j = 0; j <= str1.length; j++) {
23
+ if (i && j) {
24
+ if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
25
+ // @ts-expect-error
26
+ value = prev;
27
+ } else {
28
+ // @ts-expect-error
29
+ value = Math.min(current[j], current[j - 1], prev) + 1;
30
+ }
31
+ } else {
32
+ value = i + j;
33
+ }
34
+
35
+ prev = current[j];
36
+ current[j] = value;
37
+ }
38
+ }
39
+
40
+ return current.pop();
41
+ }; // return an edit distance from 0 to 1
42
+
43
+
44
+ var _distance = function (str1, str2) {
45
+ if (str1 === null && str2 === null) {
46
+ throw new Error('Trying to compare two null values');
47
+ }
48
+
49
+ if (str1 === null || str2 === null) {
50
+ return 0;
51
+ }
52
+
53
+ str1 = String(str1);
54
+ str2 = String(str2);
55
+ var distance = levenshtein(str1, str2);
56
+
57
+ if (str1.length > str2.length) {
58
+ return 1 - distance / str1.length;
59
+ } else {
60
+ return 1 - distance / str2.length;
61
+ }
62
+ };
63
+
64
+ var _nonWordRe = /[^a-zA-Z0-9\u00C0-\u00FF, ]+/g;
65
+
66
+ var _iterateGrams = function (value, gramSize) {
67
+ gramSize = gramSize || 2;
68
+ var simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-',
69
+ lenDiff = gramSize - simplified.length,
70
+ results = [];
71
+
72
+ if (lenDiff > 0) {
73
+ for (var i = 0; i < lenDiff; ++i) {
74
+ simplified += '-';
75
+ }
76
+ }
77
+
78
+ for (var i = 0; i < simplified.length - gramSize + 1; ++i) {
79
+ results.push(simplified.slice(i, i + gramSize));
80
+ }
81
+
82
+ return results;
83
+ };
84
+
85
+ var _gramCounter = function (value, gramSize) {
86
+ // return an object where key=gram, value=number of occurrences
87
+ gramSize = gramSize || 2;
88
+
89
+ var result = {},
90
+ grams = _iterateGrams(value, gramSize),
91
+ i = 0;
92
+
93
+ for (i; i < grams.length; ++i) {
94
+ if (grams[i] in result) {
95
+ // @ts-expect-error
96
+ result[grams[i]] += 1;
97
+ } else {
98
+ // @ts-expect-error
99
+ result[grams[i]] = 1;
100
+ }
101
+ }
102
+
103
+ return result;
104
+ }; // the main functions
105
+
106
+
107
+ fuzzyset.get = function (value, defaultValue, minMatchScore) {
108
+ // check for value in set, returning defaultValue or null if none found
109
+ if (minMatchScore === undefined) {
110
+ minMatchScore = 0.33;
111
+ }
112
+
113
+ var result = this._get(value, minMatchScore);
114
+
115
+ if (!result && typeof defaultValue !== 'undefined') {
116
+ return defaultValue;
117
+ }
118
+
119
+ return result;
120
+ };
121
+
122
+ fuzzyset._get = function (value, minMatchScore) {
123
+ var results = []; // start with high gram size and if there are no results, go to lower gram sizes
124
+
125
+ for (var gramSize = this.gramSizeUpper; gramSize >= this.gramSizeLower; --gramSize) {
126
+ results = this.__get(value, gramSize, minMatchScore);
127
+
128
+ if (results && results.length > 0) {
129
+ return results;
130
+ }
131
+ }
132
+
133
+ return null;
134
+ };
135
+
136
+ fuzzyset.__get = function (value, gramSize, minMatchScore) {
137
+ var normalizedValue = this._normalizeStr(value),
138
+ matches = {},
139
+ gramCounts = _gramCounter(normalizedValue, gramSize),
140
+ items = this.items[gramSize],
141
+ sumOfSquareGramCounts = 0,
142
+ gram,
143
+ gramCount,
144
+ i,
145
+ index,
146
+ otherGramCount;
147
+
148
+ for (gram in gramCounts) {
149
+ // @ts-expect-error
150
+ gramCount = gramCounts[gram];
151
+ sumOfSquareGramCounts += Math.pow(gramCount, 2);
152
+
153
+ if (gram in this.matchDict) {
154
+ for (i = 0; i < this.matchDict[gram].length; ++i) {
155
+ index = this.matchDict[gram][i][0];
156
+ otherGramCount = this.matchDict[gram][i][1];
157
+
158
+ if (index in matches) {
159
+ // @ts-expect-error
160
+ matches[index] += gramCount * otherGramCount;
161
+ } else {
162
+ // @ts-expect-error
163
+ matches[index] = gramCount * otherGramCount;
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ function isEmptyObject(obj) {
170
+ for (var prop in obj) {
171
+ if (obj.hasOwnProperty(prop)) {
172
+ return false;
173
+ }
174
+ }
175
+
176
+ return true;
177
+ }
178
+
179
+ if (isEmptyObject(matches)) {
180
+ return null;
181
+ }
182
+
183
+ var vectorNormal = Math.sqrt(sumOfSquareGramCounts),
184
+ results = [],
185
+ matchScore; // build a results list of [score, str]
186
+
187
+ for (var matchIndex in matches) {
188
+ // @ts-expect-error
189
+ matchScore = matches[matchIndex];
190
+ results.push([matchScore / (vectorNormal * items[matchIndex][0]), items[matchIndex][1]]);
191
+ }
192
+
193
+ var sortDescending = function (a, b) {
194
+ if (a[0] < b[0]) {
195
+ return 1;
196
+ } else if (a[0] > b[0]) {
197
+ return -1;
198
+ } else {
199
+ return 0;
200
+ }
201
+ };
202
+
203
+ results.sort(sortDescending);
204
+
205
+ if (this.useLevenshtein) {
206
+ var newResults = [],
207
+ endIndex = Math.min(50, results.length); // truncate somewhat arbitrarily to 50
208
+ // @ts-expect-error
209
+
210
+ for (var i = 0; i < endIndex; ++i) {
211
+ // @ts-expect-error
212
+ newResults.push([_distance(results[i][1], normalizedValue), results[i][1]]);
213
+ }
214
+
215
+ results = newResults;
216
+ results.sort(sortDescending);
217
+ }
218
+
219
+ newResults = [];
220
+ results.forEach(function (scoreWordPair) {
221
+ if (scoreWordPair[0] >= minMatchScore) {
222
+ // @ts-expect-error
223
+ newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]);
224
+ }
225
+ }.bind(this));
226
+ return newResults;
227
+ };
228
+
229
+ fuzzyset.add = function (value) {
230
+ var normalizedValue = this._normalizeStr(value);
231
+
232
+ if (normalizedValue in this.exactSet) {
233
+ return false;
234
+ }
235
+
236
+ var i = this.gramSizeLower;
237
+
238
+ for (i; i < this.gramSizeUpper + 1; ++i) {
239
+ this._add(value, i);
240
+ }
241
+ };
242
+
243
+ fuzzyset._add = function (value, gramSize) {
244
+ var normalizedValue = this._normalizeStr(value),
245
+ items = this.items[gramSize] || [],
246
+ index = items.length;
247
+
248
+ items.push(0);
249
+
250
+ var gramCounts = _gramCounter(normalizedValue, gramSize);
251
+
252
+ var sumOfSquareGramCounts = 0;
253
+ var gram;
254
+ var gramCount;
255
+
256
+ for (gram in gramCounts) {
257
+ // @ts-expect-error
258
+ gramCount = gramCounts[gram];
259
+ sumOfSquareGramCounts += Math.pow(gramCount, 2);
260
+
261
+ if (gram in this.matchDict) {
262
+ this.matchDict[gram].push([index, gramCount]);
263
+ } else {
264
+ this.matchDict[gram] = [[index, gramCount]];
265
+ }
266
+ }
267
+
268
+ var vectorNormal = Math.sqrt(sumOfSquareGramCounts);
269
+ items[index] = [vectorNormal, normalizedValue];
270
+ this.items[gramSize] = items;
271
+ this.exactSet[normalizedValue] = value;
272
+ };
273
+
274
+ fuzzyset._normalizeStr = function (str) {
275
+ if (Object.prototype.toString.call(str) !== '[object String]') {
276
+ throw new Error('Must use a string as argument to FuzzySet functions');
277
+ }
278
+
279
+ return str.toLowerCase();
280
+ }; // return length of items in set
281
+
282
+
283
+ fuzzyset.length = function () {
284
+ var count = 0,
285
+ prop;
286
+
287
+ for (prop in this.exactSet) {
288
+ if (this.exactSet.hasOwnProperty(prop)) {
289
+ count += 1;
290
+ }
291
+ }
292
+
293
+ return count;
294
+ }; // return is set is empty
295
+
296
+
297
+ fuzzyset.isEmpty = function () {
298
+ for (var prop in this.exactSet) {
299
+ if (this.exactSet.hasOwnProperty(prop)) {
300
+ return false;
301
+ }
302
+ }
303
+
304
+ return true;
305
+ }; // return list of values loaded into set
306
+
307
+
308
+ fuzzyset.values = function () {
309
+ var values = [],
310
+ prop;
311
+
312
+ for (prop in this.exactSet) {
313
+ if (this.exactSet.hasOwnProperty(prop)) {
314
+ values.push(this.exactSet[prop]);
315
+ }
316
+ }
317
+
318
+ return values;
319
+ }; // initialization
320
+
321
+
322
+ var i = fuzzyset.gramSizeLower;
323
+
324
+ for (i; i < fuzzyset.gramSizeUpper + 1; ++i) {
325
+ fuzzyset.items[i] = [];
326
+ } // add all the items to the set
327
+
328
+
329
+ for (i = 0; i < arr.length; ++i) {
330
+ fuzzyset.add(arr[i]);
331
+ }
332
+
333
+ return fuzzyset;
334
+ };
335
+
336
+ export default FuzzySet;
@@ -0,0 +1,72 @@
1
+ export const legacyColors = ['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A'];
2
+ export const legacyColorMixins = ['background', 'backgroundActive', 'backgroundHover', 'backgroundOnLayer', 'text', 'textHover', 'textActive', 'subtleText', 'placeholderText', 'heading', 'subtleHeading', 'codeBlock', 'link', 'linkHover', 'linkActive', 'linkOutline', 'primary', 'blue', 'teal', 'purple', 'red', 'yellow', 'green', 'skeleton'];
3
+ export const legacyColorMetaMap = {
4
+ R50: ['danger'],
5
+ R75: ['danger'],
6
+ R100: ['danger'],
7
+ R200: ['danger'],
8
+ R300: ['danger'],
9
+ R400: ['danger'],
10
+ R500: ['danger'],
11
+ Y50: ['warning'],
12
+ Y75: ['warning'],
13
+ Y100: ['warning'],
14
+ Y200: ['warning'],
15
+ Y300: ['warning'],
16
+ Y400: ['warning'],
17
+ Y500: ['warning'],
18
+ G50: ['success'],
19
+ G75: ['success'],
20
+ G100: ['success'],
21
+ G200: ['success'],
22
+ G300: ['success'],
23
+ G400: ['success'],
24
+ G500: ['success'],
25
+ B50: ['brand'],
26
+ B75: ['brand'],
27
+ B100: ['brand'],
28
+ B200: ['brand'],
29
+ B300: ['brand'],
30
+ B400: ['brand'],
31
+ B500: ['brand'],
32
+ P50: ['discovery'],
33
+ P75: ['discovery'],
34
+ P100: ['discovery'],
35
+ P200: ['discovery'],
36
+ P300: ['discovery'],
37
+ P400: ['discovery'],
38
+ P500: ['discovery'],
39
+ T50: ['accent', 'teal'],
40
+ T75: ['accent', 'teal'],
41
+ T100: ['accent', 'teal'],
42
+ T200: ['accent', 'teal'],
43
+ T300: ['accent', 'teal'],
44
+ T400: ['accent', 'teal'],
45
+ T500: ['accent', 'teal'],
46
+ N0: ['onBold'],
47
+ N800: ['text'],
48
+ background: ['background', 'default'],
49
+ backgroundActive: ['background', 'selected'],
50
+ backgroundHover: ['background', 'hovered'],
51
+ backgroundOnLayer: ['background', 'blanket'],
52
+ text: ['text'],
53
+ textHover: ['text', 'subtle'],
54
+ textActive: ['text', 'link', 'pressed'],
55
+ subtleText: ['text', 'subtlest'],
56
+ placeholderText: ['text', 'subtlest'],
57
+ heading: ['text'],
58
+ subtleHeading: ['text', 'subtle'],
59
+ link: ['text', 'link'],
60
+ linkHover: ['text', 'link', 'hovered'],
61
+ linkActive: ['text', 'link', 'pressed'],
62
+ linkOutline: ['border', 'selected'],
63
+ primary: ['brand'],
64
+ blue: ['accent', 'blue'],
65
+ teal: ['accent', 'teal'],
66
+ purple: ['accent', 'purple'],
67
+ red: ['accent', 'red'],
68
+ yellow: ['accent', 'orange'],
69
+ green: ['accent', 'green'],
70
+ grey: ['background', 'neutral'],
71
+ skeleton: ['background', 'neutral']
72
+ };
@@ -0,0 +1 @@
1
+ export const namedColors = ['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple'];
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.8.3"
3
+ "version": "0.8.4"
4
4
  }
package/dist/esm/main.js CHANGED
@@ -9,9 +9,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
9
9
 
10
10
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
11
11
 
12
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
13
 
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
15
 
16
16
  import chalk from 'chalk';
17
17
  import fs from 'fs';
@@ -340,7 +340,7 @@ function _main() {
340
340
  case 4:
341
341
  _yield$parseArgs = _context5.sent;
342
342
  packages = _yield$parseArgs.packages;
343
- _process$env$_PACKAGE = "0.8.3", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
343
+ _process$env$_PACKAGE = "0.8.4", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
344
344
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
345
345
 
346
346
  if (packages && packages.length > 0) {
@@ -5,7 +5,8 @@ import path from 'path';
5
5
  */
6
6
 
7
7
  import './styled-to-emotion/styled-to-emotion';
8
- var presets = ['styled-to-emotion'].map(function (preset) {
9
- return path.join(__dirname, preset, "".concat(preset, ".@(ts|js)"));
8
+ import './theme-to-design-tokens/theme-to-design-tokens';
9
+ var presets = ['styled-to-emotion', 'theme-to-design-tokens'].map(function (preset) {
10
+ return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
10
11
  });
11
12
  export default presets;
@@ -0,0 +1,165 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+
3
+ /* eslint-disable no-console */
4
+ import colorToToken from './utils/color-to-token';
5
+ import { isDecendantOfToken, isDecendantOfType } from './utils/ast';
6
+ import { cleanMeta, getMetaFromAncestors } from './utils/ast-meta';
7
+ import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from './utils/color';
8
+ import Search from './utils/fuzzy-search';
9
+ import { legacyColorMetaMap } from './utils/legacy-colors';
10
+ import designTokens from '@atlaskit/tokens/token-names';
11
+ var tokens = Object.keys(designTokens);
12
+ var search = Search(tokens, false);
13
+
14
+ function hasImportDeclaration(j, source, sourcePath) {
15
+ return !!source.find(j.ImportDeclaration).filter(function (path) {
16
+ return path.node.source.value === sourcePath;
17
+ }).length;
18
+ }
19
+
20
+ function hasImportSpecifier(j, source, specifier, sourcePath) {
21
+ return !!source.find(j.ImportDeclaration).filter(function (path) {
22
+ return path.node.source.value === sourcePath;
23
+ }).find(j.ImportSpecifier, {
24
+ local: {
25
+ name: specifier
26
+ }
27
+ }).length;
28
+ }
29
+
30
+ function insertTokenImport(j, source) {
31
+ if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
32
+ return;
33
+ }
34
+
35
+ var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
36
+ source.get().node.program.body.unshift(newImport);
37
+ }
38
+
39
+ function buildToken(j, tokenResult, node) {
40
+ var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenResult.suggestion[0] || 'util.UNSAFE_MISSING_TOKEN'), tokenResult.fallbackNeeded && node].filter(Boolean));
41
+ callExpr.comments = [j.commentBlock(" [token-confidence: ".concat(tokenResult.confidence, "] "))];
42
+ return callExpr;
43
+ }
44
+
45
+ function getTokenFromNode(j, path, debug, paletteColor) {
46
+ var baseMeta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
47
+ var foundMeta = getMetaFromAncestors(j, path);
48
+ var propertyName = foundMeta.find(function (name) {
49
+ if (!name) {
50
+ return false;
51
+ }
52
+
53
+ return name.toLowerCase().match(/(.*color|image|fill|stroke|shadow|border(?!-)|background(?!-)|outline(?!-)|column-rule-color)/);
54
+ });
55
+ var state = 'resting';
56
+ foundMeta.find(function (name) {
57
+ if (!name) {
58
+ return false;
59
+ }
60
+
61
+ var result = /(hover|active|disabled)/.exec(name.toLowerCase());
62
+
63
+ if (result) {
64
+ if (result[0] === 'active') {
65
+ state = 'pressed';
66
+ } else {
67
+ state = result[0];
68
+ }
69
+
70
+ return true;
71
+ }
72
+
73
+ return false;
74
+ });
75
+ var tokenResult = colorToToken(paletteColor || '', {
76
+ state: state,
77
+ propertyName: propertyName
78
+ }, function () {
79
+ var searchTerm = cleanMeta([].concat(_toConsumableArray(foundMeta), _toConsumableArray(baseMeta))).join(' ');
80
+ var results = search.get(searchTerm);
81
+
82
+ if (results) {
83
+ return results.map(function (result) {
84
+ return result[1];
85
+ });
86
+ }
87
+
88
+ return [];
89
+ });
90
+ return tokenResult;
91
+ }
92
+
93
+ export default function transformer(file, api) {
94
+ var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
95
+ var j = api.jscodeshift;
96
+ var source = j(file.source);
97
+ var transformed = false;
98
+ source // Handle colors.N100
99
+ .find(j.MemberExpression).filter(function (path) {
100
+ return path.value.object.type === 'Identifier' && path.value.object.name === 'colors' && path.value.property.type === 'Identifier' && isLegacyColor(path.value.property.name);
101
+ }).filter(function (path) {
102
+ return !isDecendantOfToken(j, path);
103
+ }).forEach(function (path) {
104
+ debug && console.log('file:', file.path);
105
+ insertTokenImport(j, source);
106
+ var key = path.value.property.type === 'Identifier' ? path.value.property.name : undefined;
107
+ var colorMeta = legacyColorMetaMap[key] || [];
108
+ var tokenId = getTokenFromNode(j, path, debug, key, colorMeta);
109
+ j(path).replaceWith(buildToken(j, tokenId, path.value));
110
+ transformed = true;
111
+ });
112
+ source.find(j.ObjectProperty).filter(function (path) {
113
+ return path.value.value.type === 'Identifier' && (isLegacyColor(path.value.value.name) || isLegacyNamedColor(path.value.value.name));
114
+ }).filter(function (path) {
115
+ return hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme/colors');
116
+ }).filter(function (path) {
117
+ return !isDecendantOfToken(j, path.value.value);
118
+ }).forEach(function (path) {
119
+ var valuePath = path.get('value');
120
+ debug && console.log('file:', file.path);
121
+ insertTokenImport(j, source);
122
+ var colorMeta = legacyColorMetaMap[valuePath.name] || [];
123
+ var tokenId = getTokenFromNode(j, valuePath, debug, valuePath.name, colorMeta);
124
+ j(path).replaceWith(j.objectProperty(path.value.key, buildToken(j, tokenId, valuePath.value)));
125
+ transformed = true;
126
+ });
127
+ source.find(j.Identifier).filter(function (path) {
128
+ return isLegacyColor(path.value.name) || isLegacyNamedColor(path.value.name);
129
+ }).filter(function (path) {
130
+ return hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme/colors');
131
+ }).filter(function (path) {
132
+ return !['ImportSpecifier', 'MemberExpression', 'ObjectProperty'].includes(path.parentPath.value.type);
133
+ }).filter(function (path) {
134
+ return !isDecendantOfToken(j, path);
135
+ }).forEach(function (path) {
136
+ debug && console.log('file:', file.path);
137
+ insertTokenImport(j, source);
138
+ var colorMeta = legacyColorMetaMap[path.value.name] || [];
139
+ var tokenId = getTokenFromNode(j, path, debug, path.value.name, colorMeta);
140
+ j(path).replaceWith(buildToken(j, tokenId, path.value));
141
+ transformed = true;
142
+ });
143
+ source.find(j.Literal).filter(function (path) {
144
+ return typeof path.value.value === 'string' && (includesHardCodedColor(path.value.value) || isHardCodedColor(path.value.value));
145
+ }).filter(function (path) {
146
+ return !isDecendantOfToken(j, path);
147
+ }).forEach(function (path) {
148
+ var _path$value, _path$value$value;
149
+
150
+ debug && console.log('file:', file.path);
151
+ insertTokenImport(j, source);
152
+ 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();
153
+ var colorMeta = legacyColorMetaMap[value] || [];
154
+ var tokenId = getTokenFromNode(j, path, debug, value, colorMeta);
155
+ var tokenNode = buildToken(j, tokenId, path.value);
156
+ j(path).replaceWith(isDecendantOfType(j, path, j.JSXAttribute) ? j.jsxExpressionContainer(tokenNode) : tokenNode);
157
+ transformed = true;
158
+ });
159
+
160
+ if (transformed) {
161
+ return source.toSource();
162
+ }
163
+
164
+ return file.source;
165
+ }
@@ -0,0 +1 @@
1
+ export {};