@atlaskit/codemod-cli 0.13.3 → 0.13.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.
- package/CHANGELOG.md +6 -0
- package/README.md +117 -3
- package/dist/cjs/cli.js +70 -75
- package/dist/cjs/filepath.js +65 -29
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/main.js +329 -167
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +72 -31
- package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -3
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +19 -6
- package/dist/cjs/presets/index.js +3 -1
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +19 -12
- package/dist/cjs/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +51 -36
- package/dist/cjs/presets/theme-remove-deprecated-mixins/utils/replacements.js +25 -25
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +66 -46
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +33 -18
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +11 -7
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +10 -6
- 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 +16 -2
- package/dist/cjs/sinceRef.js +69 -35
- package/dist/cjs/transforms.js +44 -26
- package/dist/cjs/types.js +27 -3
- package/dist/cjs/utils.js +6 -6
- package/dist/es2019/cli.js +4 -0
- package/dist/es2019/main.js +2 -0
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +1 -0
- package/dist/es2019/sinceRef.js +1 -0
- package/dist/esm/cli.js +4 -0
- package/dist/esm/main.js +3 -1
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +1 -0
- package/dist/esm/sinceRef.js +1 -0
- package/package.json +2 -2
- package/dist/cjs/version.json +0 -4
- package/dist/es2019/version.json +0 -4
- package/dist/esm/version.json +0 -4
|
@@ -4,140 +4,140 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.colorReplacements = void 0;
|
|
7
|
-
|
|
7
|
+
var colorReplacements = {
|
|
8
8
|
background: {
|
|
9
|
-
fullReplacement:
|
|
9
|
+
fullReplacement: "themed({ light: token('elevation.surface', N0), dark: token('elevation.surface', DN30) })",
|
|
10
10
|
staticReplacement: 'N0',
|
|
11
11
|
tokenId: 'elevation.surface',
|
|
12
12
|
importSpecifiers: ['N0', 'DN30']
|
|
13
13
|
},
|
|
14
14
|
backgroundActive: {
|
|
15
|
-
fullReplacement:
|
|
15
|
+
fullReplacement: "themed({ light: token('color.background.selected', B50), dark: token('color.background.selected', B75) })",
|
|
16
16
|
staticReplacement: 'B50',
|
|
17
17
|
tokenId: 'color.background.selected',
|
|
18
18
|
importSpecifiers: ['B50', 'B75']
|
|
19
19
|
},
|
|
20
20
|
backgroundHover: {
|
|
21
|
-
fullReplacement:
|
|
21
|
+
fullReplacement: "themed({ light: token('color.background.neutral.hovered', N30), dark: token('color.background.neutral.hovered', DN70) })",
|
|
22
22
|
staticReplacement: 'N30',
|
|
23
23
|
tokenId: 'color.background.neutral.hovered',
|
|
24
24
|
importSpecifiers: ['N30', 'DN70']
|
|
25
25
|
},
|
|
26
26
|
backgroundOnLayer: {
|
|
27
|
-
fullReplacement:
|
|
27
|
+
fullReplacement: "themed({ light: token('elevation.surface.overlay', N0), dark: token('elevation.surface.overlay', DN50) })",
|
|
28
28
|
staticReplacement: 'N0',
|
|
29
29
|
tokenId: 'elevation.surface.overlay',
|
|
30
30
|
importSpecifiers: ['N0', 'DN50']
|
|
31
31
|
},
|
|
32
32
|
text: {
|
|
33
|
-
fullReplacement:
|
|
33
|
+
fullReplacement: "themed({ light: token('color.text', N900), dark: token('color.text', DN600) })",
|
|
34
34
|
staticReplacement: 'N900',
|
|
35
35
|
tokenId: 'color.text',
|
|
36
36
|
importSpecifiers: ['N900', 'DN600']
|
|
37
37
|
},
|
|
38
38
|
textHover: {
|
|
39
|
-
fullReplacement:
|
|
39
|
+
fullReplacement: "themed({ light: token('color.text', N800), dark: token('color.text', DN600) })",
|
|
40
40
|
staticReplacement: 'N800',
|
|
41
41
|
tokenId: 'color.text',
|
|
42
42
|
importSpecifiers: ['N800', 'DN600']
|
|
43
43
|
},
|
|
44
44
|
textActive: {
|
|
45
|
-
fullReplacement:
|
|
45
|
+
fullReplacement: "themed({ light: token('color.text.selected', B400), dark: token('color.text.selected', B400) })",
|
|
46
46
|
staticReplacement: 'B400',
|
|
47
47
|
tokenId: 'color.text.selected',
|
|
48
48
|
importSpecifiers: ['B400', 'B400']
|
|
49
49
|
},
|
|
50
50
|
subtleText: {
|
|
51
|
-
fullReplacement:
|
|
51
|
+
fullReplacement: "themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })",
|
|
52
52
|
staticReplacement: 'N200',
|
|
53
53
|
tokenId: 'color.text.subtlest',
|
|
54
54
|
importSpecifiers: ['N200', 'DN300']
|
|
55
55
|
},
|
|
56
56
|
placeholderText: {
|
|
57
|
-
fullReplacement:
|
|
57
|
+
fullReplacement: "themed({ light: token('color.text.subtlest', N100), dark: token('color.text.subtlest', DN200) })",
|
|
58
58
|
staticReplacement: 'N100',
|
|
59
59
|
tokenId: 'color.text.subtlest',
|
|
60
60
|
importSpecifiers: ['N100', 'DN200']
|
|
61
61
|
},
|
|
62
62
|
heading: {
|
|
63
|
-
fullReplacement:
|
|
63
|
+
fullReplacement: "themed({ light: token('color.text', N800), dark: token('color.text', DN600) })",
|
|
64
64
|
staticReplacement: 'N800',
|
|
65
65
|
tokenId: 'color.text',
|
|
66
66
|
importSpecifiers: ['N800', 'DN600']
|
|
67
67
|
},
|
|
68
68
|
subtleHeading: {
|
|
69
|
-
fullReplacement:
|
|
69
|
+
fullReplacement: "themed({ light: token('color.text.subtlest', N200), dark: token('color.text.subtlest', DN300) })",
|
|
70
70
|
staticReplacement: 'N200',
|
|
71
71
|
tokenId: 'color.text.subtlest',
|
|
72
72
|
importSpecifiers: ['N200', 'DN300']
|
|
73
73
|
},
|
|
74
74
|
codeBlock: {
|
|
75
|
-
fullReplacement:
|
|
75
|
+
fullReplacement: "themed({ light: N20, dark: DN50 });",
|
|
76
76
|
staticReplacement: 'N20',
|
|
77
77
|
importSpecifiers: ['N20', 'DN50']
|
|
78
78
|
},
|
|
79
79
|
link: {
|
|
80
|
-
fullReplacement:
|
|
80
|
+
fullReplacement: "themed({ light: token('color.link', B400), dark: token('color.link', B100) })",
|
|
81
81
|
staticReplacement: 'B400',
|
|
82
82
|
tokenId: 'color.link',
|
|
83
83
|
importSpecifiers: ['B400', 'B100']
|
|
84
84
|
},
|
|
85
85
|
linkHover: {
|
|
86
|
-
fullReplacement:
|
|
86
|
+
fullReplacement: "themed({ light: token('color.link.pressed', B300), dark: token('color.link.pressed', B200) })",
|
|
87
87
|
staticReplacement: 'B300',
|
|
88
88
|
tokenId: 'color.link.pressed',
|
|
89
89
|
importSpecifiers: ['B300', 'B200']
|
|
90
90
|
},
|
|
91
91
|
linkActive: {
|
|
92
|
-
fullReplacement:
|
|
92
|
+
fullReplacement: "themed({ light: token('color.link.pressed', B500), dark: token('color.link.pressed', B100) })",
|
|
93
93
|
staticReplacement: 'B500',
|
|
94
94
|
tokenId: 'color.link.pressed',
|
|
95
95
|
importSpecifiers: ['B500', 'B100']
|
|
96
96
|
},
|
|
97
97
|
linkOutline: {
|
|
98
|
-
fullReplacement:
|
|
98
|
+
fullReplacement: "themed({ light: token('color.border.focused', B100), dark: token('color.border.focused', B200) })",
|
|
99
99
|
staticReplacement: 'B100',
|
|
100
100
|
tokenId: 'color.border.focused',
|
|
101
101
|
importSpecifiers: ['B100', 'B200']
|
|
102
102
|
},
|
|
103
103
|
primary: {
|
|
104
|
-
fullReplacement:
|
|
104
|
+
fullReplacement: "themed({ light: token('color.background.brand.bold', B400), dark: token('color.background.brand.bold', B100) })",
|
|
105
105
|
staticReplacement: 'B400',
|
|
106
106
|
tokenId: 'color.background.brand.bold',
|
|
107
107
|
importSpecifiers: ['B400', 'B100']
|
|
108
108
|
},
|
|
109
109
|
blue: {
|
|
110
|
-
fullReplacement:
|
|
110
|
+
fullReplacement: "themed({ light: B400, dark: B100, })",
|
|
111
111
|
staticReplacement: 'B400',
|
|
112
112
|
importSpecifiers: ['B400', 'B100']
|
|
113
113
|
},
|
|
114
114
|
teal: {
|
|
115
|
-
fullReplacement:
|
|
115
|
+
fullReplacement: "themed({ light: T300, dark: T200 })",
|
|
116
116
|
staticReplacement: 'T300',
|
|
117
117
|
importSpecifiers: ['T300', 'T200']
|
|
118
118
|
},
|
|
119
119
|
purple: {
|
|
120
|
-
fullReplacement:
|
|
120
|
+
fullReplacement: "themed({ light: P300, dark: P100 })",
|
|
121
121
|
staticReplacement: 'P300',
|
|
122
122
|
importSpecifiers: ['P300', 'P100']
|
|
123
123
|
},
|
|
124
124
|
red: {
|
|
125
|
-
fullReplacement:
|
|
125
|
+
fullReplacement: "R300",
|
|
126
126
|
staticReplacement: 'R300',
|
|
127
127
|
importSpecifiers: ['R300']
|
|
128
128
|
},
|
|
129
129
|
yellow: {
|
|
130
|
-
fullReplacement:
|
|
130
|
+
fullReplacement: "Y300",
|
|
131
131
|
staticReplacement: 'Y300',
|
|
132
132
|
importSpecifiers: ['Y300']
|
|
133
133
|
},
|
|
134
134
|
green: {
|
|
135
|
-
fullReplacement:
|
|
135
|
+
fullReplacement: "G300",
|
|
136
136
|
staticReplacement: 'G300',
|
|
137
137
|
importSpecifiers: ['G300']
|
|
138
138
|
},
|
|
139
139
|
skeleton: {
|
|
140
|
-
fullReplacement:
|
|
140
|
+
fullReplacement: "token('color.skeleton', N20A)",
|
|
141
141
|
staticReplacement: 'N20A',
|
|
142
142
|
tokenId: 'color.skeleton',
|
|
143
143
|
importSpecifiers: ['N20A']
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = transformer;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
8
9
|
var _utils = require("@codeshift/utils");
|
|
9
10
|
var _ast = require("./utils/ast");
|
|
10
11
|
var _astMeta = require("./utils/ast-meta");
|
|
@@ -14,24 +15,28 @@ var _legacyColors = require("./utils/legacy-colors");
|
|
|
14
15
|
var _tokens = require("./utils/tokens");
|
|
15
16
|
/* eslint-disable no-console */
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
var kebabize = function kebabize(str) {
|
|
19
|
+
return str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, function ($, ofs) {
|
|
20
|
+
return (ofs ? '-' : '') + $.toLowerCase();
|
|
21
|
+
});
|
|
22
|
+
};
|
|
18
23
|
function isBoldColor(color) {
|
|
19
|
-
|
|
24
|
+
var number = parseInt(color.replace(/^./, ''), 10);
|
|
20
25
|
return number > 300;
|
|
21
26
|
}
|
|
22
27
|
function insertTokenImport(j, source) {
|
|
23
28
|
if ((0, _utils.hasImportDeclaration)(j, source, '@atlaskit/tokens')) {
|
|
24
29
|
return;
|
|
25
30
|
}
|
|
26
|
-
|
|
31
|
+
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
27
32
|
source.get().node.program.body.unshift(newImport);
|
|
28
33
|
}
|
|
29
34
|
function buildToken(j, tokenId, node) {
|
|
30
|
-
|
|
35
|
+
var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
31
36
|
return callExpr;
|
|
32
37
|
}
|
|
33
38
|
function getColorFromIdentifier(expression) {
|
|
34
|
-
|
|
39
|
+
var value = '';
|
|
35
40
|
if (expression.type === 'Identifier') {
|
|
36
41
|
value = expression.name;
|
|
37
42
|
}
|
|
@@ -44,9 +49,9 @@ function getColorFromIdentifier(expression) {
|
|
|
44
49
|
return value;
|
|
45
50
|
}
|
|
46
51
|
function getTokenFromNode(j, path, value, propertyName) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
var valueMeta = (0, _astMeta.cleanMeta)(_legacyColors.legacyColorMetaMap[value] || []);
|
|
53
|
+
var ancestorMeta = (0, _astMeta.cleanMeta)([].concat((0, _toConsumableArray2.default)((0, _astMeta.getMetaFromAncestors)(j, path)), (0, _toConsumableArray2.default)(kebabize(propertyName).split('-'))) || []);
|
|
54
|
+
var property = (0, _astMeta.cleanMeta)([kebabize(propertyName)])[0];
|
|
50
55
|
|
|
51
56
|
// Attempt to find a property from ancestors if one is not found
|
|
52
57
|
if (!property || !['border', 'icon', 'background', 'text'].includes(property)) {
|
|
@@ -63,10 +68,12 @@ function getTokenFromNode(j, path, value, propertyName) {
|
|
|
63
68
|
property = 'text';
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
var meta = [];
|
|
72
|
+
var possibleTokens = _tokens.tokens;
|
|
68
73
|
if (property === 'text') {
|
|
69
|
-
possibleTokens = _tokens.tokens.filter(
|
|
74
|
+
possibleTokens = _tokens.tokens.filter(function (token) {
|
|
75
|
+
return token.includes('.text');
|
|
76
|
+
});
|
|
70
77
|
if (valueMeta.includes('neutral')) {
|
|
71
78
|
meta.push('color', 'text');
|
|
72
79
|
}
|
|
@@ -79,17 +86,17 @@ function getTokenFromNode(j, path, value, propertyName) {
|
|
|
79
86
|
|
|
80
87
|
// handle non-neutrals
|
|
81
88
|
if (!valueMeta.includes('neutral')) {
|
|
82
|
-
meta.push('color',
|
|
89
|
+
meta.push.apply(meta, ['color'].concat((0, _toConsumableArray2.default)(ancestorMeta), (0, _toConsumableArray2.default)(valueMeta)));
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
92
|
if (property === 'background' || property === 'background-color') {
|
|
86
93
|
if (ancestorMeta.includes('disabled')) {
|
|
87
94
|
// disabled backgrounds
|
|
88
|
-
meta.push(property,
|
|
95
|
+
meta.push.apply(meta, [property].concat((0, _toConsumableArray2.default)(ancestorMeta)));
|
|
89
96
|
} else if (
|
|
90
97
|
// Surfaces
|
|
91
98
|
valueMeta.includes('neutral') && value !== 'N100' && value !== 'N200' && value !== 'N300' && value !== 'N400' && value !== 'N500' && value !== 'N600' && value !== 'N700' && value !== 'N800') {
|
|
92
|
-
meta.push('surface',
|
|
99
|
+
meta.push.apply(meta, ['surface'].concat((0, _toConsumableArray2.default)(ancestorMeta)));
|
|
93
100
|
} else if (value.includes('N0')) {
|
|
94
101
|
// default surface
|
|
95
102
|
meta.push('elevation', 'surface');
|
|
@@ -102,47 +109,54 @@ function getTokenFromNode(j, path, value, propertyName) {
|
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
if (property === 'border' || property === 'border-color' || property === 'border-left' || property === 'border-right' || property === 'border-top' || property === 'border-bottom' || property === 'outline' || property === 'outline-color') {
|
|
105
|
-
possibleTokens = _tokens.tokens.filter(
|
|
112
|
+
possibleTokens = _tokens.tokens.filter(function (token) {
|
|
113
|
+
return token.includes('.border') || token.includes('.focus');
|
|
114
|
+
});
|
|
106
115
|
if (valueMeta.includes('neutral')) {
|
|
107
116
|
// standard netural boarder
|
|
108
|
-
meta.push('color', 'border',
|
|
117
|
+
meta.push.apply(meta, ['color', 'border'].concat((0, _toConsumableArray2.default)(ancestorMeta)));
|
|
109
118
|
} else {
|
|
110
|
-
meta.push('border',
|
|
119
|
+
meta.push.apply(meta, ['border'].concat((0, _toConsumableArray2.default)(valueMeta), (0, _toConsumableArray2.default)(ancestorMeta)));
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
if (ancestorMeta.includes('icon')) {
|
|
114
|
-
possibleTokens = _tokens.tokens.filter(
|
|
123
|
+
possibleTokens = _tokens.tokens.filter(function (token) {
|
|
124
|
+
return token.includes('.icon');
|
|
125
|
+
});
|
|
115
126
|
if (ancestorMeta.includes('disabled')) {
|
|
116
127
|
// disabled backgrounds
|
|
117
128
|
meta.push('disabled');
|
|
118
129
|
}
|
|
119
|
-
meta.push('color', 'icon',
|
|
130
|
+
meta.push.apply(meta, ['color', 'icon'].concat((0, _toConsumableArray2.default)(valueMeta)));
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
// Fallback if guided behavior yields nothing
|
|
123
134
|
if (meta.length === 0) {
|
|
124
|
-
meta.push(property,
|
|
135
|
+
meta.push.apply(meta, [property].concat((0, _toConsumableArray2.default)(valueMeta), (0, _toConsumableArray2.default)(ancestorMeta)));
|
|
125
136
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
var search = (0, _fuzzySearch.default)(possibleTokens, false);
|
|
138
|
+
var results = search.get(meta.join(' '));
|
|
139
|
+
var tokenId = ['MISSING_TOKEN'];
|
|
129
140
|
if (results) {
|
|
130
|
-
tokenId = results.map(
|
|
141
|
+
tokenId = results.map(function (result) {
|
|
142
|
+
return result[1];
|
|
143
|
+
});
|
|
131
144
|
}
|
|
132
145
|
return tokenId[0];
|
|
133
146
|
}
|
|
134
147
|
function parseCSSPropertyName(cssString) {
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
var lastColonIndex = cssString.lastIndexOf(':');
|
|
149
|
+
var propertyNameEndIndex = Math.max(cssString.lastIndexOf(';', lastColonIndex), cssString.lastIndexOf(' ', lastColonIndex));
|
|
137
150
|
return cssString.slice(propertyNameEndIndex + 1, lastColonIndex).trim();
|
|
138
151
|
}
|
|
139
|
-
function transformer(file, api
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
function transformer(file, api) {
|
|
153
|
+
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
154
|
+
var j = api.jscodeshift;
|
|
155
|
+
var source = j(file.source);
|
|
156
|
+
var transformed = false;
|
|
143
157
|
|
|
144
158
|
// Objects
|
|
145
|
-
source.find(j.ObjectProperty).forEach(path
|
|
159
|
+
source.find(j.ObjectProperty).forEach(function (path) {
|
|
146
160
|
if (path.value.value.type === 'ObjectExpression') {
|
|
147
161
|
return;
|
|
148
162
|
}
|
|
@@ -154,11 +168,11 @@ function transformer(file, api, debug = false) {
|
|
|
154
168
|
if ((0, _ast.isParentOfToken)(j, path.value.value)) {
|
|
155
169
|
return;
|
|
156
170
|
}
|
|
157
|
-
|
|
171
|
+
var value = getColorFromIdentifier(path.value.value);
|
|
158
172
|
if (!value || !(0, _color.includesHardCodedColor)(value) && !(0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
159
173
|
return;
|
|
160
174
|
}
|
|
161
|
-
|
|
175
|
+
var key;
|
|
162
176
|
if (path.value.key.type === 'NumericLiteral' || path.value.key.type === 'StringLiteral') {
|
|
163
177
|
key = path.value.key.value.toString();
|
|
164
178
|
}
|
|
@@ -170,14 +184,14 @@ function transformer(file, api, debug = false) {
|
|
|
170
184
|
if (!key) {
|
|
171
185
|
return;
|
|
172
186
|
}
|
|
173
|
-
|
|
187
|
+
var tokenId = getTokenFromNode(j, path, value, key);
|
|
174
188
|
insertTokenImport(j, source);
|
|
175
189
|
j(path).replaceWith(j.objectProperty(path.value.key, buildToken(j, tokenId, path.value.value)));
|
|
176
190
|
transformed = true;
|
|
177
191
|
});
|
|
178
192
|
|
|
179
193
|
// Template literals
|
|
180
|
-
source.find(j.TemplateLiteral).forEach(path
|
|
194
|
+
source.find(j.TemplateLiteral).forEach(function (path) {
|
|
181
195
|
function replaceTemplateLiteralExpressions(j, expression, index) {
|
|
182
196
|
if ((0, _ast.isDecendantOfToken)(j, expression)) {
|
|
183
197
|
return;
|
|
@@ -185,22 +199,28 @@ function transformer(file, api, debug = false) {
|
|
|
185
199
|
if (index >= path.value.quasis.length) {
|
|
186
200
|
return;
|
|
187
201
|
}
|
|
188
|
-
|
|
189
|
-
|
|
202
|
+
var quasi = path.value.quasis[index];
|
|
203
|
+
var value = getColorFromIdentifier(expression.value);
|
|
190
204
|
if (!value || !(0, _color.includesHardCodedColor)(value) && !(0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
191
205
|
return;
|
|
192
206
|
}
|
|
193
|
-
|
|
207
|
+
var tokenId = getTokenFromNode(j, expression, value, parseCSSPropertyName(quasi.value.cooked || ''));
|
|
194
208
|
insertTokenImport(j, source);
|
|
195
209
|
expression.replace(buildToken(j, tokenId, expression.value));
|
|
196
210
|
}
|
|
197
|
-
j(path).find(j.Identifier).filter(
|
|
198
|
-
|
|
211
|
+
j(path).find(j.Identifier).filter(function (expression) {
|
|
212
|
+
return !(0, _utils.isDecendantOfType)(j, expression, j.MemberExpression);
|
|
213
|
+
}).forEach(function (expression, i) {
|
|
214
|
+
return replaceTemplateLiteralExpressions(j, expression, i);
|
|
215
|
+
});
|
|
216
|
+
j(path).find(j.MemberExpression).forEach(function (expression, i) {
|
|
217
|
+
return replaceTemplateLiteralExpressions(j, expression, i);
|
|
218
|
+
});
|
|
199
219
|
transformed = true;
|
|
200
220
|
});
|
|
201
221
|
|
|
202
222
|
// JSX props
|
|
203
|
-
source.find(j.JSXAttribute).forEach(path
|
|
223
|
+
source.find(j.JSXAttribute).forEach(function (path) {
|
|
204
224
|
var _path$value, _path$value$value;
|
|
205
225
|
if (((_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.type) !== 'JSXExpressionContainer') {
|
|
206
226
|
return;
|
|
@@ -208,15 +228,15 @@ function transformer(file, api, debug = false) {
|
|
|
208
228
|
if ((0, _ast.isParentOfToken)(j, path)) {
|
|
209
229
|
return;
|
|
210
230
|
}
|
|
211
|
-
|
|
212
|
-
|
|
231
|
+
var expression = path.value.value.expression;
|
|
232
|
+
var value = getColorFromIdentifier(expression);
|
|
213
233
|
if (!value || !(0, _color.includesHardCodedColor)(value) && !(0, _color.isHardCodedColor)(value) && !(0, _color.isLegacyColor)(value) && !(0, _color.isLegacyNamedColor)(value)) {
|
|
214
234
|
return;
|
|
215
235
|
}
|
|
216
|
-
|
|
236
|
+
var tokenId = getTokenFromNode(j, path, value, path.value.name.name);
|
|
217
237
|
insertTokenImport(j, source);
|
|
218
|
-
j(path).find(j.JSXExpressionContainer).forEach(path
|
|
219
|
-
|
|
238
|
+
j(path).find(j.JSXExpressionContainer).forEach(function (path) {
|
|
239
|
+
var tokenNode = buildToken(j, tokenId, path.value.expression);
|
|
220
240
|
j(path).replaceWith(j.jsxExpressionContainer(tokenNode));
|
|
221
241
|
});
|
|
222
242
|
transformed = true;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.cleanMeta = cleanMeta;
|
|
7
8
|
exports.getMetaFromAncestors = getMetaFromAncestors;
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
8
10
|
var _ast = require("./ast");
|
|
9
11
|
var _tokens = require("./tokens");
|
|
10
|
-
function getMetaFromAncestors(j, path
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
function getMetaFromAncestors(j, path) {
|
|
13
|
+
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
14
|
+
var parent = path.parentPath;
|
|
15
|
+
var grandParent = parent && parent.parentPath;
|
|
13
16
|
if (parent && parent.value.type === 'ObjectProperty') {
|
|
14
|
-
|
|
17
|
+
var value = '';
|
|
15
18
|
if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
|
|
16
19
|
value = parent.value.key.value.toString();
|
|
17
20
|
} else {
|
|
@@ -20,13 +23,19 @@ function getMetaFromAncestors(j, path, meta = []) {
|
|
|
20
23
|
meta.push(value);
|
|
21
24
|
}
|
|
22
25
|
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
grandParent.value.quasis
|
|
26
|
+
var expressionIndex = grandParent.value.expressions.findIndex(function (exp) {
|
|
27
|
+
return exp.name === path.value.name;
|
|
28
|
+
});
|
|
29
|
+
var quasi = grandParent.value.quasis[expressionIndex];
|
|
30
|
+
var propertyName = (quasi.value.cooked || quasi.value.raw || '').replace(/\n/g, '').split(/;|{|}/).filter(function (el) {
|
|
31
|
+
return !el.match(/\.|\@|\(|\)/);
|
|
32
|
+
}).pop().split(/:/g)[0].trim();
|
|
33
|
+
grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
|
|
34
|
+
return q.value.cooked;
|
|
35
|
+
})
|
|
27
36
|
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
28
|
-
.reverse().some(str
|
|
29
|
-
|
|
37
|
+
.reverse().some(function (str) {
|
|
38
|
+
var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
30
39
|
if (result) {
|
|
31
40
|
meta.push(result[0]);
|
|
32
41
|
return true;
|
|
@@ -39,11 +48,11 @@ function getMetaFromAncestors(j, path, meta = []) {
|
|
|
39
48
|
meta.push(parent.value.name.name);
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
|
-
|
|
51
|
+
var closestJSXElement = (0, _ast.getClosestDecendantOfType)(j, path, j.JSXOpeningElement);
|
|
43
52
|
if (closestJSXElement) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
meta.push(
|
|
53
|
+
var jsxElementName = closestJSXElement.value.name.name;
|
|
54
|
+
var nameComponents = jsxElementName.replace(/([a-z])([A-Z])/g, '$1 $2').split(' ');
|
|
55
|
+
meta.push.apply(meta, (0, _toConsumableArray2.default)(nameComponents));
|
|
47
56
|
}
|
|
48
57
|
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
49
58
|
meta.push(parent.value.id.name);
|
|
@@ -54,11 +63,17 @@ function getMetaFromAncestors(j, path, meta = []) {
|
|
|
54
63
|
return meta;
|
|
55
64
|
}
|
|
56
65
|
function cleanMeta(meta) {
|
|
57
|
-
return meta.reduce(
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
return meta.reduce(function (accum, val) {
|
|
67
|
+
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
68
|
+
return e.toLowerCase();
|
|
69
|
+
}) : []));
|
|
70
|
+
}, []).reduce(function (accum, val) {
|
|
71
|
+
var cleanVal = val.replace(/:/g, '').replace(/,/g, '').replace('grey', 'neutral').replace('skeleton', '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('primary', 'bold').replace('secondary', 'subtle').replace('hyperlink', 'link').replace('anchor', 'link').replace('active', 'pressed').replace('hover', 'hovered').replace('card', 'raised').replace('dragged', 'surface overlay').replace('dragging', 'surface overlay').replace('drag', 'surface overlay').replace('background-color', 'background').replace('color', 'text').replace('icons', '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');
|
|
72
|
+
accum.push.apply(accum, (0, _toConsumableArray2.default)(cleanVal.split(' ')));
|
|
60
73
|
return accum;
|
|
61
|
-
}, []).filter(
|
|
74
|
+
}, []).filter(function (val) {
|
|
75
|
+
return _tokens.getUniqueWordsFromTokens.includes(val);
|
|
76
|
+
}).reduce(function (accum, val) {
|
|
62
77
|
if (!accum.includes(val)) {
|
|
63
78
|
accum.push(val);
|
|
64
79
|
}
|
|
@@ -6,24 +6,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.includesHardCodedColor = void 0;
|
|
7
7
|
var _legacyColors = require("./legacy-colors");
|
|
8
8
|
var _namedColors = require("./named-colors");
|
|
9
|
-
|
|
9
|
+
var isLegacyColor = function isLegacyColor(value) {
|
|
10
|
+
return _legacyColors.legacyColors.includes(value);
|
|
11
|
+
};
|
|
10
12
|
exports.isLegacyColor = isLegacyColor;
|
|
11
|
-
|
|
13
|
+
var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
14
|
+
return _legacyColors.legacyColorMixins.includes(value);
|
|
15
|
+
};
|
|
12
16
|
exports.isLegacyNamedColor = isLegacyNamedColor;
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
var includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
18
|
+
var value = raw.toLowerCase();
|
|
15
19
|
if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
|
|
16
20
|
return true;
|
|
17
21
|
}
|
|
18
|
-
for (
|
|
19
|
-
if (value.includes(
|
|
22
|
+
for (var i = 0; i < _namedColors.namedColors.length; i++) {
|
|
23
|
+
if (value.includes("".concat(_namedColors.namedColors[i], ";"))) {
|
|
20
24
|
return true;
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
return false;
|
|
24
28
|
};
|
|
25
29
|
exports.includesHardCodedColor = includesHardCodedColor;
|
|
26
|
-
|
|
30
|
+
var isHardCodedColor = function isHardCodedColor(value) {
|
|
27
31
|
if (_namedColors.namedColors.includes(value.toLowerCase())) {
|
|
28
32
|
return true;
|
|
29
33
|
}
|
|
@@ -9,7 +9,11 @@ exports.default = void 0;
|
|
|
9
9
|
/**
|
|
10
10
|
* Fuzzy search ripped from the internet.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
var FuzzySet = function FuzzySet() {
|
|
13
|
+
var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
|
+
var useLevenshtein = arguments.length > 1 ? arguments[1] : undefined;
|
|
15
|
+
var gramSizeLower = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
|
|
16
|
+
var gramSizeUpper = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3;
|
|
13
17
|
var fuzzyset = {
|
|
14
18
|
gramSizeLower: gramSizeLower,
|
|
15
19
|
gramSizeUpper: gramSizeUpper,
|
|
@@ -18,7 +22,7 @@ const FuzzySet = function (arr = [], useLevenshtein, gramSizeLower = 2, gramSize
|
|
|
18
22
|
matchDict: {},
|
|
19
23
|
items: {}
|
|
20
24
|
};
|
|
21
|
-
var levenshtein = function (str1, str2) {
|
|
25
|
+
var levenshtein = function levenshtein(str1, str2) {
|
|
22
26
|
var current = [];
|
|
23
27
|
var prev;
|
|
24
28
|
var value;
|
|
@@ -43,7 +47,7 @@ const FuzzySet = function (arr = [], useLevenshtein, gramSizeLower = 2, gramSize
|
|
|
43
47
|
};
|
|
44
48
|
|
|
45
49
|
// return an edit distance from 0 to 1
|
|
46
|
-
var _distance = function (str1, str2) {
|
|
50
|
+
var _distance = function _distance(str1, str2) {
|
|
47
51
|
if (str1 === null && str2 === null) {
|
|
48
52
|
throw new Error('Trying to compare two null values');
|
|
49
53
|
}
|
|
@@ -60,7 +64,7 @@ const FuzzySet = function (arr = [], useLevenshtein, gramSizeLower = 2, gramSize
|
|
|
60
64
|
}
|
|
61
65
|
};
|
|
62
66
|
var _nonWordRe = /[^a-zA-Z0-9\u00C0-\u00FF, ]+/g;
|
|
63
|
-
var _iterateGrams = function (value, gramSize) {
|
|
67
|
+
var _iterateGrams = function _iterateGrams(value, gramSize) {
|
|
64
68
|
gramSize = gramSize || 2;
|
|
65
69
|
var simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-',
|
|
66
70
|
lenDiff = gramSize - simplified.length,
|
|
@@ -75,7 +79,7 @@ const FuzzySet = function (arr = [], useLevenshtein, gramSizeLower = 2, gramSize
|
|
|
75
79
|
}
|
|
76
80
|
return results;
|
|
77
81
|
};
|
|
78
|
-
var _gramCounter = function (value, gramSize) {
|
|
82
|
+
var _gramCounter = function _gramCounter(value, gramSize) {
|
|
79
83
|
// return an object where key=gram, value=number of occurrences
|
|
80
84
|
gramSize = gramSize || 2;
|
|
81
85
|
var result = {},
|
|
@@ -165,7 +169,7 @@ const FuzzySet = function (arr = [], useLevenshtein, gramSizeLower = 2, gramSize
|
|
|
165
169
|
matchScore = matches[matchIndex];
|
|
166
170
|
results.push([matchScore / (vectorNormal * items[matchIndex][0]), items[matchIndex][1]]);
|
|
167
171
|
}
|
|
168
|
-
var sortDescending = function (a, b) {
|
|
172
|
+
var sortDescending = function sortDescending(a, b) {
|
|
169
173
|
if (a[0] < b[0]) {
|
|
170
174
|
return 1;
|
|
171
175
|
} else if (a[0] > b[0]) {
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.legacyColors = exports.legacyColorMixins = exports.legacyColorMetaMap = void 0;
|
|
7
|
-
|
|
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
8
|
exports.legacyColors = legacyColors;
|
|
9
|
-
|
|
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
10
|
exports.legacyColorMixins = legacyColorMixins;
|
|
11
|
-
|
|
11
|
+
var legacyColorMetaMap = {
|
|
12
12
|
R50: ['danger'],
|
|
13
13
|
R75: ['danger'],
|
|
14
14
|
R100: ['danger'],
|