GithubHelp home page GithubHelp logo

obweger / modster Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 1.0 198 KB

A plugin system and CLI for consuming and executing jscodeshift codemods, in a way that is not terrible.

License: MIT License

TypeScript 99.10% JavaScript 0.90%
codemod codemods plugin jscodeshift cli

modster's Introduction

Modster

Codemoding, the easy way.

Modster is a plugin system and CLI for consuming and executing jscodeshift codemods, in a way that is not terrible.

In Modster, you pick your codemod from a list of codemods, answer a few questions to have it configured, choose a file or directory to run against - and off you go!

Easy? Yes, much. ✌️

Modster in action

See the full run.

Modster in full action

Installation

E.g. using yarn:

$ yarn install modster
$ yarn modster

Configuration

.codemods.js

Modster is configured via a configuration file, typically named .codemods.js. It is expected to export an object with the following fields:

Field Type Required Description
packageManager string Your package manager; typically yarn or npm.
sourceDirectory string The directory on which you want codemods to operate. You can further limit the scope of a codemod when running Modster.
extensions string[] The file extensions you want to run codemods against. Passed to jscodeshift as the --ext option.
parser string The parser to use for parsing source files. One of babel | babylon | flow | ts | tsx. Passed to jscodeshift as the --parser option.
plugins string[] A list of Modster plugins, following the eslint-style plugin naming convention. See below for a list of existing plugins and how to create your own plugins.
postUpdateTasks function A function of the shape (updatedFiles: string[]) => { name: string; cmd: string }[], receiving the list of files modified by a codemod, and return a list of tasks to be executed. Every task has a name (e.g. prettier) and a command to be executed (e.g. yarn run prettier ...).
Like so.
  export default {
      packageManager: 'yarn',
      extensions: ['tsx', 'ts'],
      sourceFolder: 'src',
      parser: 'tsx',
      plugins: [
          'hello-world'
      ],
      postUpdateTask: (files: string[]) => [
          {
              name: 'eslint autofix',
              command: `yarn eslint ${files.join(' ')} --ext tsx,ts --fix`
          }
      ]
  }

CLI options

Modster takes two optional CLI options, --config <path-to-file>, and --dry.

Option Description
--config <path-to-file> The path to Modster's configuration file, relative to process.cwd(). Defaults to ./codemods.
--dry If set, runs jscodeshift in a dry run. Post-update tasks are printed but not executed.

Plugins

Modster uses a plugin system to consume codemods, similar to how e.g. eslint consumes linting rules. It is important to understand that Modser comes with no built-in codemod functionality; running Modster without plugins therefore doesn't make a huge amount of sense. But good news! - using and even writing Modster plugins is dead simple:

Existing plugins

To consume a Modster plugin, you simply install it as an npm package, e.g. using yarn:

$ yarn install modster-plugin-hello-world

... and add it to your .codemods.js, following the eslint-style plugin naming convention:

module.exports = {
    // ...
    plugins: [
        // ...
+      'hello-world'
    ]
}

See below for a list of Modster plugins:

Plugin Description
Hello World A minimal plugin example; mostly a reference for developing new plugins.

To add a plugin to this list, please raise a PR.

Developing plugins

See Developing Modster plugins.

Contributions

Yes please!

modster's People

Contributors

obweger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.