@kaizen/components 1.69.1 → 1.70.0
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/codemods/migrateBrandMomentMoodToVariant/index.ts +5 -3
- package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.spec.ts +16 -5
- package/codemods/migrateCardVariantToColor/index.ts +5 -3
- package/codemods/migrateCardVariantToColor/transformCardVariantToColor.spec.ts +16 -5
- package/codemods/migrateConfirmationModalMoodsToVariant/index.ts +3 -1
- package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.spec.ts +27 -44
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/index.ts +5 -3
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.spec.ts +16 -5
- package/codemods/migrateGlobalNotificationTypeToVariant/index.ts +5 -3
- package/codemods/migrateInformationTileMoodToVariant/index.ts +5 -3
- package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.spec.ts +16 -7
- package/codemods/migrateInlineNotificationTypeToVariant/index.ts +5 -3
- package/codemods/migrateMultiActionTileMoodToVariant/index.ts +5 -3
- package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.spec.ts +16 -7
- package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.spec.ts +42 -43
- package/codemods/migrateProgressBarMoodToColor/index.ts +5 -3
- package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.spec.ts +16 -5
- package/codemods/migrateToastNotificationTypeToVariant/index.ts +6 -4
- package/codemods/migrateWellVariantToColor/index.ts +5 -3
- package/codemods/migrateWellVariantToColor/transformWellVariantToColor.spec.ts +26 -68
- package/codemods/migrateWellVariantToColor/transformWellVariantToColor.ts +10 -4
- package/codemods/removeInputEditModalMood/index.ts +3 -1
- package/codemods/removeInputEditModalMood/removeInputEditModalMood.spec.ts +23 -20
- package/codemods/removePopoverVariant/index.ts +1 -1
- package/codemods/removePopoverVariant/removePopoverVariant.spec.ts +23 -25
- package/codemods/upgradeIconV1/index.ts +2 -17
- package/codemods/upgradeIconV1/upgradeIconV1.spec.ts +18 -120
- package/codemods/upgradeIconV1/upgradeIconV1.ts +21 -28
- package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +0 -10
- package/codemods/utils/getKaioTagName.spec.ts +167 -23
- package/codemods/utils/getKaioTagName.ts +71 -35
- package/codemods/utils/migrateStringProp.spec.ts +16 -5
- package/codemods/utils/migrateStringProp.ts +10 -3
- package/codemods/utils/removeProps.spec.ts +26 -25
- package/codemods/utils/removeProps.ts +10 -3
- package/codemods/utils/transformComponentsInDir.ts +40 -13
- package/codemods/utils/transformSource.spec.ts +1 -27
- package/codemods/utils/transformSource.ts +0 -26
- package/codemods/utils/updateKaioImports.ts +2 -0
- package/dist/cjs/LinkButton/LinkButton.cjs +59 -0
- package/dist/cjs/LinkButton/LinkButton.module.css.cjs +6 -0
- package/dist/cjs/__rc__/Button/Button.module.css.cjs +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/esm/LinkButton/LinkButton.mjs +53 -0
- package/dist/esm/LinkButton/LinkButton.module.css.mjs +4 -0
- package/dist/esm/__rc__/Button/Button.module.css.mjs +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/styles.css +3259 -3229
- package/dist/types/LinkButton/LinkButton.d.ts +11 -0
- package/dist/types/LinkButton/index.d.ts +1 -0
- package/dist/types/__rc__/Button/Button.d.ts +6 -5
- package/dist/types/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/LinkButton/LinkButton.module.css +4 -0
- package/src/LinkButton/LinkButton.tsx +71 -0
- package/src/LinkButton/_docs/LinkButton--api-specification.mdx +281 -0
- package/src/LinkButton/_docs/LinkButton--usage-guidelines.mdx +29 -0
- package/src/LinkButton/_docs/LinkButton.doc.stories.tsx +136 -0
- package/src/LinkButton/_docs/LinkButton.spec.stories.tsx +80 -0
- package/src/LinkButton/_docs/LinkButton.stickersheet.stories.tsx +130 -0
- package/src/LinkButton/index.ts +1 -0
- package/src/__rc__/Button/Button.module.css +44 -19
- package/src/__rc__/Button/Button.tsx +8 -4
- package/src/__rc__/Button/_docs/Button--api-specification.mdx +5 -5
- package/src/__rc__/Button/_docs/Button--usage-guidelines.mdx +2 -5
- package/src/index.ts +1 -2
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { transformComponentsInDir } from '../utils'
|
|
2
2
|
import { transformWellVariantToColor } from './transformWellVariantToColor'
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const run = (): void => {
|
|
5
5
|
console.log(' ~(-_- ~) Running Well transformer (~ -_-)~')
|
|
6
6
|
const targetDir = process.argv[2]
|
|
7
7
|
if (!targetDir) {
|
|
8
8
|
process.exit(1)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
transformComponentsInDir(targetDir,
|
|
11
|
+
transformComponentsInDir(targetDir, ['Well'], (tagNames) => [
|
|
12
|
+
transformWellVariantToColor(tagNames),
|
|
13
|
+
])
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
run()
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { parseJsx } from '../__tests__/utils'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getKaioTagNamesMapByComponentName,
|
|
4
|
+
printAst,
|
|
5
|
+
transformSource,
|
|
6
|
+
type TransformSourceArgs,
|
|
7
|
+
} from '../utils'
|
|
3
8
|
import { transformWellVariantToColor } from './transformWellVariantToColor'
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
const transformWell = (sourceFile: TransformSourceArgs['sourceFile']): string => {
|
|
11
|
+
const kaioTagNamesMap = getKaioTagNamesMapByComponentName(sourceFile, ['Well'])
|
|
12
|
+
return transformSource({
|
|
13
|
+
sourceFile,
|
|
14
|
+
transformers: [transformWellVariantToColor(kaioTagNamesMap!)],
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('transformWellVariantToColor()', () => {
|
|
6
19
|
it('replaces variant="default" with color="gray"', () => {
|
|
7
20
|
const inputAst = parseJsx(`
|
|
8
21
|
import {Well} from "@kaizen/components"
|
|
@@ -12,12 +25,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
12
25
|
import {Well} from "@kaizen/components"
|
|
13
26
|
export const TestComponent = () => <Well color="gray">Test</Well>
|
|
14
27
|
`)
|
|
15
|
-
|
|
16
|
-
sourceFile: inputAst,
|
|
17
|
-
astTransformer: transformWellVariantToColor,
|
|
18
|
-
tagName: 'Well',
|
|
19
|
-
})
|
|
20
|
-
expect(transformed).toEqual(printAst(outputAst))
|
|
28
|
+
expect(transformWell(inputAst)).toEqual(printAst(outputAst))
|
|
21
29
|
})
|
|
22
30
|
|
|
23
31
|
it('replaces variant="informative" with color="blue"', () => {
|
|
@@ -29,12 +37,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
29
37
|
import {Well} from "@kaizen/components"
|
|
30
38
|
export const TestComponent = () => <Well color="blue">Test</Well>
|
|
31
39
|
`)
|
|
32
|
-
|
|
33
|
-
sourceFile: inputAst,
|
|
34
|
-
astTransformer: transformWellVariantToColor,
|
|
35
|
-
tagName: 'Well',
|
|
36
|
-
})
|
|
37
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
40
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
38
41
|
})
|
|
39
42
|
|
|
40
43
|
it('adds color="gray" if variant is not specified', () => {
|
|
@@ -46,12 +49,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
46
49
|
import {Well} from "@kaizen/components"
|
|
47
50
|
export const TestComponent = () => <Well color="gray">Test</Well>
|
|
48
51
|
`)
|
|
49
|
-
|
|
50
|
-
sourceFile: inputAst,
|
|
51
|
-
astTransformer: transformWellVariantToColor,
|
|
52
|
-
tagName: 'Well',
|
|
53
|
-
})
|
|
54
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
52
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
55
53
|
})
|
|
56
54
|
|
|
57
55
|
it('handles multiple attributes and replace only variant', () => {
|
|
@@ -63,12 +61,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
63
61
|
import {Well} from "@kaizen/components"
|
|
64
62
|
export const TestComponent = () => <Well color="blue" id="123">Test</Well>
|
|
65
63
|
`)
|
|
66
|
-
|
|
67
|
-
sourceFile: inputAst,
|
|
68
|
-
astTransformer: transformWellVariantToColor,
|
|
69
|
-
tagName: 'Well',
|
|
70
|
-
})
|
|
71
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
64
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
72
65
|
})
|
|
73
66
|
|
|
74
67
|
it('handles multiple attributes and add color if variant is not specified', () => {
|
|
@@ -80,12 +73,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
80
73
|
import {Well} from "@kaizen/components"
|
|
81
74
|
export const TestComponent = () => <Well id="123" color="gray">Test</Well>
|
|
82
75
|
`)
|
|
83
|
-
|
|
84
|
-
sourceFile: inputAst,
|
|
85
|
-
astTransformer: transformWellVariantToColor,
|
|
86
|
-
tagName: 'Well',
|
|
87
|
-
})
|
|
88
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
76
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
89
77
|
})
|
|
90
78
|
|
|
91
79
|
it('handles nested Well components', () => {
|
|
@@ -97,12 +85,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
97
85
|
import {Well} from "@kaizen/components"
|
|
98
86
|
export const TestComponent = () => <div><Well id="123" color="gray">Test</Well></div>
|
|
99
87
|
`)
|
|
100
|
-
|
|
101
|
-
sourceFile: inputAst,
|
|
102
|
-
astTransformer: transformWellVariantToColor,
|
|
103
|
-
tagName: 'Well',
|
|
104
|
-
})
|
|
105
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
88
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
106
89
|
})
|
|
107
90
|
|
|
108
91
|
it('transforms multiple Wells', () => {
|
|
@@ -114,12 +97,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
114
97
|
import {Well} from "@kaizen/components"
|
|
115
98
|
export const TestComponent = () => <div><Well color="blue">Test</Well><Well color="gray">Test 2</Well></div>
|
|
116
99
|
`)
|
|
117
|
-
|
|
118
|
-
sourceFile: inputAst,
|
|
119
|
-
astTransformer: transformWellVariantToColor,
|
|
120
|
-
tagName: 'Well',
|
|
121
|
-
})
|
|
122
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
100
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
123
101
|
})
|
|
124
102
|
|
|
125
103
|
it('transforms Well with arbitrary braces', () => {
|
|
@@ -131,12 +109,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
131
109
|
import {Well} from "@kaizen/components"
|
|
132
110
|
export const TestComponent = () => <div><Well color="blue">Test</Well><Well color="orange">Test</Well><Well color="green">Test</Well></div>
|
|
133
111
|
`)
|
|
134
|
-
|
|
135
|
-
sourceFile: inputAst,
|
|
136
|
-
astTransformer: transformWellVariantToColor,
|
|
137
|
-
tagName: 'Well',
|
|
138
|
-
})
|
|
139
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
112
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
140
113
|
})
|
|
141
114
|
|
|
142
115
|
it("won't add color if color already exists", () => {
|
|
@@ -148,12 +121,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
148
121
|
import {Well} from "@kaizen/components"
|
|
149
122
|
export const TestComponent = () => <div><Well color="blue">Test</Well></div>
|
|
150
123
|
`)
|
|
151
|
-
|
|
152
|
-
sourceFile: inputAst,
|
|
153
|
-
astTransformer: transformWellVariantToColor,
|
|
154
|
-
tagName: 'Well',
|
|
155
|
-
})
|
|
156
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
124
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
157
125
|
})
|
|
158
126
|
|
|
159
127
|
it("won't modify variants usings variables", () => {
|
|
@@ -165,12 +133,7 @@ describe('transformWellVariantToColor', () => {
|
|
|
165
133
|
import {Well} from "@kaizen/components"
|
|
166
134
|
export const TestComponent = () => <div><Well variant={wellVariable}>Test</Well></div>
|
|
167
135
|
`)
|
|
168
|
-
|
|
169
|
-
sourceFile: inputAst,
|
|
170
|
-
astTransformer: transformWellVariantToColor,
|
|
171
|
-
tagName: 'Well',
|
|
172
|
-
})
|
|
173
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
136
|
+
expect(transformWell(inputAst)).toBe(printAst(outputAst))
|
|
174
137
|
})
|
|
175
138
|
|
|
176
139
|
it('transforms aliased Well components', () => {
|
|
@@ -182,11 +145,6 @@ describe('transformWellVariantToColor', () => {
|
|
|
182
145
|
import {Well as KaizenWell} from "@kaizen/components"
|
|
183
146
|
export const TestComponent = () => <div><KaizenWell color="blue">Test</KaizenWell></div>
|
|
184
147
|
`)
|
|
185
|
-
|
|
186
|
-
sourceFile: inputAst,
|
|
187
|
-
astTransformer: transformWellVariantToColor,
|
|
188
|
-
tagName: 'KaizenWell',
|
|
189
|
-
})
|
|
190
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
148
|
+
expect(transformWell(inputAst)).toEqual(printAst(outputAst))
|
|
191
149
|
})
|
|
192
150
|
})
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import ts from 'typescript'
|
|
2
|
-
import { updateJsxElementWithNewProps } from '../utils'
|
|
2
|
+
import { updateJsxElementWithNewProps, type TagImportAttributesMap } from '../utils'
|
|
3
3
|
import { getPropValueText } from '../utils/getPropValueText'
|
|
4
4
|
|
|
5
5
|
export const transformWellVariantToColor =
|
|
6
|
-
(
|
|
7
|
-
(
|
|
6
|
+
(tagsMap: TagImportAttributesMap): ts.TransformerFactory<ts.SourceFile> =>
|
|
7
|
+
(context) =>
|
|
8
|
+
(rootNode) => {
|
|
8
9
|
function visit(node: ts.Node): ts.Node {
|
|
9
10
|
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
10
|
-
|
|
11
|
+
const tagName = node.tagName.getText()
|
|
12
|
+
const tagImportAttributes = tagsMap.get(tagName)
|
|
13
|
+
|
|
14
|
+
if (!tagImportAttributes) return node
|
|
15
|
+
|
|
16
|
+
if (node.tagName.getText() === tagImportAttributes.tagName) {
|
|
11
17
|
let hasVariant = false
|
|
12
18
|
let hasColor = false
|
|
13
19
|
let newAttributes = node.attributes.properties.map((attr) => {
|
|
@@ -8,7 +8,9 @@ const run = (): void => {
|
|
|
8
8
|
process.exit(1)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
transformComponentsInDir(targetDir,
|
|
11
|
+
transformComponentsInDir(targetDir, ['InputEditModal'], (tagNames) => [
|
|
12
|
+
removeInputEditModalMood(tagNames),
|
|
13
|
+
])
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
run()
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import { parseJsx } from '../__tests__/utils'
|
|
2
|
-
import { printAst,
|
|
2
|
+
import { printAst, transformSource, type TransformSourceArgs } from '../utils'
|
|
3
3
|
import { removeInputEditModalMood } from './removeInputEditModalMood'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const transformInputEditModal = (sourceFile: TransformSourceArgs['sourceFile']): string => {
|
|
6
|
+
const tagsMap = new Map([
|
|
7
|
+
[
|
|
8
|
+
'InputEditModal',
|
|
9
|
+
{
|
|
10
|
+
importModuleName: '@kaizen/components',
|
|
11
|
+
tagName: 'InputEditModal',
|
|
12
|
+
originalName: 'InputEditModal',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
return transformSource({
|
|
18
|
+
sourceFile,
|
|
19
|
+
transformers: [removeInputEditModalMood(tagsMap)],
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('removeInputEditModalMood()', () => {
|
|
6
24
|
it('removes mood', () => {
|
|
7
25
|
const inputAst = parseJsx(`
|
|
8
26
|
export const TestComponent = () => <InputEditModal mood="positive"/>
|
|
@@ -10,12 +28,7 @@ describe('removeInputEditModalMood', () => {
|
|
|
10
28
|
const outputAst = parseJsx(`
|
|
11
29
|
export const TestComponent = () => <InputEditModal />
|
|
12
30
|
`)
|
|
13
|
-
|
|
14
|
-
sourceFile: inputAst,
|
|
15
|
-
astTransformer: removeInputEditModalMood,
|
|
16
|
-
tagName: 'InputEditModal',
|
|
17
|
-
})
|
|
18
|
-
expect(transformed).toEqual(printAst(outputAst))
|
|
31
|
+
expect(transformInputEditModal(inputAst)).toEqual(printAst(outputAst))
|
|
19
32
|
})
|
|
20
33
|
|
|
21
34
|
it('handles multiple attributes and remove only mood', () => {
|
|
@@ -25,12 +38,7 @@ describe('removeInputEditModalMood', () => {
|
|
|
25
38
|
const outputAst = parseJsx(`
|
|
26
39
|
export const TestComponent = () => <InputEditModal id="123"/>
|
|
27
40
|
`)
|
|
28
|
-
|
|
29
|
-
sourceFile: inputAst,
|
|
30
|
-
astTransformer: removeInputEditModalMood,
|
|
31
|
-
tagName: 'InputEditModal',
|
|
32
|
-
})
|
|
33
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
41
|
+
expect(transformInputEditModal(inputAst)).toBe(printAst(outputAst))
|
|
34
42
|
})
|
|
35
43
|
|
|
36
44
|
it('transforms multiple InputEditModals', () => {
|
|
@@ -40,11 +48,6 @@ describe('removeInputEditModalMood', () => {
|
|
|
40
48
|
const outputAst = parseJsx(`
|
|
41
49
|
export const TestComponent = () => <div><InputEditModal /><InputEditModal /></div>
|
|
42
50
|
`)
|
|
43
|
-
|
|
44
|
-
sourceFile: inputAst,
|
|
45
|
-
astTransformer: removeInputEditModalMood,
|
|
46
|
-
tagName: 'InputEditModal',
|
|
47
|
-
})
|
|
48
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
51
|
+
expect(transformInputEditModal(inputAst)).toBe(printAst(outputAst))
|
|
49
52
|
})
|
|
50
53
|
})
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { parseJsx } from '../__tests__/utils'
|
|
2
|
-
import { printAst,
|
|
2
|
+
import { printAst, transformSource, type TransformSourceArgs } from '../utils'
|
|
3
3
|
import { removePopoverVariant } from './removePopoverVariant'
|
|
4
4
|
|
|
5
|
+
const transformPopover = (sourceFile: TransformSourceArgs['sourceFile']): string => {
|
|
6
|
+
const tagsMap = new Map([
|
|
7
|
+
[
|
|
8
|
+
'Popover',
|
|
9
|
+
{
|
|
10
|
+
importModuleName: '@kaizen/components',
|
|
11
|
+
tagName: 'Popover',
|
|
12
|
+
originalName: 'Popover',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
return transformSource({
|
|
18
|
+
sourceFile,
|
|
19
|
+
transformers: [removePopoverVariant(tagsMap)],
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
describe('removePopoverVariant()', () => {
|
|
6
24
|
it('removes variant', () => {
|
|
7
25
|
const inputAst = parseJsx(`
|
|
@@ -10,12 +28,7 @@ describe('removePopoverVariant()', () => {
|
|
|
10
28
|
const outputAst = parseJsx(`
|
|
11
29
|
export const TestComponent = () => <Popover />
|
|
12
30
|
`)
|
|
13
|
-
|
|
14
|
-
sourceFile: inputAst,
|
|
15
|
-
astTransformer: removePopoverVariant,
|
|
16
|
-
tagName: 'Popover',
|
|
17
|
-
})
|
|
18
|
-
expect(transformed).toEqual(printAst(outputAst))
|
|
31
|
+
expect(transformPopover(inputAst)).toEqual(printAst(outputAst))
|
|
19
32
|
})
|
|
20
33
|
|
|
21
34
|
it('removes customIcon', () => {
|
|
@@ -25,12 +38,7 @@ describe('removePopoverVariant()', () => {
|
|
|
25
38
|
const outputAst = parseJsx(`
|
|
26
39
|
export const TestComponent = () => <Popover />
|
|
27
40
|
`)
|
|
28
|
-
|
|
29
|
-
sourceFile: inputAst,
|
|
30
|
-
astTransformer: removePopoverVariant,
|
|
31
|
-
tagName: 'Popover',
|
|
32
|
-
})
|
|
33
|
-
expect(transformed).toEqual(printAst(outputAst))
|
|
41
|
+
expect(transformPopover(inputAst)).toEqual(printAst(outputAst))
|
|
34
42
|
})
|
|
35
43
|
|
|
36
44
|
it('handles multiple attributes and remove only variant', () => {
|
|
@@ -40,12 +48,7 @@ describe('removePopoverVariant()', () => {
|
|
|
40
48
|
const outputAst = parseJsx(`
|
|
41
49
|
export const TestComponent = () => <Popover id="123"/>
|
|
42
50
|
`)
|
|
43
|
-
|
|
44
|
-
sourceFile: inputAst,
|
|
45
|
-
astTransformer: removePopoverVariant,
|
|
46
|
-
tagName: 'Popover',
|
|
47
|
-
})
|
|
48
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
51
|
+
expect(transformPopover(inputAst)).toBe(printAst(outputAst))
|
|
49
52
|
})
|
|
50
53
|
|
|
51
54
|
it('transforms multiple Popovers', () => {
|
|
@@ -55,11 +58,6 @@ describe('removePopoverVariant()', () => {
|
|
|
55
58
|
const outputAst = parseJsx(`
|
|
56
59
|
export const TestComponent = () => <div><Popover /><Popover /></div>
|
|
57
60
|
`)
|
|
58
|
-
|
|
59
|
-
sourceFile: inputAst,
|
|
60
|
-
astTransformer: removePopoverVariant,
|
|
61
|
-
tagName: 'Popover',
|
|
62
|
-
})
|
|
63
|
-
expect(transformed).toBe(printAst(outputAst))
|
|
61
|
+
expect(transformPopover(inputAst)).toBe(printAst(outputAst))
|
|
64
62
|
})
|
|
65
63
|
})
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getKaioTagNamesByRegex, transformSource, traverseDir } from '../utils'
|
|
3
|
-
import { createEncodedSourceFile } from '../utils/createEncodedSourceFile'
|
|
1
|
+
import { transformComponentsInDirByPattern } from '../utils'
|
|
4
2
|
import { upgradeIconV1 } from './upgradeIconV1'
|
|
5
3
|
|
|
6
4
|
const run = (): void => {
|
|
@@ -11,20 +9,7 @@ const run = (): void => {
|
|
|
11
9
|
process.exit(1)
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
const sourceFile = createEncodedSourceFile(componentFilePath, sourceCode)
|
|
16
|
-
const tagNames = getKaioTagNamesByRegex(sourceFile, 'Icon$')
|
|
17
|
-
if (tagNames) {
|
|
18
|
-
const updatedSourceFile = transformSource({
|
|
19
|
-
sourceFile,
|
|
20
|
-
transformers: [upgradeIconV1(tagNames)],
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
fs.writeFileSync(componentFilePath, updatedSourceFile, 'utf8')
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
traverseDir(targetDir, transformFile)
|
|
12
|
+
transformComponentsInDirByPattern(targetDir, 'Icon$', (tagNames) => [upgradeIconV1(tagNames)])
|
|
28
13
|
}
|
|
29
14
|
|
|
30
15
|
run()
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { parseJsx } from '../__tests__/utils'
|
|
2
2
|
import {
|
|
3
|
+
getKaioTagNamesMapByPattern,
|
|
3
4
|
printAst,
|
|
4
5
|
transformSource,
|
|
5
|
-
type ImportModuleNameTagsMap,
|
|
6
6
|
type TransformSourceArgs,
|
|
7
7
|
} from '../utils'
|
|
8
8
|
import { upgradeIconV1 } from './upgradeIconV1'
|
|
9
9
|
|
|
10
|
-
const transformIcons = (
|
|
11
|
-
sourceFile
|
|
12
|
-
|
|
13
|
-
): string =>
|
|
14
|
-
transformSource({
|
|
10
|
+
const transformIcons = (sourceFile: TransformSourceArgs['sourceFile']): string => {
|
|
11
|
+
const kaioTagNamesMap = getKaioTagNamesMapByPattern(sourceFile, 'Icon$')
|
|
12
|
+
return transformSource({
|
|
15
13
|
sourceFile,
|
|
16
|
-
transformers: [upgradeIconV1(
|
|
14
|
+
transformers: [upgradeIconV1(kaioTagNamesMap!)],
|
|
17
15
|
})
|
|
16
|
+
}
|
|
18
17
|
|
|
19
18
|
describe('upgradeIconV1()', () => {
|
|
20
19
|
describe('CaMonogramIcon to Brand', () => {
|
|
@@ -29,12 +28,7 @@ describe('upgradeIconV1()', () => {
|
|
|
29
28
|
import { Brand } from "@kaizen/components"
|
|
30
29
|
export const TestComponent = () => <Brand ${transformedBrandProps} />
|
|
31
30
|
`)
|
|
32
|
-
expect(
|
|
33
|
-
transformIcons(
|
|
34
|
-
inputAst,
|
|
35
|
-
new Map([['@kaizen/components', new Map([['CaMonogramIcon', 'CaMonogramIcon']])]]),
|
|
36
|
-
),
|
|
37
|
-
).toEqual(printAst(outputAst))
|
|
31
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
38
32
|
})
|
|
39
33
|
|
|
40
34
|
it('updates import from CaMonogramIcon using alias to Brand', () => {
|
|
@@ -46,12 +40,7 @@ describe('upgradeIconV1()', () => {
|
|
|
46
40
|
import { Brand } from "@kaizen/components"
|
|
47
41
|
export const TestComponent = () => <Brand ${transformedBrandProps} />
|
|
48
42
|
`)
|
|
49
|
-
expect(
|
|
50
|
-
transformIcons(
|
|
51
|
-
inputAst,
|
|
52
|
-
new Map([['@kaizen/components', new Map([['LogoAlias', 'CaMonogramIcon']])]]),
|
|
53
|
-
),
|
|
54
|
-
).toEqual(printAst(outputAst))
|
|
43
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
55
44
|
})
|
|
56
45
|
|
|
57
46
|
it('does not add another Brand import if it is already imported', () => {
|
|
@@ -63,20 +52,7 @@ describe('upgradeIconV1()', () => {
|
|
|
63
52
|
import { Brand } from "@kaizen/components"
|
|
64
53
|
export const TestComponent = () => <Brand ${transformedBrandProps} />
|
|
65
54
|
`)
|
|
66
|
-
expect(
|
|
67
|
-
transformIcons(
|
|
68
|
-
inputAst,
|
|
69
|
-
new Map([
|
|
70
|
-
[
|
|
71
|
-
'@kaizen/components',
|
|
72
|
-
new Map([
|
|
73
|
-
['Brand', 'Brand'],
|
|
74
|
-
['CaMonogramIcon', 'CaMonogramIcon'],
|
|
75
|
-
]),
|
|
76
|
-
],
|
|
77
|
-
]),
|
|
78
|
-
),
|
|
79
|
-
).toEqual(printAst(outputAst))
|
|
55
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
80
56
|
})
|
|
81
57
|
|
|
82
58
|
it('uses Brand alias for an existing import', () => {
|
|
@@ -88,20 +64,7 @@ describe('upgradeIconV1()', () => {
|
|
|
88
64
|
import { Brand as KzBrand } from "@kaizen/components"
|
|
89
65
|
export const TestComponent = () => <KzBrand ${transformedBrandProps} />
|
|
90
66
|
`)
|
|
91
|
-
expect(
|
|
92
|
-
transformIcons(
|
|
93
|
-
inputAst,
|
|
94
|
-
new Map([
|
|
95
|
-
[
|
|
96
|
-
'@kaizen/components',
|
|
97
|
-
new Map([
|
|
98
|
-
['KzBrand', 'Brand'],
|
|
99
|
-
['CaMonogramIcon', 'CaMonogramIcon'],
|
|
100
|
-
]),
|
|
101
|
-
],
|
|
102
|
-
]),
|
|
103
|
-
),
|
|
104
|
-
).toEqual(printAst(outputAst))
|
|
67
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
105
68
|
})
|
|
106
69
|
})
|
|
107
70
|
|
|
@@ -117,12 +80,7 @@ describe('upgradeIconV1()', () => {
|
|
|
117
80
|
import { LoadingSpinner } from "@kaizen/components"
|
|
118
81
|
export const TestComponent = () => <LoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
119
82
|
`)
|
|
120
|
-
expect(
|
|
121
|
-
transformIcons(
|
|
122
|
-
inputAst,
|
|
123
|
-
new Map([['@kaizen/components', new Map([['SpinnerIcon', 'SpinnerIcon']])]]),
|
|
124
|
-
),
|
|
125
|
-
).toEqual(printAst(outputAst))
|
|
83
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
126
84
|
})
|
|
127
85
|
|
|
128
86
|
it('updates import from SpinnerIcon using alias to LoadingSpinner', () => {
|
|
@@ -134,12 +92,7 @@ describe('upgradeIconV1()', () => {
|
|
|
134
92
|
import { LoadingSpinner } from "@kaizen/components"
|
|
135
93
|
export const TestComponent = () => <LoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
136
94
|
`)
|
|
137
|
-
expect(
|
|
138
|
-
transformIcons(
|
|
139
|
-
inputAst,
|
|
140
|
-
new Map([['@kaizen/components', new Map([['LogoAlias', 'SpinnerIcon']])]]),
|
|
141
|
-
),
|
|
142
|
-
).toEqual(printAst(outputAst))
|
|
95
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
143
96
|
})
|
|
144
97
|
|
|
145
98
|
it('does not add another LoadingSpinner import if it is already imported', () => {
|
|
@@ -151,20 +104,7 @@ describe('upgradeIconV1()', () => {
|
|
|
151
104
|
import { LoadingSpinner } from "@kaizen/components"
|
|
152
105
|
export const TestComponent = () => <LoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
153
106
|
`)
|
|
154
|
-
expect(
|
|
155
|
-
transformIcons(
|
|
156
|
-
inputAst,
|
|
157
|
-
new Map([
|
|
158
|
-
[
|
|
159
|
-
'@kaizen/components',
|
|
160
|
-
new Map([
|
|
161
|
-
['LoadingSpinner', 'LoadingSpinner'],
|
|
162
|
-
['SpinnerIcon', 'SpinnerIcon'],
|
|
163
|
-
]),
|
|
164
|
-
],
|
|
165
|
-
]),
|
|
166
|
-
),
|
|
167
|
-
).toEqual(printAst(outputAst))
|
|
107
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
168
108
|
})
|
|
169
109
|
|
|
170
110
|
it('uses LoadingSpinner alias for an existing import', () => {
|
|
@@ -176,20 +116,7 @@ describe('upgradeIconV1()', () => {
|
|
|
176
116
|
import { LoadingSpinner as KzLoadingSpinner } from "@kaizen/components"
|
|
177
117
|
export const TestComponent = () => <KzLoadingSpinner ${transformedLoadingSpinnerProps} />
|
|
178
118
|
`)
|
|
179
|
-
expect(
|
|
180
|
-
transformIcons(
|
|
181
|
-
inputAst,
|
|
182
|
-
new Map([
|
|
183
|
-
[
|
|
184
|
-
'@kaizen/components',
|
|
185
|
-
new Map([
|
|
186
|
-
['KzLoadingSpinner', 'LoadingSpinner'],
|
|
187
|
-
['SpinnerIcon', 'SpinnerIcon'],
|
|
188
|
-
]),
|
|
189
|
-
],
|
|
190
|
-
]),
|
|
191
|
-
),
|
|
192
|
-
).toEqual(printAst(outputAst))
|
|
119
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
193
120
|
})
|
|
194
121
|
})
|
|
195
122
|
|
|
@@ -202,12 +129,7 @@ describe('upgradeIconV1()', () => {
|
|
|
202
129
|
import { Icon } from "@kaizen/components/future"
|
|
203
130
|
export const TestComponent = () => <Icon name="flag" isFilled />
|
|
204
131
|
`)
|
|
205
|
-
expect(
|
|
206
|
-
transformIcons(
|
|
207
|
-
inputAst,
|
|
208
|
-
new Map([['@kaizen/components', new Map([['FlagOnIcon', 'FlagOnIcon']])]]),
|
|
209
|
-
),
|
|
210
|
-
).toEqual(printAst(outputAst))
|
|
132
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
211
133
|
})
|
|
212
134
|
|
|
213
135
|
it('transforms aliased old Icon', () => {
|
|
@@ -219,12 +141,7 @@ describe('upgradeIconV1()', () => {
|
|
|
219
141
|
import { Icon } from "@kaizen/components/future"
|
|
220
142
|
export const TestComponent = () => <Icon name="menu" />
|
|
221
143
|
`)
|
|
222
|
-
expect(
|
|
223
|
-
transformIcons(
|
|
224
|
-
inputAst,
|
|
225
|
-
new Map([['@kaizen/components', new Map([['IconAlias', 'HamburgerIcon']])]]),
|
|
226
|
-
),
|
|
227
|
-
).toEqual(printAst(outputAst))
|
|
144
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
228
145
|
})
|
|
229
146
|
|
|
230
147
|
describe('import statements', () => {
|
|
@@ -238,12 +155,7 @@ describe('upgradeIconV1()', () => {
|
|
|
238
155
|
import { Icon } from "@kaizen/components/future"
|
|
239
156
|
export const TestComponent = () => <Card><Icon name="add" /></Card>
|
|
240
157
|
`)
|
|
241
|
-
expect(
|
|
242
|
-
transformIcons(
|
|
243
|
-
inputAst,
|
|
244
|
-
new Map([['@kaizen/components', new Map([['AddIcon', 'AddIcon']])]]),
|
|
245
|
-
),
|
|
246
|
-
).toEqual(printAst(outputAst))
|
|
158
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
247
159
|
})
|
|
248
160
|
|
|
249
161
|
it('does not update import of components which are not from KAIO', () => {
|
|
@@ -269,21 +181,7 @@ describe('upgradeIconV1()', () => {
|
|
|
269
181
|
</>
|
|
270
182
|
)
|
|
271
183
|
`)
|
|
272
|
-
expect(
|
|
273
|
-
transformIcons(
|
|
274
|
-
inputAst,
|
|
275
|
-
new Map([
|
|
276
|
-
[
|
|
277
|
-
'@kaizen/components',
|
|
278
|
-
new Map([
|
|
279
|
-
['AddIcon', 'AddIcon'],
|
|
280
|
-
['IconAlias', 'HamburgerIcon'],
|
|
281
|
-
]),
|
|
282
|
-
],
|
|
283
|
-
['somewhere-else', new Map([['HamHam', 'HamburgerIcon']])],
|
|
284
|
-
]),
|
|
285
|
-
),
|
|
286
|
-
).toEqual(printAst(outputAst))
|
|
184
|
+
expect(transformIcons(inputAst)).toEqual(printAst(outputAst))
|
|
287
185
|
})
|
|
288
186
|
})
|
|
289
187
|
})
|