> For the complete documentation index, see [llms.txt](https://notes.lirenxn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.lirenxn.com/2020/wk-notes-01-10-codemod.md).

# Wk-notes-01-10-codemod

### A Confusion

`nodemon` is a **js lib** used for node that watch the files change and reload.

'Codemods' are **scripts** used to rewrite other scripts.

#### Codemod

An advanced find-and-replace and a better one than 'sed'.

**`jscodeshift`**

Batch javascript code manipulating providing its ast. A wrapper of `recast` (a AST-to-AST tool)

```javascript
// transform-script.js
export default (fileInfo, api) => {
  const j = api.jscodeshift;

  const root = j(fileInfo.source)

  return root.find(j.CallExpression, {
      callee: {
        type: 'MemberExpression',
        object: { type: 'Identifier', name: 'console' },
      },
    }
  )
  .remove()
  .toSource();
};
```
