@octaviaflow/upgrade 1.0.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/README.md +97 -0
- package/bin/carbon-upgrade.js +48 -0
- package/cli.js +53573 -0
- package/package.json +56 -0
- package/telemetry.yml +17 -0
- package/transforms/ARCHITECTURE.md +47 -0
- package/transforms/__testfixtures__/featureflag-deprecate-flags-prop.input.js +143 -0
- package/transforms/__testfixtures__/featureflag-deprecate-flags-prop.output.js +133 -0
- package/transforms/__testfixtures__/ibm-products-update-userprofileimage.input.js +57 -0
- package/transforms/__testfixtures__/ibm-products-update-userprofileimage.output.js +50 -0
- package/transforms/__testfixtures__/icons-react-size-prop-object-key.input.js +25 -0
- package/transforms/__testfixtures__/icons-react-size-prop-object-key.output.js +25 -0
- package/transforms/__testfixtures__/icons-react-size-prop-rename.input.js +53 -0
- package/transforms/__testfixtures__/icons-react-size-prop-rename.output.js +53 -0
- package/transforms/__testfixtures__/icons-react-size-prop-with-prop.input.js +25 -0
- package/transforms/__testfixtures__/icons-react-size-prop-with-prop.output.js +28 -0
- package/transforms/__testfixtures__/refactor-light-to-layer.input.js +23 -0
- package/transforms/__testfixtures__/refactor-light-to-layer.output.js +23 -0
- package/transforms/__testfixtures__/refactor-to-callout.input.js +34 -0
- package/transforms/__testfixtures__/refactor-to-callout.output.js +32 -0
- package/transforms/__testfixtures__/refactor-to-callout2.input.js +13 -0
- package/transforms/__testfixtures__/refactor-to-callout2.output.js +13 -0
- package/transforms/__testfixtures__/refactor-to-callout3.input.js +14 -0
- package/transforms/__testfixtures__/refactor-to-callout3.output.js +14 -0
- package/transforms/__testfixtures__/refactor-to-callout4.input.js +12 -0
- package/transforms/__testfixtures__/refactor-to-callout4.output.js +12 -0
- package/transforms/__testfixtures__/size-prop-update.input.js +152 -0
- package/transforms/__testfixtures__/size-prop-update.output.js +152 -0
- package/transforms/__testfixtures__/small-to-size-prop.input.js +20 -0
- package/transforms/__testfixtures__/small-to-size-prop.output.js +19 -0
- package/transforms/__testfixtures__/sort-prop-types.input.js +16 -0
- package/transforms/__testfixtures__/sort-prop-types.output.js +16 -0
- package/transforms/__testfixtures__/sort-prop-types2.input.js +16 -0
- package/transforms/__testfixtures__/sort-prop-types2.output.js +16 -0
- package/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.input.js +17 -0
- package/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.output.js +17 -0
- package/transforms/__testfixtures__/update-carbon-icons-react-import-to-carbon-react.input.js +17 -0
- package/transforms/__testfixtures__/update-carbon-icons-react-import-to-carbon-react.output.js +17 -0
- package/transforms/__tests__/featureflag-deprecate-flags-prop-test.js +15 -0
- package/transforms/__tests__/ibm-products-update-userprofileimage-test.js +21 -0
- package/transforms/__tests__/icons-react-size-prop.js +67 -0
- package/transforms/__tests__/refactor-light-to-layer-test.js +14 -0
- package/transforms/__tests__/refactor-to-callout.js +18 -0
- package/transforms/__tests__/size-prop-update-test.js +15 -0
- package/transforms/__tests__/small-to-size-test.js +15 -0
- package/transforms/__tests__/sort-prop-types-test.js +16 -0
- package/transforms/__tests__/update-carbon-components-react-import-to-scoped.js +15 -0
- package/transforms/__tests__/update-carbon-icons-react-import-to-carbon-react.js +15 -0
- package/transforms/featureflag-deprecate-flags-prop.js +89 -0
- package/transforms/ibm-products-update-userprofileimage.js +134 -0
- package/transforms/icons-react-size-prop.js +327 -0
- package/transforms/refactor-light-to-layer.js +117 -0
- package/transforms/refactor-to-callout.js +160 -0
- package/transforms/size-prop-update.js +143 -0
- package/transforms/small-to-size-prop.js +59 -0
- package/transforms/sort-prop-types.js +91 -0
- package/transforms/update-carbon-components-react-import-to-scoped.js +42 -0
- package/transforms/update-carbon-icons-react-import-to-carbon-react.js +42 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
//prettier-ignore
|
|
11
|
+
import { Button } from "@octaviaflow/react";
|
|
12
|
+
//prettier-ignore
|
|
13
|
+
import { Tile, Tooltip } from "@octaviaflow/react";
|
|
14
|
+
//prettier-ignore
|
|
15
|
+
import CodeSnippet from "@octaviaflow/react";
|
|
16
|
+
import Something from 'somewhere-else';
|
|
17
|
+
import { SomethingElse } from 'somewhere-else';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
//prettier-ignore
|
|
11
|
+
import { Add } from '@octaviaflow/icons-react';
|
|
12
|
+
//prettier-ignore
|
|
13
|
+
import { Settings, Search } from '@octaviaflow/icons-react';
|
|
14
|
+
//prettier-ignore
|
|
15
|
+
import Icons from '@octaviaflow/icons-react';
|
|
16
|
+
import Something from 'somewhere-else';
|
|
17
|
+
import { SomethingElse } from 'somewhere-else';
|
package/transforms/__testfixtures__/update-carbon-icons-react-import-to-carbon-react.output.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
//prettier-ignore
|
|
11
|
+
import { Add } from "@octaviaflow/react/icons";
|
|
12
|
+
//prettier-ignore
|
|
13
|
+
import { Settings, Search } from "@octaviaflow/react/icons";
|
|
14
|
+
//prettier-ignore
|
|
15
|
+
import Icons from "@octaviaflow/react/icons";
|
|
16
|
+
import Something from 'somewhere-else';
|
|
17
|
+
import { SomethingElse } from 'somewhere-else';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'featureflag-deprecate-flags-prop');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Copyright IBM Corp. 2021, 2024
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
20
|
+
|
|
21
|
+
defineTest(__dirname, 'ibm-products-update-userprofileimage');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
describe('icons-react-size-prop', () => {
|
|
16
|
+
let mock;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
mock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
mock.mockRestore();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
defineTest(
|
|
27
|
+
__dirname,
|
|
28
|
+
'icons-react-size-prop',
|
|
29
|
+
{
|
|
30
|
+
printOptions: {
|
|
31
|
+
quote: 'single',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
'icons-react-size-prop-rename',
|
|
35
|
+
{
|
|
36
|
+
parser: 'babylon',
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
defineTest(
|
|
41
|
+
__dirname,
|
|
42
|
+
'icons-react-size-prop',
|
|
43
|
+
{
|
|
44
|
+
printOptions: {
|
|
45
|
+
quote: 'single',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
'icons-react-size-prop-with-prop',
|
|
49
|
+
{
|
|
50
|
+
parser: 'babylon',
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
defineTest(
|
|
55
|
+
__dirname,
|
|
56
|
+
'icons-react-size-prop',
|
|
57
|
+
{
|
|
58
|
+
printOptions: {
|
|
59
|
+
quote: 'single',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
'icons-react-size-prop-object-key',
|
|
63
|
+
{
|
|
64
|
+
parser: 'babylon',
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
13
|
+
|
|
14
|
+
defineTest(__dirname, 'refactor-light-to-layer');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'refactor-to-callout');
|
|
16
|
+
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout2');
|
|
17
|
+
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout3');
|
|
18
|
+
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout4');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'size-prop-update');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'small-to-size-prop');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'sort-prop-types');
|
|
16
|
+
defineTest(__dirname, 'sort-prop-types', null, 'sort-prop-types2');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'update-carbon-components-react-import-to-scoped');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { defineTest } = require('jscodeshift/dist/testUtils');
|
|
14
|
+
|
|
15
|
+
defineTest(__dirname, 'update-carbon-icons-react-import-to-carbon-react');
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Copyright IBM Corp. 2024
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*
|
|
16
|
+
* Migrate the `flags` object prop to individual boolean props
|
|
17
|
+
*
|
|
18
|
+
* Transforms:
|
|
19
|
+
*
|
|
20
|
+
* <FeatureFlags flags={{ 'enable-v12-tile-default-icons': true }}>
|
|
21
|
+
*
|
|
22
|
+
* Into:
|
|
23
|
+
*
|
|
24
|
+
* <FeatureFlags enableV12TileDefaultIcons>
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
const defaultOptions = {
|
|
30
|
+
quote: 'single',
|
|
31
|
+
trailingComma: true,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//This list can be updated as needed, if any flags are made true by default
|
|
35
|
+
const flagsToRemove = [
|
|
36
|
+
'enable-v11-release',
|
|
37
|
+
'enable-css-custom-properties',
|
|
38
|
+
'enable-css-grid',
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
function transform(fileInfo, api, options) {
|
|
42
|
+
const { jscodeshift: j } = api;
|
|
43
|
+
const root = j(fileInfo.source);
|
|
44
|
+
const printOptions = options.printOptions || defaultOptions;
|
|
45
|
+
if (
|
|
46
|
+
!root.find(j.JSXOpeningElement, { name: { name: 'FeatureFlags' } }).size()
|
|
47
|
+
) {
|
|
48
|
+
return null; // if no FeatureFlags found, don't modify & return the file
|
|
49
|
+
}
|
|
50
|
+
root
|
|
51
|
+
.find(j.JSXOpeningElement, { name: { name: 'FeatureFlags' } })
|
|
52
|
+
.forEach((path) => {
|
|
53
|
+
const flagsAttribute = path.node.attributes.find(
|
|
54
|
+
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'flags'
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (flagsAttribute?.value?.expression?.type === 'ObjectExpression') {
|
|
58
|
+
const properties = flagsAttribute.value.expression.properties;
|
|
59
|
+
|
|
60
|
+
// Filter out flags to remove
|
|
61
|
+
const filteredProperties = properties.filter((prop) => {
|
|
62
|
+
const keyName =
|
|
63
|
+
prop.key.type === 'Identifier' ? prop.key.name : prop.key.value;
|
|
64
|
+
return !flagsToRemove.includes(keyName);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Convert remaining flags to boolean props
|
|
68
|
+
const newAttributes = filteredProperties
|
|
69
|
+
.filter((flag) => flag.value.value === true)
|
|
70
|
+
.map((flag) => {
|
|
71
|
+
const flagName =
|
|
72
|
+
flag.key.type === 'Identifier' ? flag.key.name : flag.key.value;
|
|
73
|
+
const propName = flagName.replace(/-(\w)/g, (_, c) =>
|
|
74
|
+
c.toUpperCase()
|
|
75
|
+
);
|
|
76
|
+
return j.jsxAttribute(j.jsxIdentifier(propName));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
path.node.attributes = [
|
|
80
|
+
...path.node.attributes.filter((attr) => attr.name.name !== 'flags'),
|
|
81
|
+
...newAttributes,
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return root.toSource(printOptions);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = transform;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright OctaviaFlow
|
|
3
|
+
* Author: Vishal Kumar
|
|
4
|
+
* Created: 11/November/2025
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Copyright IBM Corp. 2021, 2024
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*
|
|
16
|
+
* Rewrites UserProfileImage to UserAvatar
|
|
17
|
+
*
|
|
18
|
+
* Transforms:
|
|
19
|
+
*
|
|
20
|
+
* <UserProfileImage />
|
|
21
|
+
*
|
|
22
|
+
* Into:
|
|
23
|
+
*
|
|
24
|
+
* <UserAvatar />
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
const transform = (fileInfo, api) => {
|
|
30
|
+
const j = api.jscodeshift;
|
|
31
|
+
const root = j(fileInfo.source);
|
|
32
|
+
let shouldImportUser = false;
|
|
33
|
+
let shouldImportGroup = false;
|
|
34
|
+
|
|
35
|
+
const ensureImport = (identifierName) => {
|
|
36
|
+
const importDeclaration = j.importDeclaration(
|
|
37
|
+
[j.importSpecifier(j.identifier(identifierName))],
|
|
38
|
+
j.literal('@octaviaflow/react/icons')
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const existingImport = root
|
|
42
|
+
.find(j.ImportDeclaration, {
|
|
43
|
+
source: { value: '@octaviaflow/react/icons' },
|
|
44
|
+
})
|
|
45
|
+
.filter((path) => {
|
|
46
|
+
return path.node.specifiers.some(
|
|
47
|
+
(specifier) => specifier.imported.name === identifierName
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (existingImport.size() === 0) {
|
|
52
|
+
root.find(j.Program).get('body', 0).insertBefore(importDeclaration);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
// Transform UserProfileImage to UserAvatar
|
|
56
|
+
root
|
|
57
|
+
.find(j.JSXElement, {
|
|
58
|
+
openingElement: { name: { name: 'UserProfileImage' } },
|
|
59
|
+
})
|
|
60
|
+
.forEach((path) => {
|
|
61
|
+
// Change the component name
|
|
62
|
+
path.node.openingElement.name.name = 'UserAvatar';
|
|
63
|
+
if (path.node.closingElement) {
|
|
64
|
+
path.node.closingElement.name.name = 'UserAvatar';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const colorMapping = {
|
|
68
|
+
'light-cyan': 'order-1-cyan',
|
|
69
|
+
'dark-cyan': 'order-7-cyan',
|
|
70
|
+
'light-gray': 'order-2-gray',
|
|
71
|
+
'dark-gray': 'order-8-gray',
|
|
72
|
+
'light-green': 'order-3-green',
|
|
73
|
+
'dark-green': 'order-9-green',
|
|
74
|
+
'light-magenta': 'order-10-magenta',
|
|
75
|
+
'dark-magenta': 'order-10-magenta',
|
|
76
|
+
'light-purple': 'order-5-purple',
|
|
77
|
+
'dark-purple': 'order-11-purple',
|
|
78
|
+
'light-teal': 'order-6-teal',
|
|
79
|
+
'dark-teal': 'order-12-teal',
|
|
80
|
+
};
|
|
81
|
+
const updatedAttributes = [];
|
|
82
|
+
// Update attributes
|
|
83
|
+
path.node.openingElement.attributes.forEach((attr) => {
|
|
84
|
+
if (attr.name.name === 'backgroundColor') {
|
|
85
|
+
if (colorMapping[attr.value.value]) {
|
|
86
|
+
attr.value.value = colorMapping[attr.value.value];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (attr.name.name === 'theme') {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (attr.name.name === 'initials') {
|
|
93
|
+
attr.name.name = 'name';
|
|
94
|
+
}
|
|
95
|
+
if (attr.name.name === 'kind' || attr.name.name === 'icon') {
|
|
96
|
+
const originalName = attr.name.name;
|
|
97
|
+
attr.name.name = 'renderIcon';
|
|
98
|
+
if (originalName === 'kind') {
|
|
99
|
+
if (attr.value.value === 'user') {
|
|
100
|
+
attr.value = j.jsxExpressionContainer(j.identifier('User'));
|
|
101
|
+
shouldImportUser = true;
|
|
102
|
+
} else if (attr.value.value === 'group') {
|
|
103
|
+
attr.value = j.jsxExpressionContainer(j.identifier('Group'));
|
|
104
|
+
shouldImportGroup = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
updatedAttributes.push(attr);
|
|
109
|
+
});
|
|
110
|
+
path.node.openingElement.attributes = updatedAttributes;
|
|
111
|
+
});
|
|
112
|
+
// Update import statement
|
|
113
|
+
root
|
|
114
|
+
.find(j.ImportDeclaration)
|
|
115
|
+
.filter((path) => path.node.source.value === '@octaviaflow/ibm-products')
|
|
116
|
+
.forEach((path) => {
|
|
117
|
+
path.node.specifiers.forEach((specifier) => {
|
|
118
|
+
if (specifier.imported.name === 'UserProfileImage') {
|
|
119
|
+
specifier.imported.name = 'UserAvatar';
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (shouldImportUser) {
|
|
125
|
+
ensureImport('User');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (shouldImportGroup) {
|
|
129
|
+
ensureImport('Group');
|
|
130
|
+
}
|
|
131
|
+
return root.toSource();
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
module.exports = transform;
|