A few examples on jscodeshift codemods with tests.
npm start
Run npm start
to start an interactive CLI where you will be prompted for:
- the codemod/transform to run
- the input file to transform
- options to be passed to the codemod/transform
that will be run via jscodeshift
.
npm run lint
Run npm run lint
to type-check .ts
files and run linting across .js
and .ts
files via eslint
.
npm test
Run npm test
to do a one-time pass of Jest unit tests with coverage.
npm run jest:projects
Run npm run jest:projects
to do a one-time pass of ESLint linting, and Jest unit tests with coverage.
When developing, run npm run jest:projects:watch
which will validate ESLint linting and Jest unit tests as you develop and change code.
The repository has been tested to work in Node 12.
- Jscodeshift (codemods)
- TypeScript (type-checking/transpiling)
- Jest (testing & code coverage)
- ESLint (linting)
- Prettier (code formatting)
- Inquirer (interactive command line user interface)
- Renovate (dependency update)
- GitHub Actions (continuous integration)
- jscodeshift
- recast (used by
jscodeshift
to transform code into an abstract syntax tree (AST)) - ast-types (used by
jscodeshift
to provide typescript typings within the abstract syntax tree - AST Explorer
- Awesome jscodeshift (curated list of
jscodeshift
references) - github.com/elliottsj/jscodeshift-typescript-example
- github.com/cpojer/js-codemod
- skovy.dev - Creating a custom transform for jscodeshift
- Medium - Kacper Kula - Metaprogramming in JS: Write your first codemod!
- katilius.dev - Writing Javascript Codemods and Understanding AST Easily
The repository is available as open source under the terms of the MIT License.