@workday/canvas-kit-codemod 7.0.0-alpha.0-next.7 → 7.0.0-alpha.78-next.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.
- package/dist/es6/v7/recategorizeIconButtons.d.ts +3 -0
- package/dist/es6/v7/recategorizeIconButtons.d.ts.map +1 -0
- package/dist/es6/v7/recategorizeIconButtons.js +114 -0
- package/dist/es6/v7/renameIconPosition.d.ts +3 -0
- package/dist/es6/v7/renameIconPosition.d.ts.map +1 -0
- package/dist/es6/v7/renameIconPosition.js +37 -0
- package/dist/es6/v7/renameIconRef.d.ts +3 -0
- package/dist/es6/v7/renameIconRef.d.ts.map +1 -0
- package/dist/es6/v7/renameIconRef.js +70 -0
- package/dist/es6/v7/updateSegmentedControl.d.ts +3 -0
- package/dist/es6/v7/updateSegmentedControl.d.ts.map +1 -0
- package/dist/es6/v7/updateSegmentedControl.js +24 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recategorizeIconButtons.d.ts","sourceRoot":"","sources":["../../../lib/v7/recategorizeIconButtons.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAMR,MAAM,aAAa,CAAC;AAarB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAsI7E"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
var updateJSXTag = function (nodePath, newTag) {
|
|
3
|
+
var componentName = nodePath.value.openingElement.name.name;
|
|
4
|
+
if (componentName === 'IconButton') {
|
|
5
|
+
nodePath.value.openingElement.name.name = newTag;
|
|
6
|
+
if (nodePath.value.closingElement) {
|
|
7
|
+
nodePath.value.closingElement.name.name = newTag;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default function transformer(file, api, options) {
|
|
12
|
+
var j = api.jscodeshift;
|
|
13
|
+
var root = j(file.source);
|
|
14
|
+
var requiredImportSpecifiers = [];
|
|
15
|
+
/**
|
|
16
|
+
* 1. Find button imports
|
|
17
|
+
*/
|
|
18
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
19
|
+
if (!containsCanvasImports) {
|
|
20
|
+
return file.source;
|
|
21
|
+
}
|
|
22
|
+
var buttonType = 'TertiaryButton'; //default button if no variant is specified
|
|
23
|
+
// Button Mapping
|
|
24
|
+
// circle -> tertiary
|
|
25
|
+
// circle-filled -> secondary
|
|
26
|
+
// inverse -> tertiary inverse
|
|
27
|
+
// inverse-filled -> secondary inverse
|
|
28
|
+
// plain/square -> not supported
|
|
29
|
+
// square-filled -> not supported
|
|
30
|
+
/**
|
|
31
|
+
* 2. Find `IconButton`
|
|
32
|
+
* - If it has no variant, it means it's "circle" which is the default
|
|
33
|
+
* - Swap to `TertiaryButton`
|
|
34
|
+
* - Add `TertiaryButton` import if it doesn't exist.
|
|
35
|
+
* - If not
|
|
36
|
+
* - check the variant of the IconButton
|
|
37
|
+
* - Swap it out for the appropriate mapping
|
|
38
|
+
*/
|
|
39
|
+
root
|
|
40
|
+
.find(j.JSXElement, function (value) {
|
|
41
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
42
|
+
(value.openingElement.name.name === importMap.IconButton ||
|
|
43
|
+
value.openingElement.name.name === styledMap.IconButton);
|
|
44
|
+
})
|
|
45
|
+
.forEach(function (nodePath) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
var attrs = nodePath.value.openingElement.attributes;
|
|
48
|
+
var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
|
|
49
|
+
// Default IconButton variant is `circle`
|
|
50
|
+
if (variantProp) {
|
|
51
|
+
var variantPropValue = (_a = variantProp.value) === null || _a === void 0 ? void 0 : _a.value;
|
|
52
|
+
buttonType = /filled/gi.test(variantPropValue) ? 'SecondaryButton' : 'TertiaryButton';
|
|
53
|
+
if (!variantPropValue.includes('inverse')) {
|
|
54
|
+
(_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b.splice(attrs === null || attrs === void 0 ? void 0 : attrs.indexOf(variantProp), 1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
updateJSXTag(nodePath, buttonType);
|
|
58
|
+
requiredImportSpecifiers.push(buttonType);
|
|
59
|
+
});
|
|
60
|
+
// Find all instances of IconButton within a style function
|
|
61
|
+
// const StyledIconButton = styled(IconButton) gets renamed to
|
|
62
|
+
// const StyledIconButton = styled(CorrectButtonMapping)
|
|
63
|
+
root.find(j.VariableDeclarator).forEach(function (nodePath) {
|
|
64
|
+
var _a;
|
|
65
|
+
if (((_a = nodePath.value.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
|
|
66
|
+
nodePath.value.init.callee.type === 'CallExpression' &&
|
|
67
|
+
nodePath.value.init.callee.arguments[0].type === 'Identifier') {
|
|
68
|
+
nodePath.value.init.callee.arguments[0].name = buttonType;
|
|
69
|
+
requiredImportSpecifiers.push(buttonType);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Remove old imports: `IconButton`
|
|
74
|
+
* Add new required imports
|
|
75
|
+
*/
|
|
76
|
+
var buttonImports = root.find(j.ImportDeclaration, {
|
|
77
|
+
source: { value: function (value) { return value.includes('@workday/canvas-kit-react'); } },
|
|
78
|
+
});
|
|
79
|
+
if (!buttonImports.length) {
|
|
80
|
+
// Add new specifiers to a new import
|
|
81
|
+
var allImports = root.find(j.ImportDeclaration);
|
|
82
|
+
var lastImport = allImports.at(allImports.length);
|
|
83
|
+
if (lastImport) {
|
|
84
|
+
lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(function (specifier) { return j.importSpecifier(j.identifier(specifier)); }), j.stringLiteral('@workday/canvas-kit-react/button')));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
buttonImports.forEach(function (_a) {
|
|
89
|
+
var _b;
|
|
90
|
+
var node = _a.node;
|
|
91
|
+
var specifiersToRemove = ['IconButton'];
|
|
92
|
+
// Remove old specifiers
|
|
93
|
+
if (typeof node.source.value === 'string' &&
|
|
94
|
+
node.source.value.includes('@workday/canvas-kit-react')) {
|
|
95
|
+
(_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.forEach(function (specifier) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
98
|
+
specifiersToRemove.includes(specifier.imported.name)) {
|
|
99
|
+
// delete specifier
|
|
100
|
+
(_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.splice((_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.indexOf(specifier), 1);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// Add new specifiers to existing import
|
|
105
|
+
requiredImportSpecifiers.forEach(function (specifier) {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(function (existing) { return existing.type === 'ImportSpecifier' && existing.imported.name === specifier; }))) {
|
|
108
|
+
(_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.push(j.importSpecifier(j.identifier(specifier)));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return root.toSource();
|
|
114
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameIconPosition.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameIconPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAA+C,MAAM,aAAa,CAAC;AAIjG,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA+C7E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
export default function transformer(file, api, options) {
|
|
3
|
+
var j = api.jscodeshift;
|
|
4
|
+
var root = j(file.source);
|
|
5
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
6
|
+
if (!containsCanvasImports) {
|
|
7
|
+
return file.source;
|
|
8
|
+
}
|
|
9
|
+
root
|
|
10
|
+
.find(j.JSXElement, function (value) {
|
|
11
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
12
|
+
(value.openingElement.name.name ===
|
|
13
|
+
(importMap.PrimaryButton || importMap.SecondaryButton) ||
|
|
14
|
+
value.openingElement.name.name === (styledMap.PrimaryButton || styledMap.SecondaryButton));
|
|
15
|
+
})
|
|
16
|
+
.forEach(function (nodePath) {
|
|
17
|
+
var _a;
|
|
18
|
+
var findAttribute = function (name) { return function (item) {
|
|
19
|
+
return item.type === 'JSXAttribute' &&
|
|
20
|
+
item.name.type === 'JSXIdentifier' &&
|
|
21
|
+
item.name.name === name;
|
|
22
|
+
}; };
|
|
23
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
24
|
+
if (attributes) {
|
|
25
|
+
var iconPosition = attributes.find(findAttribute('iconPosition'));
|
|
26
|
+
if (((_a = iconPosition === null || iconPosition === void 0 ? void 0 : iconPosition.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
27
|
+
if (iconPosition.value.value === 'left') {
|
|
28
|
+
iconPosition.value.value = 'start';
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
iconPosition.value.value = 'end';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return root.toSource();
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameIconRef.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameIconRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAgBlE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiE7E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
var inputsMap = {
|
|
3
|
+
'@workday/canvas-kit-react/icon': [
|
|
4
|
+
'AccentIcon',
|
|
5
|
+
'AppletIcon',
|
|
6
|
+
'SystemIcon',
|
|
7
|
+
'SystemIconCircle',
|
|
8
|
+
'Graphic',
|
|
9
|
+
'Svg',
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
export default function transformer(file, api, options) {
|
|
13
|
+
var j = api.jscodeshift;
|
|
14
|
+
var root = j(file.source);
|
|
15
|
+
// defaultImports should be an array of local names that were imported using
|
|
16
|
+
// a default import from any of the modules listed in inputsMap. For example,
|
|
17
|
+
// given...
|
|
18
|
+
//
|
|
19
|
+
// ```
|
|
20
|
+
// import Checkbox from '@workday/canvas-kit-react/checkbox';
|
|
21
|
+
// import CanvasTextArea from '@workday/canvas-kit-react/text-area';
|
|
22
|
+
// import {TextInput} from '@workday/canvas-kit-react/text-input';
|
|
23
|
+
// import StatusIndicator from '@workday/canvas-kit-react/status-indicator';
|
|
24
|
+
// ```
|
|
25
|
+
//
|
|
26
|
+
// ... defaultImports should be set to `['Checkbox', 'CanvasTextArea']`
|
|
27
|
+
var defaultImports = [];
|
|
28
|
+
root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
|
|
29
|
+
var _a;
|
|
30
|
+
var packageName = nodePath.parent.node.source.value;
|
|
31
|
+
var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
32
|
+
if (packageName in inputsMap && localName) {
|
|
33
|
+
defaultImports.push(localName);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var runningSource = file.source;
|
|
37
|
+
var _loop_1 = function (inputPackageName) {
|
|
38
|
+
var currentRoot = j(runningSource);
|
|
39
|
+
var _a = getImportRenameMap(j, currentRoot, inputPackageName), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
40
|
+
if (containsCanvasImports) {
|
|
41
|
+
var inputNames_1 = inputsMap[inputPackageName];
|
|
42
|
+
currentRoot
|
|
43
|
+
.find(j.JSXIdentifier, function (value) { return value.name === 'iconRef'; })
|
|
44
|
+
.replaceWith(function (nodePath) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
var elementName = (_d = (_c = (_b = (_a = nodePath.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.name;
|
|
47
|
+
// Rewrite inputRef to ref if any of the following are true:
|
|
48
|
+
// (a) elementName was the name used in a default import of the current
|
|
49
|
+
// input being processed (e.g., `import TextInput ...`)
|
|
50
|
+
// (b) elementName was the name used in a named import of the current
|
|
51
|
+
// input being processed (e.g., `import {TextInput} ...` or
|
|
52
|
+
// `import {TextInput as CanvasTextInput} ...`)
|
|
53
|
+
// (c) elementName was created by calling `styled` on the current input
|
|
54
|
+
// being processed (e.g., `const StyledTextInput = styled(TextInput)`)
|
|
55
|
+
if (defaultImports.includes(elementName) ||
|
|
56
|
+
inputNames_1.map(function (n) { return importMap[n]; }).includes(elementName) ||
|
|
57
|
+
inputNames_1.map(function (n) { return styledMap[n]; }).includes(elementName)) {
|
|
58
|
+
return j.jsxIdentifier('ref');
|
|
59
|
+
}
|
|
60
|
+
return nodePath.value;
|
|
61
|
+
});
|
|
62
|
+
runningSource = currentRoot.toSource();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
for (var _i = 0, _a = Object.keys(inputsMap); _i < _a.length; _i++) {
|
|
66
|
+
var inputPackageName = _a[_i];
|
|
67
|
+
_loop_1(inputPackageName);
|
|
68
|
+
}
|
|
69
|
+
return runningSource;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateSegmentedControl.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateSegmentedControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAa,MAAM,aAAa,CAAC;AAI/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAgC7E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
export default function transformer(file, api, options) {
|
|
3
|
+
var j = api.jscodeshift;
|
|
4
|
+
var root = j(file.source);
|
|
5
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/segmented-control'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
6
|
+
if (!containsCanvasImports) {
|
|
7
|
+
return file.source;
|
|
8
|
+
}
|
|
9
|
+
root
|
|
10
|
+
.find(j.JSXElement, function (value) {
|
|
11
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
12
|
+
(value.openingElement.name.name === importMap.SegmentedControl ||
|
|
13
|
+
value.openingElement.name.name === styledMap.SegmentedControl);
|
|
14
|
+
})
|
|
15
|
+
.forEach(function (nodePath) {
|
|
16
|
+
for (var _i = 0, _a = nodePath.value.children || []; _i < _a.length; _i++) {
|
|
17
|
+
var child = _a[_i];
|
|
18
|
+
if (child.type === 'JSXElement' && child.openingElement.name.type === 'JSXIdentifier') {
|
|
19
|
+
child.openingElement.name.name = 'SegmentedControl.Button';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return root.toSource();
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@workday/canvas-kit-codemod",
|
|
3
3
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "7.0.0-alpha.
|
|
5
|
+
"version": "7.0.0-alpha.78-next.6+400ffc0b",
|
|
6
6
|
"description": "A collection of codemods for use on Workday Canvas Kit packages.",
|
|
7
7
|
"main": "dist/es6/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"test": "TZ=UTC jest -c ../../jest.config.js",
|
|
43
43
|
"typecheck:src": "tsc -p . --noEmit --incremental false"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "400ffc0b29c2762180758d9b7c1bdc0562cb01e4"
|
|
46
46
|
}
|