deriv-codemod
is a tool for helping migrate code. It uses jscodeshift internally to transform the source code.
Installation
deriv-codemod
requires Node.js v14+ to run.
To install globally:
npm i -g deriv-codemod
Just run the below command to get started.
deriv-codemod
List of codemods available
-
Change extension
- It simply modifies the extension of the file.
-
Convert proptypes to TS
- It converts React
propTypes
to Typescript type. - The things it does are:
- Remove prop-types import from the import section.
- Collects the component name and the list of properties and their type in propTypes.
- Generates a TS type based on component name and collected list of properties and their type.
- Inserts the generated type as a type annotation to the props param of the component. It also supports destructured props, props in React.memo and React.forwardRef.
- Removes the propTypes.
- It also supports multiple components in the same file.
- React
propTypes
to TS type:
- Converts all the primitive types such as boolean, string, number to respective TS type.
- For
PropTypes.func
, it will insert an empty anonymous arrow fn type () => void
. - For
PropTypes.object
or PropTypes.array
, it maps unknown as respective TS type. - It also supports
PropTypes.oneOfTypes
which will map it to TS union types.
Local development
Want to contribute? Great!
Open your Terminal and run the below command.
To install dependencies:
npm install
To build:
npm run build
Please check jscodeshift docs before writing a codemod.