@ukic/codemod 1.0.0-alpha.2 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +4 -7
- package/codemod.js +4 -14
- package/data/changes.js +11 -5
- package/data/reactChanges.js +11 -5
- package/package.json +2 -2
- package/sections/component-changes.js +6 -2
- package/sections/generate-regex.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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.0.0-alpha.3](https://github.com/mi6/ic-ui-kit/compare/@ukic/codemod@1.0.0-alpha.2...@ukic/codemod@1.0.0-alpha.3) (2025-02-05)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **codemod:** added json data and combine both versions of data for component serach ([0faeee1](https://github.com/mi6/ic-ui-kit/commit/0faeee11b54c4582c3a6b2d0186372ae16afa447))
|
|
11
|
+
|
|
6
12
|
# [1.0.0-alpha.2](https://github.com/mi6/ic-ui-kit/compare/@ukic/codemod@1.0.0-alpha.1...@ukic/codemod@1.0.0-alpha.2) (2025-01-24)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @ukic/codemod
|
package/README.md
CHANGED
|
@@ -29,17 +29,14 @@ This package will be usable as an executable requiring a directory and optional
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### Examples:
|
|
32
|
+
With tests
|
|
32
33
|
```console
|
|
33
34
|
- npx @ukic/codemod --dir ./#path/app/src/components --test true
|
|
34
35
|
```
|
|
35
|
-
|
|
36
|
-
or run locally via
|
|
37
|
-
|
|
36
|
+
Without tests
|
|
38
37
|
```console
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
- node ./codemod --dir ./#path/app/src/components --test false
|
|
42
|
-
```
|
|
38
|
+
- npx @ukic/codemod --dir ./#path/app/src/components
|
|
39
|
+
```
|
|
43
40
|
|
|
44
41
|
## Contributing
|
|
45
42
|
|
package/codemod.js
CHANGED
|
@@ -34,7 +34,6 @@ const main = async (path, test = false) => {
|
|
|
34
34
|
const files = await searchDirectory(path);
|
|
35
35
|
files.forEach((file) => {
|
|
36
36
|
const linesArray = readFileLinesToArray(file);
|
|
37
|
-
const isReact = file.includes(".tsx") || file.includes(".jsx");
|
|
38
37
|
if (test && (file.includes(".spec.") || file.includes(".test."))) {
|
|
39
38
|
const changedFile = simpleTestComparison(linesArray, [
|
|
40
39
|
...htmlData,
|
|
@@ -46,20 +45,11 @@ const main = async (path, test = false) => {
|
|
|
46
45
|
console.log(`${file.split("\\").slice(-1)} modified successfully`);
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
|
-
}
|
|
50
|
-
if (file.includes(`.cy.`)) {
|
|
51
|
-
const changedFile = compareComponent(linesArray, htmlData);
|
|
52
|
-
if (changedFile !== linesArray) {
|
|
53
|
-
fs.writeFile(file, changedFile, (err) => {
|
|
54
|
-
if (err) return console.log(err);
|
|
55
|
-
console.log(`${file.split("\\").slice(-1)} modified successfully`);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
48
|
} else {
|
|
59
|
-
const changedComponentFile = compareComponent(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
49
|
+
const changedComponentFile = compareComponent(linesArray, [
|
|
50
|
+
...htmlData,
|
|
51
|
+
...reactData,
|
|
52
|
+
]);
|
|
63
53
|
if (changedComponentFile !== linesArray) {
|
|
64
54
|
fs.writeFile(file, String(changedComponentFile), (err) => {
|
|
65
55
|
if (err) return console.log(err);
|
package/data/changes.js
CHANGED
|
@@ -6,22 +6,28 @@ export default [
|
|
|
6
6
|
type: "prop",
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
|
-
v2Name:
|
|
9
|
+
v2Name: `small\\b[^'"]`,
|
|
10
10
|
v3Name: 'size="small"',
|
|
11
11
|
componentsAffected: "ic-select",
|
|
12
12
|
type: "absolute",
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
v2Name:
|
|
15
|
+
v2Name: `size=[{]?["']default['"][}]?`,
|
|
16
16
|
v3Name: 'size="medium"',
|
|
17
17
|
componentsAffected: "ic-status-tag",
|
|
18
|
-
type: "
|
|
18
|
+
type: "absolute",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
v2Name: `size=[{]?["']default['"][}]?`,
|
|
22
|
+
v3Name: 'size="medium"',
|
|
23
|
+
componentsAffected: "ic-dialog",
|
|
24
|
+
type: "absolute",
|
|
19
25
|
},
|
|
20
26
|
{
|
|
21
|
-
v2Name:
|
|
27
|
+
v2Name: `size=[{]?["']default['"][}]?`,
|
|
22
28
|
v3Name: 'size="medium"',
|
|
23
29
|
componentsAffected: "ic-switch",
|
|
24
|
-
type: "
|
|
30
|
+
type: "absolute",
|
|
25
31
|
},
|
|
26
32
|
{
|
|
27
33
|
v2Name: "group-title",
|
package/data/reactChanges.js
CHANGED
|
@@ -6,7 +6,7 @@ export default [
|
|
|
6
6
|
type: "prop",
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
|
-
v2Name:
|
|
9
|
+
v2Name: `small\\b[^'"]`,
|
|
10
10
|
v3Name: "size={'small'}",
|
|
11
11
|
componentsAffected: "IcSelect",
|
|
12
12
|
type: "absolute",
|
|
@@ -18,16 +18,22 @@ export default [
|
|
|
18
18
|
type: "prop",
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
v2Name:
|
|
21
|
+
v2Name: `size=[{]?["']default['"][}]?`,
|
|
22
22
|
v3Name: "size={'medium'}",
|
|
23
23
|
componentsAffected: "IcStatusTag",
|
|
24
|
-
type: "
|
|
24
|
+
type: "absolute",
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
v2Name:
|
|
27
|
+
v2Name: `size=[{]?["']default['"][}]?`,
|
|
28
28
|
v3Name: "size={'medium'}",
|
|
29
29
|
componentsAffected: "IcSwitch",
|
|
30
|
-
type: "
|
|
30
|
+
type: "absolute",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
v2Name: `size=[{]?["']default['"][}]?`,
|
|
34
|
+
v3Name: "size={'medium'}",
|
|
35
|
+
componentsAffected: "IcDialog",
|
|
36
|
+
type: "absolute",
|
|
31
37
|
},
|
|
32
38
|
{
|
|
33
39
|
v2Name: "groupTitle",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukic/codemod",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "Codemod tool to help assist users upgrading from v2 to v3 of the UKIC design system",
|
|
5
5
|
"bin": "./codemod.js",
|
|
6
6
|
"author": "mi6",
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"access": "public",
|
|
20
20
|
"registry": "https://registry.npmjs.org/"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "c4ead3a55cd2fcb22af6e0e92a46f99c89cb194f"
|
|
23
23
|
}
|
|
@@ -33,8 +33,12 @@ export function compareComponent(stringArray, jsonData) {
|
|
|
33
33
|
if (newProp.type === "absolute") {
|
|
34
34
|
const regex = generateRegex(newProp.v2Name, "absolute-props");
|
|
35
35
|
const exactMatch = String(newComponent).match(regex);
|
|
36
|
-
if (exactMatch)
|
|
37
|
-
newComponent = newComponent.replace(
|
|
36
|
+
if (exactMatch) {
|
|
37
|
+
newComponent = newComponent.replace(
|
|
38
|
+
exactMatch[0],
|
|
39
|
+
newProp.v3Name
|
|
40
|
+
);
|
|
41
|
+
}
|
|
38
42
|
} else newComponent = newComponent.replace(prop, newProp.v3Name);
|
|
39
43
|
});
|
|
40
44
|
fileString = fileString.replace(component, newComponent);
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
function generateRegex(component, style) {
|
|
9
9
|
switch (style) {
|
|
10
10
|
case "prop":
|
|
11
|
-
return new RegExp(`<${component}
|
|
11
|
+
return new RegExp(`<${component}[^\/|<]+`, "gm");
|
|
12
12
|
case "component":
|
|
13
13
|
return new RegExp(`${component}\\W`, "gm");
|
|
14
14
|
case "web-component":
|
|
15
15
|
return new RegExp(`${component}\\b[^-]`, "gm");
|
|
16
16
|
case "absolute":
|
|
17
|
-
return new RegExp(`<${component}
|
|
17
|
+
return new RegExp(`<${component}[^\/|<]+`, "gm");
|
|
18
18
|
case "absolute-props":
|
|
19
|
-
return new RegExp(`${component}
|
|
19
|
+
return new RegExp(`${component}`, "gm");
|
|
20
20
|
case "test-simple":
|
|
21
21
|
return new RegExp(`[[.]${component}\\b`, "gm");
|
|
22
22
|
}
|