@ukic/codemod 1.0.0-alpha.8 → 1.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.2.0](https://github.com/mi6/ic-ui-kit/compare/@ukic/codemod@1.0.0-alpha.8...@ukic/codemod@1.2.0) (2025-05-14)
7
+
8
+ ### Features
9
+
10
+ - **codemod:** minor feat for v3 ([52c30ea](https://github.com/mi6/ic-ui-kit/commit/52c30eaad0c7bfe3fbb5d9be9473a7f71ce850c3))
11
+
12
+ ### Performance Improvements
13
+
14
+ - **codemod:** added additional changes and improved performance ([753a3f9](https://github.com/mi6/ic-ui-kit/commit/753a3f924cf618490cf8624051dfda39ce590aaa))
15
+
16
+ # [1.1.0](https://github.com/mi6/ic-ui-kit/compare/@ukic/codemod@1.0.0-alpha.8...@ukic/codemod@1.1.0) (2025-04-30)
17
+
18
+ ### Features
19
+
20
+ - **codemod:** minor feat for v3 ([d51f11a](https://github.com/mi6/ic-ui-kit/commit/d51f11aea7154ad0e3df53df7221ef4b29b98082))
21
+
22
+ ### Performance Improvements
23
+
24
+ - **codemod:** added additional changes and improved performance ([724e777](https://github.com/mi6/ic-ui-kit/commit/724e7775753aa2c55c336e84bd7e32be37cf3f9c))
25
+
6
26
  # [1.0.0-alpha.8](https://github.com/mi6/ic-ui-kit/compare/@ukic/codemod@1.0.0-alpha.7...@ukic/codemod@1.0.0-alpha.8) (2025-04-28)
7
27
 
8
28
  **Note:** Version bump only for package @ukic/codemod
package/README.md CHANGED
@@ -11,7 +11,7 @@ Given a directory, it will scan over files and find any relevant ICDS components
11
11
  ## How to run
12
12
 
13
13
 
14
- This package will be usable as an executable requiring a directory and optional test boolean argument to cover tests
14
+ This package will be usable as an executable, requiring a directory and optional test boolean argument to cover tests
15
15
 
16
16
  ```console
17
17
  - npx @ukic/codemod <dir> <test>
@@ -1,180 +1,112 @@
1
- import { compareComponent } from "../sections/component-changes.js";
1
+ import { convertComponents } from "../sections/component-changes.js";
2
2
 
3
- describe("compareComponent", () => {
4
- describe("React style changes", () => {
5
- it("should replace old props with new props simple", () => {
6
- const stringArray = `
7
- <ExampleComponent oldProp1="value1" oldProp2="value2" />
3
+ describe("React style changes", () => {
4
+ it("should replace component name change", () => {
5
+ const stringArray = `
6
+ <IcDataEntity prop="value" />
8
7
  `;
9
- const jsonData = [
10
- {
11
- componentsAffected: "ExampleComponent",
12
- type: "prop",
13
- v2Name: "oldProp1",
14
- v3Name: "newProp1",
15
- },
16
- {
17
- componentsAffected: "ExampleComponent",
18
- type: "prop",
19
- v2Name: "oldProp2",
20
- v3Name: "newProp2",
21
- },
22
- ];
23
-
24
- const result = compareComponent(stringArray, jsonData);
25
- expect(result).toContain('newProp1="value1"');
26
- expect(result).toContain('newProp2="value2"');
27
- });
28
-
29
- it("should replace old props with new props absolute varient", () => {
30
- const stringArray = `<ExampleComponent oldProp1 oldProp2="oldProp1" />`;
31
- const jsonData = [
32
- {
33
- componentsAffected: "ExampleComponent",
34
- type: "absolute",
35
- v2Name: "oldProp1",
36
- v3Name: "newProp1",
37
- },
38
- ];
39
-
40
- const result = compareComponent(stringArray, jsonData);
41
- expect(result).toBe('<ExampleComponent newProp1 oldProp2="oldProp1" />');
42
- });
43
-
44
- it("should replace old props with new props simple Component", () => {
45
- const stringArray = `<ExampleComponent oldProp1="value1" oldProp2="value2" />`;
46
- const jsonData = [
47
- {
48
- componentsAffected: "ExampleComponent",
49
- type: "component",
50
- v2Name: "ExampleComponent",
51
- v3Name: "ExampleComponentNew",
52
- },
53
- ];
54
-
55
- const result = compareComponent(stringArray, jsonData);
56
- expect(result).toBe(
57
- '<ExampleComponentNew oldProp1="value1" oldProp2="value2" />'
58
- );
59
- });
60
-
61
- it("should replace old props with new props simple Component not self closing", () => {
62
- const stringArray = `<ExampleComponent oldProp1="value1" oldProp2="value2" >
63
- <div>Test</div>
64
- </ExampleComponent>`;
65
- const jsonData = [
66
- {
67
- componentsAffected: "ExampleComponent",
68
- type: "component",
69
- v2Name: "ExampleComponent",
70
- v3Name: "ExampleComponentNew",
71
- },
72
- ];
73
-
74
- const result = compareComponent(stringArray, jsonData);
75
- expect(result).toBe(
76
- `<ExampleComponentNew oldProp1="value1" oldProp2="value2" >
77
- <div>Test</div>
78
- </ExampleComponentNew>`
79
- );
80
- });
81
-
82
- it("should not replace old props with new props simple Component", () => {
83
- const stringArray = `<ExampleComponentDifferent oldProp1="value1" oldProp2="value2" />`;
84
- const jsonData = [
85
- {
86
- componentsAffected: "ExampleComponent",
87
- type: "component",
88
- v2Name: "ExampleComponent",
89
- v3Name: "ExampleComponentNew",
90
- },
91
- ];
92
-
93
- const result = compareComponent(stringArray, jsonData);
94
- expect(result).toBe(
95
- '<ExampleComponentDifferent oldProp1="value1" oldProp2="value2" />'
96
- );
97
- });
8
+
9
+ const result = convertComponents(stringArray);
10
+ expect(result.trim()).toBe('<IcDataList prop="value" />');
98
11
  });
99
12
 
100
- describe("web-component style changes", () => {
101
- it("should replace old props with new props simple", () => {
102
- const stringArray = `
103
- <example-component oldProp1="value1" oldProp2="value2" />
104
- `;
105
- const jsonData = [
106
- {
107
- componentsAffected: "example-component",
108
- type: "prop",
109
- v2Name: "oldProp1",
110
- v3Name: "newProp1",
111
- },
112
- {
113
- componentsAffected: "example-component",
114
- type: "prop",
115
- v2Name: "oldProp2",
116
- v3Name: "newProp2",
117
- },
118
- ];
119
-
120
- const result = compareComponent(stringArray, jsonData);
121
- expect(result).toContain('newProp1="value1"');
122
- expect(result).toContain('newProp2="value2"');
123
- });
124
-
125
- it("should replace old props with new props simple Component", () => {
126
- const stringArray = `<example-component oldProp1="value1" oldProp2="value2" />`;
127
- const jsonData = [
128
- {
129
- componentsAffected: "example-component",
130
- type: "web-component",
131
- v2Name: "example-component",
132
- v3Name: "example-component-new",
133
- },
134
- ];
135
-
136
- const result = compareComponent(stringArray, jsonData);
137
- expect(result).toBe(
138
- '<example-component-new oldProp1="value1" oldProp2="value2" />'
139
- );
140
- });
141
-
142
- it("should replace old props with new props simple Component not self closing", () => {
143
- const stringArray = `<example-component oldProp1="value1" oldProp2="value2" >
13
+ it("should replace old props with new prop name", () => {
14
+ const stringArray = `<IcEmptyState bodyMaxLines={50} />`;
15
+
16
+ const result = convertComponents(stringArray);
17
+ expect(result.trim()).toBe("<IcEmptyState maxLines={50} />");
18
+ });
19
+
20
+ it("should replace old props with new prop name and value", () => {
21
+ const stringArray = `<IcSelect size="default" />`;
22
+
23
+ const result = convertComponents(stringArray);
24
+ expect(result.trim()).toBe(`<IcSelect size="medium" />`);
25
+ });
26
+
27
+ it("should replace old props with new prop name and value single quotes", () => {
28
+ const stringArray = `<IcSearchBar size={'default'} />`;
29
+
30
+ const result = convertComponents(stringArray);
31
+ expect(result.trim()).toBe(`<IcSearchBar size="medium" />`);
32
+ });
33
+
34
+ it("should not replace props that are not part of component", () => {
35
+ const stringArray = `<IcStatusTag size="default" ><IcEmptyState /></IcStatusTag>`;
36
+
37
+ const result = convertComponents(stringArray);
38
+ expect(result).toBe(
39
+ `<IcStatusTag size="medium" ><IcEmptyState /></IcStatusTag>`
40
+ );
41
+ });
42
+
43
+ it("should replace old props with new prop name and value binary switch", () => {
44
+ const stringArray = `<icDialog buttons="true" />`;
45
+
46
+ const result = convertComponents(stringArray);
47
+ expect(result.trim()).toBe(`<icDialog hideDefaultControls="false" />`);
48
+ });
49
+ });
50
+
51
+ describe("web-component style changes", () => {
52
+ it("should replace component name change", () => {
53
+ const stringArray = `
54
+ <ic-data-entity prop="value" ></ic-data-entity>
55
+ `;
56
+
57
+ const result = convertComponents(stringArray);
58
+ expect(result.trim()).toBe('<ic-data-list prop="value" ></ic-data-list>');
59
+ });
60
+
61
+ it("should replace component name change and ignore similar name", () => {
62
+ const stringArray = `<ic-card heading="test"></ic-card>
63
+ <ic-card-horizontal heading="test"></ic-card-horizontal>
64
+ `;
65
+
66
+ const result = convertComponents(stringArray);
67
+ expect(result.trim())
68
+ .toBe(`<ic-card-vertical heading="test"></ic-card-vertical>
69
+ <ic-card-horizontal heading="test"></ic-card-horizontal>`);
70
+ });
71
+
72
+ it("should replace old props with new prop name", () => {
73
+ const stringArray = `<ic-empty-state body-max-lines="50" />`;
74
+
75
+ const result = convertComponents(stringArray);
76
+ expect(result.trim()).toBe(`<ic-empty-state max-lines="50" />`);
77
+ });
78
+
79
+ it("should replace old props with new props simple Component not self closing", () => {
80
+ const stringArray = `<ic-badge text-label="value1" >
144
81
  <div>Test</div>
145
- </example-component>`;
146
- const jsonData = [
147
- {
148
- componentsAffected: "example-component",
149
- type: "web-component",
150
- v2Name: "example-component",
151
- v3Name: "example-component-new",
152
- },
153
- ];
154
-
155
- const result = compareComponent(stringArray, jsonData);
156
- expect(result).toBe(
157
- `<example-component-new oldProp1="value1" oldProp2="value2" >
82
+ </ic-badge>`;
83
+
84
+ const result = convertComponents(stringArray);
85
+ expect(result).toBe(
86
+ `<ic-badge label="value1" >
158
87
  <div>Test</div>
159
- </example-component-new>`
160
- );
161
- });
162
-
163
- it("should not replace old props with new props simple Component", () => {
164
- const stringArray = `<example-component-different oldProp1="value1" oldProp2="value2" />`;
165
- const jsonData = [
166
- {
167
- componentsAffected: "example-component",
168
- type: "web-component",
169
- v2Name: "example-component",
170
- v3Name: "example-component-new",
171
- },
172
- ];
173
-
174
- const result = compareComponent(stringArray, jsonData);
175
- expect(result).toBe(
176
- '<example-component-different oldProp1="value1" oldProp2="value2" />'
177
- );
178
- });
88
+ </ic-badge>`
89
+ );
90
+ });
91
+
92
+ it("should replace old props with new prop name and value", () => {
93
+ const stringArray = `<ic-accordion size="default" />`;
94
+
95
+ const result = convertComponents(stringArray);
96
+ expect(result.trim()).toBe(`<ic-accordion size="medium" />`);
97
+ });
98
+
99
+ it("should replace old props with new prop name and value multiple", () => {
100
+ const stringArray = `<ic-button appearance="dark" />`;
101
+
102
+ const result = convertComponents(stringArray);
103
+ expect(result.trim()).toBe(`<ic-button theme="light" monochrome />`);
104
+ });
105
+
106
+ it("should replace old props with new prop name and value binary switch", () => {
107
+ const stringArray = `<ic-dialog buttons="true" />`;
108
+
109
+ const result = convertComponents(stringArray);
110
+ expect(result.trim()).toBe(`<ic-dialog hide-default-controls="false" />`);
179
111
  });
180
112
  });
@@ -1,4 +1,4 @@
1
- import { testComparison } from "../sections/test-comparison.js";
1
+ import { simpleTestComparison } from "../sections/simple-test-comparison";
2
2
 
3
3
  describe("compareTest", () => {
4
4
  it("should replace old props with new props simple", () => {
@@ -8,22 +8,31 @@ const stepOne = container.querySelector(
8
8
  ) as HTMLIcStepElement;
9
9
  expect(stepOne.stepType).toBe(stepStates.current);
10
10
  `.trim();
11
- const jsonData = [
12
- {
13
- componentsAffected: "ic-step",
14
- type: "prop",
15
- v2Name: "stepType",
16
- v3Name: "type",
17
- },
18
- ];
19
-
20
- const result = testComparison(stringArray, jsonData);
11
+ const result = simpleTestComparison(stringArray);
21
12
  expect(result).toBe(
22
13
  `
23
14
  const stepOne = container.querySelector(
24
- 'ic-step[step-title="Choose coffee"]',
15
+ 'ic-step[heading="Choose coffee"]',
25
16
  ) as HTMLIcStepElement;
26
17
  expect(stepOne.type).toBe(stepStates.current);`.trim()
27
18
  );
28
19
  });
20
+
21
+ it("should replace old type with new type simple", () => {
22
+ const stringArray =
23
+ `const select = dialog?.children[2] as HTMLIcSelectWithMultiElement;`.trim();
24
+ const result = simpleTestComparison(stringArray);
25
+ expect(result).toBe(
26
+ `const select = dialog?.children[2] as HTMLIcSelectElement;`.trim()
27
+ );
28
+ });
29
+
30
+ it("should replace old component with new component simple", () => {
31
+ const stringArray =
32
+ `expect(container.querySelectorAll("ic-data-entity")).toHaveLength(1);`.trim();
33
+ const result = simpleTestComparison(stringArray);
34
+ expect(result).toBe(
35
+ `expect(container.querySelectorAll("ic-data-list")).toHaveLength(1);`.trim()
36
+ );
37
+ });
29
38
  });
package/codemod.js CHANGED
@@ -2,10 +2,8 @@
2
2
  import fs from "fs";
3
3
  import yargs from "yargs";
4
4
  import { searchDirectory } from "./sections/directory-search.js";
5
- import { compareComponent } from "./sections/component-changes.js";
5
+ import { convertComponents } from "./sections/component-changes.js";
6
6
  import { simpleTestComparison } from "./sections/simple-test-comparison.js";
7
- import htmlData from "./data/changes.js";
8
- import reactData from "./data/reactChanges.js";
9
7
 
10
8
  /**
11
9
  *
@@ -34,11 +32,11 @@ const main = async (path, test = false) => {
34
32
  const files = await searchDirectory(path);
35
33
  files.forEach((file) => {
36
34
  const linesArray = readFileLinesToArray(file);
35
+ /**
36
+ * if file contains .spec or .test, run simple test comparison
37
+ */
37
38
  if (test && (file.includes(".spec.") || file.includes(".test."))) {
38
- const changedFile = simpleTestComparison(linesArray, [
39
- ...htmlData,
40
- ...reactData,
41
- ]);
39
+ const changedFile = simpleTestComparison(linesArray);
42
40
  if (changedFile !== linesArray) {
43
41
  fs.writeFile(file, changedFile, (err) => {
44
42
  if (err) return console.log(err);
@@ -46,10 +44,10 @@ const main = async (path, test = false) => {
46
44
  });
47
45
  }
48
46
  } else {
49
- const changedComponentFile = compareComponent(linesArray, [
50
- ...htmlData,
51
- ...reactData,
52
- ]);
47
+ /**
48
+ * run file conversion for all other files
49
+ */
50
+ const changedComponentFile = convertComponents(linesArray);
53
51
  if (changedComponentFile !== linesArray) {
54
52
  fs.writeFile(file, String(changedComponentFile), (err) => {
55
53
  if (err) return console.log(err);
@@ -0,0 +1,90 @@
1
+ const appearanceLight = {
2
+ v2: `appearance=[{]?["']light['"][}]?`,
3
+ v3: `theme="dark" monochrome`,
4
+ type: "absolute",
5
+ };
6
+
7
+ const appearanceDark = {
8
+ v2: `appearance=[{]?["']dark['"][}]?`,
9
+ v3: `monochrome`,
10
+ type: "absolute",
11
+ };
12
+
13
+ const appearanceDarkNoMonochrome = {
14
+ v2: `appearance=[{]?["']dark['"][}]?`,
15
+ v3: `theme="light"`,
16
+ type: "absolute",
17
+ };
18
+ const appearanceLightNoMonochrome = {
19
+ v2: `appearance=[{]?["']light['"][}]?`,
20
+ v3: `theme="dark"`,
21
+ type: "absolute",
22
+ };
23
+
24
+ const appearanceLightDeprecated = {
25
+ v2: `light\\b(?!'|")`,
26
+ v3: `theme="dark"`,
27
+ type: "absolute",
28
+ };
29
+
30
+ const appearanceDarkIncludesMonochrome = {
31
+ v2: `appearance=[{]?["']dark['"][}]?`,
32
+ v3: `theme="light" monochrome`,
33
+ type: "absolute",
34
+ };
35
+ const appearanceOutlined = {
36
+ v2: `appearance=[{]?["']outlined['"][}]?`,
37
+ v3: `variant="outlined"`,
38
+ type: "absolute",
39
+ };
40
+
41
+ const appearanceOutline = {
42
+ v2: `appearance=[{]?["']outline['"][}]?`,
43
+ v3: `variant="outlined"`,
44
+ type: "absolute",
45
+ };
46
+
47
+ const appearanceFilled = {
48
+ v2: `appearance=[{]?["']filled['"][}]?`,
49
+ v3: `variant="filled"`,
50
+ type: "absolute",
51
+ };
52
+
53
+ const appearanceDefault = {
54
+ v2: `appearance=[{]?["']default['"][}]?`,
55
+ v3: `theme="light"`,
56
+ type: "absolute",
57
+ };
58
+
59
+ const sizeDefault = {
60
+ v2: `size=[{]?["']default['"][}]?`,
61
+ v3: 'size="medium"',
62
+ type: "absolute",
63
+ };
64
+
65
+ const sizeSmall = {
66
+ v2: "small={true}",
67
+ v3: `size="small"`,
68
+ type: "prop",
69
+ };
70
+ const sizeSmallAbsolute = {
71
+ v2: `small\\b(?!'|"|=)`,
72
+ v3: `size="small"`,
73
+ type: "absolute",
74
+ };
75
+
76
+ export {
77
+ appearanceDark,
78
+ appearanceLight,
79
+ appearanceLightNoMonochrome,
80
+ appearanceDarkIncludesMonochrome,
81
+ appearanceDarkNoMonochrome,
82
+ appearanceLightDeprecated,
83
+ appearanceDefault,
84
+ appearanceOutlined,
85
+ appearanceOutline,
86
+ appearanceFilled,
87
+ sizeDefault,
88
+ sizeSmall,
89
+ sizeSmallAbsolute,
90
+ };