Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mukeshsoni/codemods
code modifiers scripts which work with jscodeshift
https://github.com/mukeshsoni/codemods
Last synced: 24 days ago
JSON representation
code modifiers scripts which work with jscodeshift
- Host: GitHub
- URL: https://github.com/mukeshsoni/codemods
- Owner: mukeshsoni
- Created: 2018-04-22T05:33:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T14:35:02.000Z (almost 7 years ago)
- Last Synced: 2024-11-21T06:34:16.041Z (3 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - mukeshsoni/codemods - Adds a data-test-id attribute to all jsx html elements. (Frameworks / React.js)
README
# codemods
This repository contains a collection of codemod scripts for use with [JSCodeshift](https://github.com/facebook/jscodeshift) that transform your source code in useful ways.
### Setup & Run
1. `npm install -g jscodeshift`
1. `git clone https://github.com/mukeshsoni/codemods.git` or download a zip file from `https://github.com/mukeshsoni/codemods/archive/master.zip`
1. `jscodeshift -t `
* `codemod-script` - path to the transform file, see available scripts below;
* `path` - files or directory to transform;
* use the `-d` option for a dry-run and use `-p` to print the output for comparison;
* use the `--extensions` option if your files have different extensions than `.js` (for example, `--extensions js,jsx`);
* if you use flowtype, you might also need to use `--parser=flow`;
* see all available [jscodeshift options](https://github.com/facebook/jscodeshift#usage-cli).### Included Scripts
#### `jsx-add-data-test-id-attribute.js`
Adds a `data-test-id` attribute to all jsx html elements. Helpful for test writers to grab an element and simulate some action/event on it.
It does not add the attribute to custom components. Also, doesn't add the attribute if it already exists on an element.```sh
jscodeshift -t codemods/transforms/jsx-add-data-test-id-attribute.js
```E.g. - converts
```
Beautiful
```to
```
Beautiful
```