@kaizen/components 1.80.5 ā 1.80.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/codemods/README.md +6 -0
- package/codemods/migrateV2NextToCurrent/migrateV2NextToCurrent.spec.ts +7 -5
- package/codemods/migrateV2NextToCurrent/migrateV2NextToCurrent.ts +2 -2
- package/codemods/runV1Codemods/README.md +75 -0
- package/codemods/runV1Codemods/__fixtures__/MockComponentDir/MockComponent.tsx +48 -0
- package/codemods/runV1Codemods/__fixtures__/MockComponentDir/index.ts +1 -0
- package/codemods/runV1Codemods/__fixtures__/MockComponentDir/subcomponents/MockSubcomponent.tsx +12 -0
- package/codemods/runV1Codemods/__fixtures__/MockFailedComponentDir/MockComponent.tsx +13 -0
- package/codemods/runV1Codemods/__fixtures__/MockFailedComponentDir/index.ts +1 -0
- package/codemods/runV1Codemods/__snapshots__/runV1Codemods.spec.ts.snap +56 -0
- package/codemods/runV1Codemods/index.ts +41 -0
- package/codemods/runV1Codemods/runV1Codemods.spec.ts +107 -0
- package/codemods/runV1Codemods/runV1Codemods.ts +187 -0
- package/dist/styles.css +20 -20
- package/package.json +1 -1
package/codemods/README.md
CHANGED
|
@@ -25,6 +25,12 @@ pnpm kaizen-codemod src migrateWellVariantToColor
|
|
|
25
25
|
|
|
26
26
|
## Available codemods
|
|
27
27
|
|
|
28
|
+
Released in `1.80.6`
|
|
29
|
+
|
|
30
|
+
### `runV1Codemods`
|
|
31
|
+
|
|
32
|
+
A script that runs all v1 codemods in an ideal sequence. This should be used prior to the V2 upgrade - see the [README](./runV1Codemods/README.md) for more.
|
|
33
|
+
|
|
28
34
|
### `migrateV2NextToCurrent`
|
|
29
35
|
|
|
30
36
|
Released in `1.80.4`
|
|
@@ -500,7 +500,7 @@ import type { Menu as KZMenu, MenuItem as KZMenuItem } from "@kaizen/components"
|
|
|
500
500
|
describe('Module path transformations', () => {
|
|
501
501
|
it('should transform react-aria module path', () => {
|
|
502
502
|
const inputAst = parseJsx(`import { Button } from "@kaizen/components/v3/react-aria"`)
|
|
503
|
-
const expectedAst = parseJsx(`import { Button } from "@kaizen/components/react-aria"`)
|
|
503
|
+
const expectedAst = parseJsx(`import { Button } from "@kaizen/components/libs/react-aria"`)
|
|
504
504
|
|
|
505
505
|
const result = transformComponents(inputAst)
|
|
506
506
|
expect(result).toBe(printAst(expectedAst))
|
|
@@ -511,7 +511,7 @@ import type { Menu as KZMenu, MenuItem as KZMenuItem } from "@kaizen/components"
|
|
|
511
511
|
`import { TextField } from "@kaizen/components/v3/react-aria-components"`,
|
|
512
512
|
)
|
|
513
513
|
const expectedAst = parseJsx(
|
|
514
|
-
`import { TextField } from "@kaizen/components/react-aria-components"`,
|
|
514
|
+
`import { TextField } from "@kaizen/components/libs/react-aria-components"`,
|
|
515
515
|
)
|
|
516
516
|
|
|
517
517
|
const result = transformComponents(inputAst)
|
|
@@ -520,7 +520,9 @@ import type { Menu as KZMenu, MenuItem as KZMenuItem } from "@kaizen/components"
|
|
|
520
520
|
|
|
521
521
|
it('should handle multiple imports from react-aria modules', () => {
|
|
522
522
|
const inputAst = parseJsx(`import { Button, Link } from "@kaizen/components/v3/react-aria"`)
|
|
523
|
-
const expectedAst = parseJsx(
|
|
523
|
+
const expectedAst = parseJsx(
|
|
524
|
+
`import { Button, Link } from "@kaizen/components/libs/react-aria"`,
|
|
525
|
+
)
|
|
524
526
|
|
|
525
527
|
const result = transformComponents(inputAst)
|
|
526
528
|
expect(result).toBe(printAst(expectedAst))
|
|
@@ -531,7 +533,7 @@ import type { Menu as KZMenu, MenuItem as KZMenuItem } from "@kaizen/components"
|
|
|
531
533
|
`import { Button as AriaButton } from "@kaizen/components/v3/react-aria"`,
|
|
532
534
|
)
|
|
533
535
|
const expectedAst = parseJsx(
|
|
534
|
-
`import { Button as AriaButton } from "@kaizen/components/react-aria"`,
|
|
536
|
+
`import { Button as AriaButton } from "@kaizen/components/libs/react-aria"`,
|
|
535
537
|
)
|
|
536
538
|
|
|
537
539
|
const result = transformComponents(inputAst)
|
|
@@ -545,7 +547,7 @@ import { Button } from "@kaizen/components/v3/react-aria"
|
|
|
545
547
|
`)
|
|
546
548
|
const expectedAst = parseJsx(`
|
|
547
549
|
import { Menu } from "@kaizen/components"
|
|
548
|
-
import { Button } from "@kaizen/components/react-aria"
|
|
550
|
+
import { Button } from "@kaizen/components/libs/react-aria"
|
|
549
551
|
`)
|
|
550
552
|
|
|
551
553
|
const result = transformComponents(inputAst)
|
|
@@ -49,8 +49,8 @@ const componentGroups: ComponentGroup[] = [
|
|
|
49
49
|
const renameMap = createRenameMapFromGroups(componentGroups)
|
|
50
50
|
|
|
51
51
|
const modulePathMap = new Map([
|
|
52
|
-
['@kaizen/components/v3/react-aria', '@kaizen/components/react-aria'],
|
|
53
|
-
['@kaizen/components/v3/react-aria-components', '@kaizen/components/react-aria-components'],
|
|
52
|
+
['@kaizen/components/v3/react-aria', '@kaizen/components/libs/react-aria'],
|
|
53
|
+
['@kaizen/components/v3/react-aria-components', '@kaizen/components/libs/react-aria-components'],
|
|
54
54
|
])
|
|
55
55
|
|
|
56
56
|
export const migrateV2NextToCurrent =
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# runV1Codemods
|
|
2
|
+
|
|
3
|
+
A comprehensive codemod that runs all V1 migration codemods in the ideal sequence.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This codemod executes all 17 V1 migration codemods in the order as pre-work to migrate to `kaizen/component@2.0.0` Kaizen components. After this you will still need to run the `migrateV2NextToCurrent` and `renameV2ComponentImportsAndUsages` after upgrading to `kaizen/component@2.0.0`
|
|
8
|
+
|
|
9
|
+
This codemod runner handles the following:
|
|
10
|
+
|
|
11
|
+
- Icon upgrades (`upgradeIconV1`)
|
|
12
|
+
- Button migrations (`upgradeV1Buttons`)
|
|
13
|
+
- GuidanceBlock actions migration (`migrateGuidanceBlockActionsToActionsSlot`)
|
|
14
|
+
- Mood to variant migrations for multiple components
|
|
15
|
+
- Variant to color migrations
|
|
16
|
+
- Type to variant migrations for notifications
|
|
17
|
+
- Removal of deprecated props
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm kaizen-codemod {target-directory} runV1Codemods
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Example
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm kaizen-codemod src/components/MockComponent runV1Codemods
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## What it does
|
|
32
|
+
|
|
33
|
+
The codemod runs the following transformations in sequence:
|
|
34
|
+
|
|
35
|
+
1. **upgradeIconV1** - Migrates V1 Icon components to next Icon
|
|
36
|
+
2. **upgradeV1Buttons** - Migrates V1 Button and IconButton to next Button/LinkButton
|
|
37
|
+
3. **migrateGuidanceBlockActionsToActionsSlot** - Migrates GuidanceBlock actions prop to actionsSlot
|
|
38
|
+
4. **migrateBrandMomentMoodToVariant** - Changes `mood` prop to `variant` on BrandMoment
|
|
39
|
+
5. **migrateCardVariantToColor** - Changes `variant` prop to `color` on Card
|
|
40
|
+
6. **migrateConfirmationModalMoodsToVariant** - Changes `mood` prop to `variant` on ConfirmationModal
|
|
41
|
+
7. **migrateEmptyStateIllustrationTypeToVariant** - Changes `illustrationType` prop to `variant` on EmptyState
|
|
42
|
+
8. **migrateGlobalNotificationTypeToVariant** - Changes `type` prop to `variant` on GlobalNotification
|
|
43
|
+
9. **migrateInformationTileMoodToVariant** - Changes `mood` prop to `variant` on InformationTile
|
|
44
|
+
10. **migrateInlineNotificationTypeToVariant** - Changes `type` prop to `variant` on InlineNotification
|
|
45
|
+
11. **migrateMultiActionTileMoodToVariant** - Changes `mood` prop to `variant` on MultiActionTile
|
|
46
|
+
12. **migrateNotificationTypeToVariant** - Changes `type` prop to `variant` on Notification
|
|
47
|
+
13. **migrateProgressBarMoodToColor** - Changes `mood` prop to `color` on ProgressBar
|
|
48
|
+
14. **migrateToastNotificationTypeToVariant** - Changes `type` prop to `variant` on ToastNotification
|
|
49
|
+
15. **migrateWellVariantToColor** - Changes `variant` prop to `color` on Well
|
|
50
|
+
16. **removeInputEditModalMood** - Removes deprecated `mood` prop from InputEditModal
|
|
51
|
+
17. **removePopoverVariant** - Removes deprecated `variant` and `customIcon` props from Popover
|
|
52
|
+
|
|
53
|
+
## Error Handling
|
|
54
|
+
|
|
55
|
+
- If any individual codemod fails, the process continues with the remaining codemods
|
|
56
|
+
- Detailed logging shows the start and completion status of each codemod
|
|
57
|
+
- A summary is provided at the end showing successful vs failed codemods
|
|
58
|
+
|
|
59
|
+
## Cautions and caveats
|
|
60
|
+
|
|
61
|
+
### Reducing the blast radius of the codemods
|
|
62
|
+
|
|
63
|
+
This running will create a lot of diffs and changes to your components as the traverses the entire directory given.
|
|
64
|
+
|
|
65
|
+
To reduce the scope, consider either running this on component or page directories or running the mode incrementally, ie:
|
|
66
|
+
|
|
67
|
+
`pnpm kaizen-codemod src/pages/MockPage runV1Codemods`
|
|
68
|
+
|
|
69
|
+
This can make it easier to review and merge in changes with confidence.
|
|
70
|
+
|
|
71
|
+
### Prettier diffs
|
|
72
|
+
|
|
73
|
+
As the codemod will rewrites files, this can cause arbitrary changes that will be resolved by `prettier` formatting. We recommend running the following to reduce the noise in your diffs:
|
|
74
|
+
|
|
75
|
+
`pnpm prettier --write "**/*.tsx"`
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @ts-nocheck this is a mock file - we can ignore this
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import {
|
|
4
|
+
BrandMoment,
|
|
5
|
+
Card,
|
|
6
|
+
GlobalNotification,
|
|
7
|
+
GuidanceBlock,
|
|
8
|
+
Informative,
|
|
9
|
+
ProgressBar,
|
|
10
|
+
Well,
|
|
11
|
+
} from '@kaizen/components'
|
|
12
|
+
import { MockSubcomponent } from './subcomponents/MockSubcomponent'
|
|
13
|
+
|
|
14
|
+
export const MockComponent = (): JSX.Element => {
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<GuidanceBlock
|
|
18
|
+
illustration={<Informative alt="" />}
|
|
19
|
+
text={{
|
|
20
|
+
title: 'This is the call to action title',
|
|
21
|
+
description:
|
|
22
|
+
'Mussum Ipsum, cacilds vidis litro abertis. Suco de cevadiss, Ć© um leite divinis.',
|
|
23
|
+
}}
|
|
24
|
+
actions={{
|
|
25
|
+
primary: { label: 'Action!', onClick: () => undefined },
|
|
26
|
+
secondary: { label: 'Cancel', href: '/cancel' },
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
<BrandMoment mood="positive">
|
|
30
|
+
<div>Success message</div>
|
|
31
|
+
</BrandMoment>
|
|
32
|
+
<Card variant="informative">
|
|
33
|
+
<div>Card content</div>
|
|
34
|
+
</Card>
|
|
35
|
+
<ProgressBar mood="positive" value={75} />
|
|
36
|
+
<Well variant="default">
|
|
37
|
+
<div>Well content</div>
|
|
38
|
+
</Well>
|
|
39
|
+
<GlobalNotification persistent={true} type="positive">
|
|
40
|
+
Global notification content
|
|
41
|
+
</GlobalNotification>
|
|
42
|
+
<div className="additional-content">
|
|
43
|
+
This is some additional content that is not part of the GuidanceBlock.
|
|
44
|
+
<MockSubcomponent />
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './'
|
package/codemods/runV1Codemods/__fixtures__/MockComponentDir/subcomponents/MockSubcomponent.tsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
// @ts-ignore This is a mock component to test codemods
|
|
3
|
+
import { Button } from '@kaizen/components'
|
|
4
|
+
|
|
5
|
+
export const MockSubcomponent = (): JSX.Element => {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<Button label="Mock Subcomponent Button" onClick={() => undefined} />
|
|
9
|
+
<Button label="Mock Subcomponent Link" href="#link" />
|
|
10
|
+
</div>
|
|
11
|
+
)
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-nocheck this is a mock file - we can ignore this
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { GlobalNotification } from '@kaizen/components'
|
|
4
|
+
|
|
5
|
+
export const MockComponent = (): JSX.Element => {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<GlobalNotification persistent={true} type="success">
|
|
9
|
+
Global notification content
|
|
10
|
+
</GlobalNotification>
|
|
11
|
+
</div>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './'
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`runV1Codemods > MockComponentDir Snapshot Tests > should transform MockComponentDir files and match snapshot 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"MockComponent.tsx": "// @ts-nocheck this is a mock file - we can ignore this
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { BrandMoment, Card, GlobalNotification, GuidanceBlock, Informative, ProgressBar, Well, LinkButton } from '@kaizen/components';
|
|
8
|
+
import { Button } from "@kaizen/components/next";
|
|
9
|
+
import { MockSubcomponent } from './subcomponents/MockSubcomponent';
|
|
10
|
+
|
|
11
|
+
export const MockComponent = (): JSX.Element => {
|
|
12
|
+
return (<div>
|
|
13
|
+
<GuidanceBlock illustration={<Informative alt=""/>} text={{
|
|
14
|
+
title: 'This is the call to action title',
|
|
15
|
+
description: 'Mussum Ipsum, cacilds vidis litro abertis. Suco de cevadiss, Ć© um leite divinis.',
|
|
16
|
+
}} actionsSlot={<><Button onPress={() => undefined} variant="secondary" size="large">Action!</Button><LinkButton href='/cancel' variant="tertiary" size="large">Cancel</LinkButton></>}/>
|
|
17
|
+
<BrandMoment variant="success">
|
|
18
|
+
<div>Success message</div>
|
|
19
|
+
</BrandMoment>
|
|
20
|
+
<Card color="blue">
|
|
21
|
+
<div>Card content</div>
|
|
22
|
+
</Card>
|
|
23
|
+
<ProgressBar color="green" value={75}/>
|
|
24
|
+
<Well color="gray">
|
|
25
|
+
<div>Well content</div>
|
|
26
|
+
</Well>
|
|
27
|
+
<GlobalNotification persistent={true} variant="success">
|
|
28
|
+
Global notification content
|
|
29
|
+
</GlobalNotification>
|
|
30
|
+
<div className="additional-content">
|
|
31
|
+
This is some additional content that is not part of the GuidanceBlock.
|
|
32
|
+
<MockSubcomponent />
|
|
33
|
+
</div>
|
|
34
|
+
</div>);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
",
|
|
42
|
+
"index.ts": "export * from './'
|
|
43
|
+
",
|
|
44
|
+
"subcomponents/MockSubcomponent.tsx": "import { Button } from "@kaizen/components/next";
|
|
45
|
+
import { LinkButton } from "@kaizen/components";
|
|
46
|
+
import React from 'react';
|
|
47
|
+
|
|
48
|
+
export const MockSubcomponent = (): JSX.Element => {
|
|
49
|
+
return (<div>
|
|
50
|
+
<Button onPress={() => undefined} variant="secondary" size="large">Mock Subcomponent Button</Button>
|
|
51
|
+
<LinkButton href="#link" variant="secondary" size="large">Mock Subcomponent Link</LinkButton>
|
|
52
|
+
</div>);
|
|
53
|
+
};
|
|
54
|
+
",
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { runV1Codemods } from './runV1Codemods'
|
|
3
|
+
|
|
4
|
+
const run = async (): Promise<void> => {
|
|
5
|
+
console.log(`š Running all V1 codemods in sequence:
|
|
6
|
+
1. upgradeIconV1
|
|
7
|
+
2. upgradeV1Buttons
|
|
8
|
+
3. migrateGuidanceBlockActionsToActionsSlot
|
|
9
|
+
4. migrateBrandMomentMoodToVariant
|
|
10
|
+
5. migrateCardVariantToColor
|
|
11
|
+
6. migrateConfirmationModalMoodsToVariant
|
|
12
|
+
7. migrateEmptyStateIllustrationTypeToVariant
|
|
13
|
+
8. migrateGlobalNotificationTypeToVariant
|
|
14
|
+
9. migrateInformationTileMoodToVariant
|
|
15
|
+
10. migrateInlineNotificationTypeToVariant
|
|
16
|
+
11. migrateMultiActionTileMoodToVariant
|
|
17
|
+
12. migrateNotificationTypeToVariant
|
|
18
|
+
13. migrateProgressBarMoodToColor
|
|
19
|
+
14. migrateToastNotificationTypeToVariant
|
|
20
|
+
15. migrateWellVariantToColor
|
|
21
|
+
16. removeInputEditModalMood
|
|
22
|
+
17. removePopoverVariant
|
|
23
|
+
`)
|
|
24
|
+
|
|
25
|
+
const targetDir = process.argv[2]
|
|
26
|
+
|
|
27
|
+
if (!targetDir) {
|
|
28
|
+
throw Error('Error: target directory does not exist')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync(targetDir) === false) {
|
|
32
|
+
throw Error('Error: target directory does not exist')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await runV1Codemods(targetDir)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
run().catch((error) => {
|
|
39
|
+
console.error('Fatal error running codemods:', error)
|
|
40
|
+
process.exit(1)
|
|
41
|
+
})
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import os from 'os'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { runV1Codemods } from './runV1Codemods'
|
|
7
|
+
|
|
8
|
+
const cleanupTestDirectory = (tempDir: string): void => {
|
|
9
|
+
if (fs.existsSync(tempDir)) {
|
|
10
|
+
fs.rmSync(tempDir, { recursive: true, force: true })
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Helper to read files from test directory
|
|
15
|
+
const readTestFiles = (tempDir: string): Record<string, string> => {
|
|
16
|
+
const files: Record<string, string> = {}
|
|
17
|
+
|
|
18
|
+
const readDir = (dirPath: string, basePath = ''): void => {
|
|
19
|
+
const items = fs.readdirSync(dirPath)
|
|
20
|
+
|
|
21
|
+
items.forEach((item) => {
|
|
22
|
+
const fullPath = path.join(dirPath, item)
|
|
23
|
+
const relativePath = path.join(basePath, item)
|
|
24
|
+
|
|
25
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
26
|
+
readDir(fullPath, relativePath)
|
|
27
|
+
} else if (item.endsWith('.tsx') || item.endsWith('.ts')) {
|
|
28
|
+
files[relativePath] = fs.readFileSync(fullPath, 'utf8')
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
readDir(tempDir)
|
|
34
|
+
return files
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const copyDirectoryToTemp = (sourceDir: string): string => {
|
|
38
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'runV1Codemods-snapshot-'))
|
|
39
|
+
|
|
40
|
+
const copyRecursive = (src: string, dest: string): void => {
|
|
41
|
+
const stat = fs.statSync(src)
|
|
42
|
+
|
|
43
|
+
if (stat.isDirectory()) {
|
|
44
|
+
if (!fs.existsSync(dest)) {
|
|
45
|
+
fs.mkdirSync(dest, { recursive: true })
|
|
46
|
+
}
|
|
47
|
+
const items = fs.readdirSync(src)
|
|
48
|
+
items.forEach((item) => {
|
|
49
|
+
copyRecursive(path.join(src, item), path.join(dest, item))
|
|
50
|
+
})
|
|
51
|
+
} else {
|
|
52
|
+
fs.copyFileSync(src, dest)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
copyRecursive(sourceDir, tempDir)
|
|
57
|
+
return tempDir
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('runV1Codemods', () => {
|
|
61
|
+
describe('MockComponentDir Snapshot Tests', () => {
|
|
62
|
+
it('should transform MockComponentDir files and match snapshot', () => {
|
|
63
|
+
const mockSourceDir = path.resolve(__dirname, '__fixtures__', 'MockComponentDir')
|
|
64
|
+
const tempDir = copyDirectoryToTemp(mockSourceDir)
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
runV1Codemods(tempDir)
|
|
68
|
+
const transformedFiles = readTestFiles(tempDir)
|
|
69
|
+
|
|
70
|
+
expect(transformedFiles).toMatchSnapshot()
|
|
71
|
+
|
|
72
|
+
expect(transformedFiles['MockComponent.tsx']).toContain('actionsSlot')
|
|
73
|
+
expect(transformedFiles['MockComponent.tsx']).not.toContain('actions={{')
|
|
74
|
+
expect(transformedFiles['MockComponent.tsx']).toContain(
|
|
75
|
+
'import { Button } from "@kaizen/components/next"',
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
expect(transformedFiles['subcomponents/MockSubcomponent.tsx']).toContain('onPress')
|
|
79
|
+
expect(transformedFiles['subcomponents/MockSubcomponent.tsx']).toContain(
|
|
80
|
+
'import { Button } from "@kaizen/components/next"',
|
|
81
|
+
)
|
|
82
|
+
} finally {
|
|
83
|
+
cleanupTestDirectory(tempDir)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
describe('MockFailedComponentDir Failed', () => {
|
|
88
|
+
it('should throw an Error and exit on a failed codemod', () => {
|
|
89
|
+
const mockSourceDir = path.resolve(__dirname, '__fixtures__', 'MockFailedComponentDir')
|
|
90
|
+
const tempDir = copyDirectoryToTemp(mockSourceDir)
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const exitSpy = vi
|
|
94
|
+
.spyOn(process, 'exit')
|
|
95
|
+
.mockImplementation((code?: string | number | null | undefined) => {
|
|
96
|
+
throw new Error(`process.exit(${code})`)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
expect(() => runV1Codemods(tempDir)).toThrow('process.exit(1)')
|
|
100
|
+
expect(exitSpy).toHaveBeenCalledWith(1)
|
|
101
|
+
exitSpy.mockRestore()
|
|
102
|
+
} finally {
|
|
103
|
+
cleanupTestDirectory(tempDir)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { transformBrandMomentMoodToVariant } from '../migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant'
|
|
3
|
+
import { transformCardVariantToColor } from '../migrateCardVariantToColor/transformCardVariantToColor'
|
|
4
|
+
import { transformConfirmationModalMoodsToVariant } from '../migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant'
|
|
5
|
+
import { transformEmptyStateIllustrationTypeToVariant } from '../migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant'
|
|
6
|
+
import { migrateGuidanceBlockActionsToActionsSlot } from '../migrateGuidanceBlockActionsToActionsSlot/migrateGuidanceBlockActionsToActionsSlot'
|
|
7
|
+
import { transformInformationTileMoodToVariant } from '../migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant'
|
|
8
|
+
import { transformMultiActionTileMoodToVariant } from '../migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant'
|
|
9
|
+
import { transformNotificationTypeToVariant } from '../migrateNotificationTypeToVariant/migrateNotificationTypeToVariant'
|
|
10
|
+
import { transformProgressBarMoodToColor } from '../migrateProgressBarMoodToColor/transformProgressBarMoodToColor'
|
|
11
|
+
import { transformWellVariantToColor } from '../migrateWellVariantToColor/transformWellVariantToColor'
|
|
12
|
+
import { removeInputEditModalMood } from '../removeInputEditModalMood/removeInputEditModalMood'
|
|
13
|
+
import { removePopoverVariant } from '../removePopoverVariant/removePopoverVariant'
|
|
14
|
+
import { upgradeIconV1 } from '../upgradeIconV1/upgradeIconV1'
|
|
15
|
+
import { upgradeV1Buttons } from '../upgradeV1Buttons/upgradeV1Buttons'
|
|
16
|
+
import { transformComponentsInDir, transformComponentsInDirByPattern } from '../utils'
|
|
17
|
+
|
|
18
|
+
interface CodemodConfig {
|
|
19
|
+
name: string
|
|
20
|
+
runner: (targetDir: string) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const codemods: CodemodConfig[] = [
|
|
24
|
+
{
|
|
25
|
+
name: 'upgradeIconV1',
|
|
26
|
+
runner: (dir) => {
|
|
27
|
+
transformComponentsInDirByPattern(dir, 'Icon$', (tagNames) => [upgradeIconV1(tagNames)])
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'upgradeV1Buttons',
|
|
32
|
+
runner: (dir) => {
|
|
33
|
+
transformComponentsInDir(dir, ['IconButton', 'Button'], (tagNames) => [
|
|
34
|
+
upgradeV1Buttons(tagNames),
|
|
35
|
+
])
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'migrateGuidanceBlockActionsToActionsSlot',
|
|
40
|
+
runner: (dir) => {
|
|
41
|
+
transformComponentsInDir(dir, ['GuidanceBlock'], (tagNames) => [
|
|
42
|
+
migrateGuidanceBlockActionsToActionsSlot(tagNames),
|
|
43
|
+
])
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'migrateBrandMomentMoodToVariant',
|
|
48
|
+
runner: (dir) => {
|
|
49
|
+
transformComponentsInDir(dir, ['BrandMoment'], (tagNames) => [
|
|
50
|
+
transformBrandMomentMoodToVariant(tagNames),
|
|
51
|
+
])
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'migrateCardVariantToColor',
|
|
56
|
+
runner: (dir) => {
|
|
57
|
+
transformComponentsInDir(dir, ['Card'], (tagNames) => [transformCardVariantToColor(tagNames)])
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'migrateConfirmationModalMoodsToVariant',
|
|
62
|
+
runner: (dir) => {
|
|
63
|
+
transformComponentsInDir(dir, ['ConfirmationModal'], (tagNames) => [
|
|
64
|
+
transformConfirmationModalMoodsToVariant(tagNames),
|
|
65
|
+
])
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'migrateEmptyStateIllustrationTypeToVariant',
|
|
70
|
+
runner: (dir) => {
|
|
71
|
+
transformComponentsInDir(dir, ['EmptyState'], (tagNames) => [
|
|
72
|
+
transformEmptyStateIllustrationTypeToVariant(tagNames),
|
|
73
|
+
])
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'migrateGlobalNotificationTypeToVariant',
|
|
78
|
+
runner: (dir) => {
|
|
79
|
+
transformComponentsInDir(dir, ['GlobalNotification'], (tagNames) => [
|
|
80
|
+
transformNotificationTypeToVariant(tagNames),
|
|
81
|
+
])
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'migrateInformationTileMoodToVariant',
|
|
86
|
+
runner: (dir) => {
|
|
87
|
+
transformComponentsInDir(dir, ['InformationTile'], (tagNames) => [
|
|
88
|
+
transformInformationTileMoodToVariant(tagNames),
|
|
89
|
+
])
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'migrateInlineNotificationTypeToVariant',
|
|
94
|
+
runner: (dir) => {
|
|
95
|
+
transformComponentsInDir(dir, ['InlineNotification'], (tagNames) => [
|
|
96
|
+
transformNotificationTypeToVariant(tagNames),
|
|
97
|
+
])
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'migrateMultiActionTileMoodToVariant',
|
|
102
|
+
runner: (dir) => {
|
|
103
|
+
transformComponentsInDir(dir, ['MultiActionTile'], (tagNames) => [
|
|
104
|
+
transformMultiActionTileMoodToVariant(tagNames),
|
|
105
|
+
])
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'migrateNotificationTypeToVariant',
|
|
110
|
+
runner: (dir) => {
|
|
111
|
+
transformComponentsInDir(dir, ['Notification'], (tagNames) => [
|
|
112
|
+
transformNotificationTypeToVariant(tagNames),
|
|
113
|
+
])
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'migrateProgressBarMoodToColor',
|
|
118
|
+
runner: (dir) => {
|
|
119
|
+
transformComponentsInDir(dir, ['ProgressBar'], (tagNames) => [
|
|
120
|
+
transformProgressBarMoodToColor(tagNames),
|
|
121
|
+
])
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'migrateToastNotificationTypeToVariant',
|
|
126
|
+
runner: (dir) => {
|
|
127
|
+
transformComponentsInDir(dir, ['ToastNotification'], (tagNames) => [
|
|
128
|
+
transformNotificationTypeToVariant(tagNames),
|
|
129
|
+
])
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'migrateWellVariantToColor',
|
|
134
|
+
runner: (dir) => {
|
|
135
|
+
transformComponentsInDir(dir, ['Well'], (tagNames) => [transformWellVariantToColor(tagNames)])
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'removeInputEditModalMood',
|
|
140
|
+
runner: (dir) => {
|
|
141
|
+
transformComponentsInDir(dir, ['InputEditModal'], (tagNames) => [
|
|
142
|
+
removeInputEditModalMood(tagNames),
|
|
143
|
+
])
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'removePopoverVariant',
|
|
148
|
+
runner: (dir) => {
|
|
149
|
+
transformComponentsInDir(dir, ['Popover'], (tagNames) => [removePopoverVariant(tagNames)])
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
export const runV1Codemods = (targetDir: string): void => {
|
|
155
|
+
console.log(`š Running ${codemods.length} codemods on directory: ${targetDir}`)
|
|
156
|
+
console.log('')
|
|
157
|
+
|
|
158
|
+
if (fs.existsSync(targetDir) === false) {
|
|
159
|
+
console.error(`Error: Target directory "${targetDir}" does not exist`)
|
|
160
|
+
process.exit(1)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let successCount = 0
|
|
164
|
+
|
|
165
|
+
for (const codemod of codemods) {
|
|
166
|
+
try {
|
|
167
|
+
console.log(`š Starting codemod: ${codemod.name}`)
|
|
168
|
+
codemod.runner(targetDir)
|
|
169
|
+
console.log(`ā
Completed codemod: ${codemod.name}`)
|
|
170
|
+
successCount++
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.log(`š„ Error in codemod: ${codemod.name} - exiting early
|
|
173
|
+
|
|
174
|
+
ā
${successCount} codemods completed successfully
|
|
175
|
+
š¢ ${codemods.length - successCount} codemods did not run
|
|
176
|
+
Address the issues in the following codemod before proceeding:
|
|
177
|
+
`)
|
|
178
|
+
|
|
179
|
+
console.error(`${codemod.name}\n`)
|
|
180
|
+
console.error(error)
|
|
181
|
+
process.exit(1)
|
|
182
|
+
}
|
|
183
|
+
console.log('')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log('\nš All codemods completed successfully!')
|
|
187
|
+
}
|
package/dist/styles.css
CHANGED
|
@@ -23,26 +23,6 @@
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
@layer kz-components {
|
|
27
|
-
.Trigger-module_button__giSqA {
|
|
28
|
-
anchor-name: var(--anchor-name);
|
|
29
|
-
display: flex;
|
|
30
|
-
align-items: center;
|
|
31
|
-
justify-content: space-between;
|
|
32
|
-
font-family: var(--typography-paragraph-body-font-family);
|
|
33
|
-
font-weight: var(--typography-paragraph-body-font-weight);
|
|
34
|
-
font-size: var(--typography-paragraph-body-font-size);
|
|
35
|
-
line-height: var(--typography-paragraph-body-line-height);
|
|
36
|
-
letter-spacing: var(--typography-paragraph-body-letter-spacing);
|
|
37
|
-
padding: var(--spacing-12);
|
|
38
|
-
min-height: var(--spacing-48);
|
|
39
|
-
min-width: var(--spacing-200);
|
|
40
|
-
background-color: var(--color-white);
|
|
41
|
-
border-radius: var(--spacing-8);
|
|
42
|
-
border: 1px solid var(--color-gray-500);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
26
|
@layer kz-components {
|
|
47
27
|
.Popover-module_popover__BjY2S {
|
|
48
28
|
position: absolute;
|
|
@@ -78,6 +58,26 @@
|
|
|
78
58
|
}
|
|
79
59
|
}
|
|
80
60
|
|
|
61
|
+
@layer kz-components {
|
|
62
|
+
.Trigger-module_button__giSqA {
|
|
63
|
+
anchor-name: var(--anchor-name);
|
|
64
|
+
display: flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
justify-content: space-between;
|
|
67
|
+
font-family: var(--typography-paragraph-body-font-family);
|
|
68
|
+
font-weight: var(--typography-paragraph-body-font-weight);
|
|
69
|
+
font-size: var(--typography-paragraph-body-font-size);
|
|
70
|
+
line-height: var(--typography-paragraph-body-line-height);
|
|
71
|
+
letter-spacing: var(--typography-paragraph-body-letter-spacing);
|
|
72
|
+
padding: var(--spacing-12);
|
|
73
|
+
min-height: var(--spacing-48);
|
|
74
|
+
min-width: var(--spacing-200);
|
|
75
|
+
background-color: var(--color-white);
|
|
76
|
+
border-radius: var(--spacing-8);
|
|
77
|
+
border: 1px solid var(--color-gray-500);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
81
|
@layer kz-components {
|
|
82
82
|
/*
|
|
83
83
|
* This is taken from the Material Symbols CDN
|