Giter Site home page Giter Site logo

Comments (5)

eventualbuddha avatar eventualbuddha commented on August 19, 2024

There's no way to do it from the CLI, and unfortunately @codemod/cli doesn't expose enough to make it easy to do programmatically either. If I exposed CLIEngine and ConfigBuilder you could make a script like so to do what you want:

// This does NOT work with any released version yet.
import { CLIEngine, ConfigBuilder } from '@codemod/cli'

const config = new ConfigBuilder()
  .ignore((path: string, basename: string) => {
    // return false to ignore any path you want
  })
  .addSourcePath('./packages')
  .addLocalPlugin('my-codemod-package')
  .build()

const engine = new CLIEngine(config)
await engine.run()

That's probably not what you really wanted though. So instead, I just made #697 to ignore node_modules by default. It'll be published soon.

from codemod.

eventualbuddha avatar eventualbuddha commented on August 19, 2024

Published in @codemod/cli v2.2.1.

from codemod.

RIP21 avatar RIP21 commented on August 19, 2024

Awesome, thanks :) That makes sense IMO as I can't really imagine somebody running a codemod against node_modules :)
Prettier, babel all those are ignoring it by default AFAIR so it makes sense :)

About a programmatic use case that would be also pretty helpful. Especially for some internal CLI tools for migrations and stuff.
Like you install company-name-cli and then run company-name-cli codemod migrate-internal-lib-v4-to-v5 --dir ./my-app
And inside you build this CLI engine and run codemod against the source dir given.
Sounds redundant :) But on a big scale, you want it to be as easy as possible to make people actually using it :)

from codemod.

eventualbuddha avatar eventualbuddha commented on August 19, 2024

Do you have a specific example of how you'd use it? I'm happy to expose an API to make it easier.

from codemod.

RIP21 avatar RIP21 commented on August 19, 2024

Exactly how you wrote above.

I'm developing a company wide CLI that has a lot of stuff in it, like scaffolding of libraries, apps, microfrontends and potentially other handy tools for maintaining, migration and refactorings.

And for now if we run codemod it requires few steps, installing of at least 2 dependencies, a plugin and a CLI and then running this cli with some particular flags like prettier etc. It's a simple task, but for many even reading 4-5 steps README is too much. So in order to simplify all that having it all abstracted away into a tool, like create-react-app that will install all the recommended codemods under the hood, proactively will ask what codemod person wants, then dir and all is done, will be the best thing.

So as an example.

cli codemod

Select codemod you want to apply:
fix-this
migrate-that
rename-that

Please provide a directory with the source files:./src

Working... ⚒ 

//Output of codemod is here

It's all in interactive shell like Yeoman or similar.
All defaults, like formatter, what's the plugin, or what's the options of the plugin, also can be abstracted away, or a choice can be given if it's not against our standards.

So as you can run babel or prettier, webpack programmatically running codemod the same way would be awesome.

Hope that I explained good enough :) From the phone, so sorry if not too much details.

from codemod.

Related Issues (20)

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.