@commercetools-frontend/codemod 0.1.0 → 0.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/README.md CHANGED
@@ -12,8 +12,20 @@ Codemod transformations for Custom Applications.
12
12
  $ npx @commercetools-frontend/codemod <transform> <glob_pattern>
13
13
  ```
14
14
 
15
+ We recommend to run `prettier` on the modified files to preserve the formatting configured on your project. For example, you can run `prettier --write $(git diff --name-only)`.
16
+
17
+ > If you are using `lint-staged` there is a high chance that you already run `prettier` on the staged files. Therefore, you don't need to run it manually.
18
+
15
19
  ## Transforms
16
20
 
21
+ ### `remove-deprecated-modal-level-props`
22
+
23
+ Remove deprecated `level` and `baseZIndex` props from modal page components.
24
+
25
+ ```
26
+ $ npx @commercetools-frontend/codemod remove-deprecated-modal-level-props 'src/**/*.js'
27
+ ```
28
+
17
29
  ### `rename-js-to-jsx`
18
30
 
19
31
  Rename `.js` files using React JSX syntax to `.jsx`.
package/build/cli.js CHANGED
@@ -25,7 +25,8 @@ Global options:
25
25
 
26
26
  Transforms:
27
27
 
28
- rename-js-to-jsx Rename ".js" files using React JSX syntax to ".jsx".
28
+ remove-deprecated-modal-level-props Remove deprecated "level" and "baseZIndex" props from modal page components.
29
+ rename-js-to-jsx Rename ".js" files using React JSX syntax to ".jsx".
29
30
  `);
30
31
  process.exit(0);
31
32
  }
@@ -36,6 +37,7 @@ Transforms:
36
37
  };
37
38
  const execute = async () => {
38
39
  switch (transform) {
40
+ case 'remove-deprecated-modal-level-props':
39
41
  case 'rename-js-to-jsx': {
40
42
  const transformPath = path_1.default.join(__dirname, `transforms/${transform}.js`);
41
43
  await runJscodeshift(transformPath, files, {
@@ -47,6 +49,7 @@ Transforms:
47
49
  '**/build/**',
48
50
  ],
49
51
  parser: 'tsx',
52
+ verbose: 0,
50
53
  dry: flags['dry-run'],
51
54
  });
52
55
  break;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const componentNamesWithDeprecatedZIndexProps = [
4
+ 'InfoModalPage',
5
+ 'FormModalPage',
6
+ 'CustomFormModalPage',
7
+ 'TabularModalPage',
8
+ ];
9
+ const deprecatedPropsToBeRemoved = ['level', 'baseZIndex'];
10
+ function removeDeprecatedModalLevelProps(file, api, options) {
11
+ const j = api.jscodeshift;
12
+ const root = j(file.source);
13
+ let hasModifications = false;
14
+ function removeDepreactedPropsFromComponent(path) {
15
+ const node = path.node;
16
+ if (node.name.type === 'JSXIdentifier' &&
17
+ componentNamesWithDeprecatedZIndexProps.includes(node.name.name)) {
18
+ node.attributes =
19
+ node.attributes?.filter((attribute) => {
20
+ if (attribute.type === 'JSXAttribute' &&
21
+ attribute.name.type === 'JSXIdentifier') {
22
+ const hasDeprecatedAttribute = deprecatedPropsToBeRemoved.includes(attribute.name.name);
23
+ hasModifications = true;
24
+ return !hasDeprecatedAttribute;
25
+ }
26
+ return true;
27
+ }) ?? [];
28
+ }
29
+ }
30
+ root.find(j.JSXOpeningElement).forEach(removeDepreactedPropsFromComponent);
31
+ return hasModifications ? root.toSource(options) : null;
32
+ }
33
+ exports.default = removeDeprecatedModalLevelProps;
@@ -20,6 +20,6 @@ function renameJsToJsx(file, api, options) {
20
20
  }
21
21
  }
22
22
  }
23
- return root.toSource(options);
23
+ return null;
24
24
  }
25
25
  exports.default = renameJsToJsx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/codemod",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Codemod transformations for Custom Applications",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -30,9 +30,9 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@tsconfig/node14": "^1.0.1",
33
- "@types/jscodeshift": "0.11.0",
33
+ "@types/jscodeshift": "0.11.5",
34
34
  "rimraf": "3.0.2",
35
- "typescript": "4.6.3"
35
+ "typescript": "4.6.4"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=14"