@atlaskit/codemod-cli 0.8.3 → 0.8.6

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 (49) hide show
  1. package/CHANGELOG.md +20 -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 +145 -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 +88 -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.js +59 -0
  10. package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +348 -0
  11. package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +83 -0
  12. package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +8 -0
  13. package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +38 -0
  14. package/dist/cjs/types.js +4 -2
  15. package/dist/cjs/version.json +1 -1
  16. package/dist/es2019/presets/index.js +2 -1
  17. package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +100 -0
  18. package/dist/es2019/presets/theme-to-design-tokens/types.js +1 -0
  19. package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +63 -0
  20. package/dist/es2019/presets/theme-to-design-tokens/utils/ast.js +10 -0
  21. package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +35 -0
  22. package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +336 -0
  23. package/dist/es2019/presets/theme-to-design-tokens/utils/legacy-colors.js +74 -0
  24. package/dist/es2019/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
  25. package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +12 -0
  26. package/dist/es2019/version.json +1 -1
  27. package/dist/esm/main.js +3 -3
  28. package/dist/esm/presets/index.js +3 -2
  29. package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +130 -0
  30. package/dist/esm/presets/theme-to-design-tokens/types.js +1 -0
  31. package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +75 -0
  32. package/dist/esm/presets/theme-to-design-tokens/utils/ast.js +10 -0
  33. package/dist/esm/presets/theme-to-design-tokens/utils/color.js +39 -0
  34. package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +340 -0
  35. package/dist/esm/presets/theme-to-design-tokens/utils/legacy-colors.js +74 -0
  36. package/dist/esm/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
  37. package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +24 -0
  38. package/dist/esm/types.js +3 -2
  39. package/dist/esm/version.json +1 -1
  40. package/dist/types/presets/index.d.ts +1 -0
  41. package/dist/types/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +2 -0
  42. package/dist/types/presets/theme-to-design-tokens/utils/ast-meta.d.ts +3 -0
  43. package/dist/types/presets/theme-to-design-tokens/utils/ast.d.ts +3 -0
  44. package/dist/types/presets/theme-to-design-tokens/utils/color.d.ts +4 -0
  45. package/dist/types/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +5 -0
  46. package/dist/types/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +3 -0
  47. package/dist/types/presets/theme-to-design-tokens/utils/named-colors.d.ts +1 -0
  48. package/dist/types/presets/theme-to-design-tokens/utils/tokens.d.ts +2 -0
  49. package/package.json +3 -2
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /* eslint-disable */
9
+
10
+ /**
11
+ * Fuzzy search ripped from the internet.
12
+ */
13
+ var FuzzySet = function FuzzySet() {
14
+ var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
15
+ var useLevenshtein = arguments.length > 1 ? arguments[1] : undefined;
16
+ var gramSizeLower = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
17
+ var gramSizeUpper = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3;
18
+ var fuzzyset = {
19
+ gramSizeLower: gramSizeLower,
20
+ gramSizeUpper: gramSizeUpper,
21
+ useLevenshtein: typeof useLevenshtein !== 'boolean' ? true : useLevenshtein,
22
+ exactSet: {},
23
+ matchDict: {},
24
+ items: {}
25
+ };
26
+
27
+ var levenshtein = function levenshtein(str1, str2) {
28
+ var current = [];
29
+ var prev;
30
+ var value;
31
+
32
+ for (var i = 0; i <= str2.length; i++) {
33
+ for (var j = 0; j <= str1.length; j++) {
34
+ if (i && j) {
35
+ if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
36
+ // @ts-expect-error
37
+ value = prev;
38
+ } else {
39
+ // @ts-expect-error
40
+ value = Math.min(current[j], current[j - 1], prev) + 1;
41
+ }
42
+ } else {
43
+ value = i + j;
44
+ }
45
+
46
+ prev = current[j];
47
+ current[j] = value;
48
+ }
49
+ }
50
+
51
+ return current.pop();
52
+ }; // return an edit distance from 0 to 1
53
+
54
+
55
+ var _distance = function _distance(str1, str2) {
56
+ if (str1 === null && str2 === null) {
57
+ throw new Error('Trying to compare two null values');
58
+ }
59
+
60
+ if (str1 === null || str2 === null) {
61
+ return 0;
62
+ }
63
+
64
+ str1 = String(str1);
65
+ str2 = String(str2);
66
+ var distance = levenshtein(str1, str2);
67
+
68
+ if (str1.length > str2.length) {
69
+ return 1 - distance / str1.length;
70
+ } else {
71
+ return 1 - distance / str2.length;
72
+ }
73
+ };
74
+
75
+ var _nonWordRe = /[^a-zA-Z0-9\u00C0-\u00FF, ]+/g;
76
+
77
+ var _iterateGrams = function _iterateGrams(value, gramSize) {
78
+ gramSize = gramSize || 2;
79
+ var simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-',
80
+ lenDiff = gramSize - simplified.length,
81
+ results = [];
82
+
83
+ if (lenDiff > 0) {
84
+ for (var i = 0; i < lenDiff; ++i) {
85
+ simplified += '-';
86
+ }
87
+ }
88
+
89
+ for (var i = 0; i < simplified.length - gramSize + 1; ++i) {
90
+ results.push(simplified.slice(i, i + gramSize));
91
+ }
92
+
93
+ return results;
94
+ };
95
+
96
+ var _gramCounter = function _gramCounter(value, gramSize) {
97
+ // return an object where key=gram, value=number of occurrences
98
+ gramSize = gramSize || 2;
99
+
100
+ var result = {},
101
+ grams = _iterateGrams(value, gramSize),
102
+ i = 0;
103
+
104
+ for (i; i < grams.length; ++i) {
105
+ if (grams[i] in result) {
106
+ // @ts-expect-error
107
+ result[grams[i]] += 1;
108
+ } else {
109
+ // @ts-expect-error
110
+ result[grams[i]] = 1;
111
+ }
112
+ }
113
+
114
+ return result;
115
+ }; // the main functions
116
+
117
+
118
+ fuzzyset.get = function (value, defaultValue, minMatchScore) {
119
+ // check for value in set, returning defaultValue or null if none found
120
+ if (minMatchScore === undefined) {
121
+ minMatchScore = 0.33;
122
+ }
123
+
124
+ var result = this._get(value, minMatchScore);
125
+
126
+ if (!result && typeof defaultValue !== 'undefined') {
127
+ return defaultValue;
128
+ }
129
+
130
+ return result;
131
+ };
132
+
133
+ fuzzyset._get = function (value, minMatchScore) {
134
+ var results = []; // start with high gram size and if there are no results, go to lower gram sizes
135
+
136
+ for (var gramSize = this.gramSizeUpper; gramSize >= this.gramSizeLower; --gramSize) {
137
+ results = this.__get(value, gramSize, minMatchScore);
138
+
139
+ if (results && results.length > 0) {
140
+ return results;
141
+ }
142
+ }
143
+
144
+ return null;
145
+ };
146
+
147
+ fuzzyset.__get = function (value, gramSize, minMatchScore) {
148
+ var normalizedValue = this._normalizeStr(value),
149
+ matches = {},
150
+ gramCounts = _gramCounter(normalizedValue, gramSize),
151
+ items = this.items[gramSize],
152
+ sumOfSquareGramCounts = 0,
153
+ gram,
154
+ gramCount,
155
+ i,
156
+ index,
157
+ otherGramCount;
158
+
159
+ for (gram in gramCounts) {
160
+ // @ts-expect-error
161
+ gramCount = gramCounts[gram];
162
+ sumOfSquareGramCounts += Math.pow(gramCount, 2);
163
+
164
+ if (gram in this.matchDict) {
165
+ for (i = 0; i < this.matchDict[gram].length; ++i) {
166
+ index = this.matchDict[gram][i][0];
167
+ otherGramCount = this.matchDict[gram][i][1];
168
+
169
+ if (index in matches) {
170
+ // @ts-expect-error
171
+ matches[index] += gramCount * otherGramCount;
172
+ } else {
173
+ // @ts-expect-error
174
+ matches[index] = gramCount * otherGramCount;
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ function isEmptyObject(obj) {
181
+ for (var prop in obj) {
182
+ if (obj.hasOwnProperty(prop)) {
183
+ return false;
184
+ }
185
+ }
186
+
187
+ return true;
188
+ }
189
+
190
+ if (isEmptyObject(matches)) {
191
+ return null;
192
+ }
193
+
194
+ var vectorNormal = Math.sqrt(sumOfSquareGramCounts),
195
+ results = [],
196
+ matchScore; // build a results list of [score, str]
197
+
198
+ for (var matchIndex in matches) {
199
+ // @ts-expect-error
200
+ matchScore = matches[matchIndex];
201
+ results.push([matchScore / (vectorNormal * items[matchIndex][0]), items[matchIndex][1]]);
202
+ }
203
+
204
+ var sortDescending = function sortDescending(a, b) {
205
+ if (a[0] < b[0]) {
206
+ return 1;
207
+ } else if (a[0] > b[0]) {
208
+ return -1;
209
+ } else {
210
+ return 0;
211
+ }
212
+ };
213
+
214
+ results.sort(sortDescending);
215
+
216
+ if (this.useLevenshtein) {
217
+ var newResults = [],
218
+ endIndex = Math.min(50, results.length); // truncate somewhat arbitrarily to 50
219
+ // @ts-expect-error
220
+
221
+ for (var i = 0; i < endIndex; ++i) {
222
+ // @ts-expect-error
223
+ newResults.push([_distance(results[i][1], normalizedValue), results[i][1]]);
224
+ }
225
+
226
+ results = newResults;
227
+ results.sort(sortDescending);
228
+ }
229
+
230
+ newResults = [];
231
+ results.forEach(function (scoreWordPair) {
232
+ if (scoreWordPair[0] >= minMatchScore) {
233
+ // @ts-expect-error
234
+ newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]);
235
+ }
236
+ }.bind(this));
237
+ return newResults;
238
+ };
239
+
240
+ fuzzyset.add = function (value) {
241
+ var normalizedValue = this._normalizeStr(value);
242
+
243
+ if (normalizedValue in this.exactSet) {
244
+ return false;
245
+ }
246
+
247
+ var i = this.gramSizeLower;
248
+
249
+ for (i; i < this.gramSizeUpper + 1; ++i) {
250
+ this._add(value, i);
251
+ }
252
+ };
253
+
254
+ fuzzyset._add = function (value, gramSize) {
255
+ var normalizedValue = this._normalizeStr(value),
256
+ items = this.items[gramSize] || [],
257
+ index = items.length;
258
+
259
+ items.push(0);
260
+
261
+ var gramCounts = _gramCounter(normalizedValue, gramSize);
262
+
263
+ var sumOfSquareGramCounts = 0;
264
+ var gram;
265
+ var gramCount;
266
+
267
+ for (gram in gramCounts) {
268
+ // @ts-expect-error
269
+ gramCount = gramCounts[gram];
270
+ sumOfSquareGramCounts += Math.pow(gramCount, 2);
271
+
272
+ if (gram in this.matchDict) {
273
+ this.matchDict[gram].push([index, gramCount]);
274
+ } else {
275
+ this.matchDict[gram] = [[index, gramCount]];
276
+ }
277
+ }
278
+
279
+ var vectorNormal = Math.sqrt(sumOfSquareGramCounts);
280
+ items[index] = [vectorNormal, normalizedValue];
281
+ this.items[gramSize] = items;
282
+ this.exactSet[normalizedValue] = value;
283
+ };
284
+
285
+ fuzzyset._normalizeStr = function (str) {
286
+ if (Object.prototype.toString.call(str) !== '[object String]') {
287
+ throw new Error('Must use a string as argument to FuzzySet functions');
288
+ }
289
+
290
+ return str.toLowerCase();
291
+ }; // return length of items in set
292
+
293
+
294
+ fuzzyset.length = function () {
295
+ var count = 0,
296
+ prop;
297
+
298
+ for (prop in this.exactSet) {
299
+ if (this.exactSet.hasOwnProperty(prop)) {
300
+ count += 1;
301
+ }
302
+ }
303
+
304
+ return count;
305
+ }; // return is set is empty
306
+
307
+
308
+ fuzzyset.isEmpty = function () {
309
+ for (var prop in this.exactSet) {
310
+ if (this.exactSet.hasOwnProperty(prop)) {
311
+ return false;
312
+ }
313
+ }
314
+
315
+ return true;
316
+ }; // return list of values loaded into set
317
+
318
+
319
+ fuzzyset.values = function () {
320
+ var values = [],
321
+ prop;
322
+
323
+ for (prop in this.exactSet) {
324
+ if (this.exactSet.hasOwnProperty(prop)) {
325
+ values.push(this.exactSet[prop]);
326
+ }
327
+ }
328
+
329
+ return values;
330
+ }; // initialization
331
+
332
+
333
+ var i = fuzzyset.gramSizeLower;
334
+
335
+ for (i; i < fuzzyset.gramSizeUpper + 1; ++i) {
336
+ fuzzyset.items[i] = [];
337
+ } // add all the items to the set
338
+
339
+
340
+ for (i = 0; i < arr.length; ++i) {
341
+ fuzzyset.add(arr[i]);
342
+ }
343
+
344
+ return fuzzyset;
345
+ };
346
+
347
+ var _default = FuzzySet;
348
+ exports.default = _default;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.legacyColors = exports.legacyColorMixins = exports.legacyColorMetaMap = void 0;
7
+ var 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'];
8
+ exports.legacyColors = legacyColors;
9
+ var 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'];
10
+ exports.legacyColorMixins = legacyColorMixins;
11
+ var legacyColorMetaMap = {
12
+ R50: ['danger'],
13
+ R75: ['danger'],
14
+ R100: ['danger'],
15
+ R200: ['danger'],
16
+ R300: ['danger'],
17
+ R400: ['danger'],
18
+ R500: ['danger'],
19
+ Y50: ['warning'],
20
+ Y75: ['warning'],
21
+ Y100: ['warning'],
22
+ Y200: ['warning'],
23
+ Y300: ['warning'],
24
+ Y400: ['warning'],
25
+ Y500: ['warning'],
26
+ G50: ['success'],
27
+ G75: ['success'],
28
+ G100: ['success'],
29
+ G200: ['success'],
30
+ G300: ['success'],
31
+ G400: ['success'],
32
+ G500: ['success'],
33
+ B50: ['brand'],
34
+ B75: ['brand'],
35
+ B100: ['brand'],
36
+ B200: ['brand'],
37
+ B300: ['brand'],
38
+ B400: ['brand'],
39
+ B500: ['brand'],
40
+ P50: ['discovery'],
41
+ P75: ['discovery'],
42
+ P100: ['discovery'],
43
+ P200: ['discovery'],
44
+ P300: ['discovery'],
45
+ P400: ['discovery'],
46
+ P500: ['discovery'],
47
+ T50: ['accent', 'teal'],
48
+ T75: ['accent', 'teal'],
49
+ T100: ['accent', 'teal'],
50
+ T200: ['accent', 'teal'],
51
+ T300: ['accent', 'teal'],
52
+ T400: ['accent', 'teal'],
53
+ T500: ['accent', 'teal'],
54
+ N0: ['inverse'],
55
+ N700: ['text'],
56
+ N800: ['text'],
57
+ N900: ['text'],
58
+ background: ['background', 'default'],
59
+ backgroundActive: ['background', 'pressed'],
60
+ backgroundHover: ['background', 'hovered'],
61
+ backgroundOnLayer: ['background', 'blanket'],
62
+ text: ['text'],
63
+ textHover: ['text', 'subtle'],
64
+ textActive: ['text', 'link', 'pressed'],
65
+ subtleText: ['text', 'subtlest'],
66
+ placeholderText: ['text', 'subtlest'],
67
+ heading: ['text'],
68
+ subtleHeading: ['text', 'subtle'],
69
+ link: ['link'],
70
+ linkHover: ['link', 'hovered'],
71
+ linkActive: ['link', 'pressed'],
72
+ linkOutline: ['border', 'selected'],
73
+ primary: ['brand'],
74
+ blue: ['accent', 'blue'],
75
+ teal: ['accent', 'teal'],
76
+ purple: ['accent', 'purple'],
77
+ red: ['accent', 'red'],
78
+ yellow: ['accent', 'orange'],
79
+ green: ['accent', 'green'],
80
+ grey: ['background', 'neutral'],
81
+ skeleton: ['background', 'neutral']
82
+ };
83
+ exports.legacyColorMetaMap = legacyColorMetaMap;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.namedColors = void 0;
7
+ var 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'];
8
+ exports.namedColors = namedColors;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.tokens = exports.getUniqueWordsFromTokens = void 0;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ var _tokenNames = _interopRequireDefault(require("@atlaskit/tokens/token-names"));
13
+
14
+ var _renameMapping = _interopRequireDefault(require("@atlaskit/tokens/rename-mapping"));
15
+
16
+ var tokens = Object.keys(_tokenNames.default).filter(function (t) {
17
+ return !t.includes('UNSAFE') && !t.includes('interaction');
18
+ }).filter(function (t) {
19
+ return !_renameMapping.default.find(function (_ref) {
20
+ var path = _ref.path;
21
+ return t === path.replace(/\.[default]\g/, '');
22
+ });
23
+ });
24
+ exports.tokens = tokens;
25
+ var getUniqueWordsFromTokens = Object.keys(_tokenNames.default).reduce(function (accum, val) {
26
+ return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(val.split('.')));
27
+ }, []).reduce(function (accum, val) {
28
+ return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(val.split(/(?=[A-Z])/g).map(function (e) {
29
+ return e.toLowerCase();
30
+ })));
31
+ }, []).reduce(function (accum, val) {
32
+ if (!accum.includes(val)) {
33
+ accum.push(val);
34
+ }
35
+
36
+ return accum;
37
+ }, []);
38
+ exports.getUniqueWordsFromTokens = getUniqueWordsFromTokens;
package/dist/cjs/types.js CHANGED
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.ValidationError = exports.NoTransformsExistError = void 0;
9
9
 
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+
10
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
13
 
12
14
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
@@ -34,7 +36,7 @@ var ValidationError = /*#__PURE__*/function (_Error) {
34
36
  return _super.apply(this, arguments);
35
37
  }
36
38
 
37
- return ValidationError;
39
+ return (0, _createClass2.default)(ValidationError);
38
40
  }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
39
41
 
40
42
  exports.ValidationError = ValidationError;
@@ -49,7 +51,7 @@ var NoTransformsExistError = /*#__PURE__*/function (_Error2) {
49
51
  return _super2.apply(this, arguments);
50
52
  }
51
53
 
52
- return NoTransformsExistError;
54
+ return (0, _createClass2.default)(NoTransformsExistError);
53
55
  }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
54
56
 
55
57
  exports.NoTransformsExistError = NoTransformsExistError;
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.8.3"
3
+ "version": "0.8.6"
4
4
  }
@@ -5,5 +5,6 @@ import path from 'path';
5
5
  */
6
6
 
7
7
  import './styled-to-emotion/styled-to-emotion';
8
- const presets = ['styled-to-emotion'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js)`));
8
+ import './theme-to-design-tokens/theme-to-design-tokens';
9
+ const presets = ['styled-to-emotion', 'theme-to-design-tokens'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
9
10
  export default presets;
@@ -0,0 +1,100 @@
1
+ /* eslint-disable no-console */
2
+ import { isDecendantOfToken, isDecendantOfType } from './utils/ast';
3
+ import { cleanMeta, getMetaFromAncestors } from './utils/ast-meta';
4
+ import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from './utils/color';
5
+ import Search from './utils/fuzzy-search';
6
+ import { legacyColorMetaMap } from './utils/legacy-colors';
7
+ import { tokens } from './utils/tokens';
8
+ const search = Search(tokens, false);
9
+
10
+ function hasImportDeclaration(j, source, sourcePath) {
11
+ return !!source.find(j.ImportDeclaration).filter(path => path.node.source.value === sourcePath).length;
12
+ }
13
+
14
+ function hasImportSpecifier(j, source, specifier, sourcePath) {
15
+ return !!source.find(j.ImportDeclaration).filter(path => path.node.source.value === sourcePath).find(j.ImportSpecifier, {
16
+ local: {
17
+ name: specifier
18
+ }
19
+ }).length;
20
+ }
21
+
22
+ function insertTokenImport(j, source) {
23
+ if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
24
+ return;
25
+ }
26
+
27
+ const newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
28
+ source.get().node.program.body.unshift(newImport);
29
+ }
30
+
31
+ function buildToken(j, tokenId, node) {
32
+ const callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
33
+ return callExpr;
34
+ }
35
+
36
+ function getTokenFromNode(j, path, baseMeta = []) {
37
+ const foundMeta = getMetaFromAncestors(j, path);
38
+ const meta = cleanMeta([...foundMeta, ...baseMeta]);
39
+ const results = search.get(meta.join(' '));
40
+ let tokenId = ['utility.UNSAFE_util.MISSING_TOKEN'];
41
+
42
+ if (results) {
43
+ tokenId = results.map(result => result[1]);
44
+ }
45
+
46
+ return tokenId[0];
47
+ }
48
+
49
+ export default function transformer(file, api, debug = false) {
50
+ const j = api.jscodeshift;
51
+ const source = j(file.source);
52
+ let transformed = false;
53
+ source // Handle colors.N100
54
+ .find(j.MemberExpression).filter(path => {
55
+ return path.value.object.type === 'Identifier' && path.value.object.name === 'colors' && path.value.property.type === 'Identifier' && isLegacyColor(path.value.property.name);
56
+ }).filter(path => !isDecendantOfToken(j, path)).forEach(path => {
57
+ debug && console.log('file:', file.path);
58
+ insertTokenImport(j, source);
59
+ const key = path.value.property.type === 'Identifier' ? path.value.property.name : undefined;
60
+ const colorMeta = legacyColorMetaMap[key] || [];
61
+ const tokenId = getTokenFromNode(j, path, colorMeta);
62
+ j(path).replaceWith(buildToken(j, tokenId, path.value));
63
+ transformed = true;
64
+ });
65
+ source.find(j.ObjectProperty).filter(path => path.value.value.type === 'Identifier' && (isLegacyColor(path.value.value.name) || isLegacyNamedColor(path.value.value.name))).filter(path => 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')).filter(path => !isDecendantOfToken(j, path.value.value)).forEach(path => {
66
+ const valuePath = path.get('value');
67
+ debug && console.log('file:', file.path);
68
+ insertTokenImport(j, source);
69
+ const colorMeta = legacyColorMetaMap[valuePath.name] || [];
70
+ const tokenId = getTokenFromNode(j, valuePath, colorMeta);
71
+ j(path).replaceWith(j.objectProperty(path.value.key, buildToken(j, tokenId, valuePath.value)));
72
+ transformed = true;
73
+ });
74
+ source.find(j.Identifier).filter(path => isLegacyColor(path.value.name) || isLegacyNamedColor(path.value.name)).filter(path => hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme/colors')).filter(path => !['ImportSpecifier', 'MemberExpression', 'ObjectProperty'].includes(path.parentPath.value.type)).filter(path => !isDecendantOfToken(j, path)).forEach(path => {
75
+ debug && console.log('file:', file.path);
76
+ insertTokenImport(j, source);
77
+ const colorMeta = legacyColorMetaMap[path.value.name] || [];
78
+ const tokenId = getTokenFromNode(j, path, colorMeta);
79
+ j(path).replaceWith(buildToken(j, tokenId, path.value));
80
+ transformed = true;
81
+ });
82
+ source.find(j.Literal).filter(path => typeof path.value.value === 'string' && (includesHardCodedColor(path.value.value) || isHardCodedColor(path.value.value))).filter(path => !isDecendantOfToken(j, path)).forEach(path => {
83
+ var _path$value, _path$value$value;
84
+
85
+ debug && console.log('file:', file.path);
86
+ insertTokenImport(j, source);
87
+ const 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();
88
+ const colorMeta = legacyColorMetaMap[value] || [];
89
+ const tokenId = getTokenFromNode(j, path, colorMeta);
90
+ const tokenNode = buildToken(j, tokenId, path.value);
91
+ j(path).replaceWith(isDecendantOfType(j, path, j.JSXAttribute) ? j.jsxExpressionContainer(tokenNode) : tokenNode);
92
+ transformed = true;
93
+ });
94
+
95
+ if (transformed) {
96
+ return source.toSource();
97
+ }
98
+
99
+ return file.source;
100
+ }