Giter VIP home page Giter VIP logo

jscodemigrate's Introduction

Migrate your code like you do with your database!

Greenkeeper badge

Join the chat at https://gitter.im/brysgo/jscodemigrate

Dependency Status Circle CI

This is a simple wrapper around jscodeshift that give you a migration like interface.

Install in your project: npm install jscodemigrate --save-dev

Generate your first codemod:

jscodemigrate g switch-to-es6-classes

And you're off! Look in codemods/ to see your newly generated jscodemigration.

I would recommended taking a look at the template, and also js-codemod for ideas.

Pull in codemigrations from npm dependencies

jscodemigrate deps

Differences from writing jscodeshift

module.exports = {
  // Function to export is called transform
  transform: ({file, root, api, options}) => {
    // All the variables are passed in an options hash
    // Included with the usually is a root variable
    // (so that each migration doens't need to reparse the file)
    const j = api.jscodeshift;
    const {expression, statement, statements} = j.template;

    const printOptions = options.printOptions || {};

    const didTransform = true;
    
    root.find(j.Identifier).replaceWith(
      p => j.identifier(p.node.name.split('').reverse().join(''))
    )
    
    // You'll notice a return hash instead of the usual resulting source string
    return {
      didTransform,
      root,
      printOptions
    };
  }
}

Configuration

.codemodrc file

{ // These options mostly mirror jscodeshift's command line args
  "paths": [ "src/", "tests/", "special/file.js" ], // Paths to search when doing codemods
  "extensions": "js,es6" // Comma separated extensions to consider
}

Per code migration config

module.exports = {
  moduleApiChange: true, // Tell jscodemigrate to pull this into dependencies
  paths: [ "tests/" ], // even if your .codemodrc file looks in all your files, this will only run in 'tests/' directory
  // Tranform is the only thing that isn't optional
  transform: ({file, root, api, options}) => {
    ...
  }
}

Made possible by

jscodemigrate's People

Contributors

brysgo avatar gitter-badger avatar greenkeeper[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.