Giter Club home page Giter Club logo

codemods's Introduction

Linguijs Codemods

This repository contains a collection of codemod scripts for use with JSCodeshift that help update Lingui APIs.


Usage

npx @lingui/codemods <transform> <path> [...options]

  • transform - name of transform, see available transforms below.
  • path - files or directory to transform
  • use the --dry option for a dry-run
  • use --print to print the output for comparison
  • use --remove-unused-imports to remove unused imports once finished the codemod

This will start an interactive wizard, and then run the specified transform.

Included Transforms

v2-to-v3

Converts some outdated standards from lingui version 2.x.x to new features and best practices introduced in lingui version 3.x.x

npx @lingui/codemods v2-to-v3 <path>

split-macro-imports

Converts @lingui/macro imports to @lingui/core/macro and @lingui/react/macro.

npx @lingui/codemods split-macro-imports <path>

Visit the Migration guide from 4.x to 5.x for more information.

jscodeshift options

To pass more options directly to jscodeshift, use --jscodeshift="...". For example:

npx @lingui/codemods --jscodeshift="--run-in-band --verbose=2"

See all available options here.

Recast Options

Options to recast's printer can be provided through jscodeshift's printOptions command line argument

npx @lingui/codemods <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"double\"}'"

Usage without params

A CLI is built-in to help you migrate your codebase, will ask you some questions:

➜  project git:(master) npx @lingui/codemods
? On which files or directory should the codemods be applied? for ex: ./src
? Which dialect of JavaScript do you use? for ex: JavaScript | Typescript | JavaScript with Flow
? Which transform would you like to apply? for ex: `v2-to-v3`

License

@lingui/codemods is MIT licensed.

codemods's People

Contributors

andrii-bodnar avatar dependabot[bot] avatar donocode avatar martijnhols avatar semantic-release-bot avatar semoal avatar thekip avatar tricoder42 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

codemods's Issues

Write a codemod to migrate from i18next to lingui

If we could write a codemod for migrating i18next projects to lingui with one command, probably old projects with i18next will think to move to Lingui πŸ‘πŸ»

For my side, I don't have so much experience with i18next, so give me some weeks to analyze how does it works to write the required mods for lingui :)

Mods

  • ,,,

V3 --> V4?

Are there plans for a V3 --> V4 codemod? The major breaking change I see is that the effective meaning of t has changed, so that where it used to just do the translation, now it gives you a hash. If I understand correctly, we need to add const { i18n } = useLingui(); and replace

t`hello`

with

i18n._(msg(`hello`))

(ref). But perhaps that last step is just a regex search replace, and there's no need for a codemod?

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Automated release explanation

How does it works?

semantic-release package contains all the necessary actions to:

  • @semantic-release/commit-analyzer: Will analyze all the commits since the latest tagged release and will detect what version needs to be increased to match the commits spec.
    For example of commits and his response:

    • fix(): commit : x.x.1 - Patch

    • feat(): commit : x.1.x - Feature

    • `perf(pencil): remove graphiteWidth option

      BREAKING CHANGE: The graphiteWidth option has been removed.
      The default graphite width of 10mm is always used for performance reasons.
      ` : 1.x.x - Breaking change

  • @semantic-release/release-notes-generator: Generate release notes for the commits added since the last release with conventional-changelog

  • @semantic-release/changelog: Create or update the changelog file in the local project repository

  • @semantic-release/npm: Publish the package on the npm registry

  • @semantic-release/git: Push a release commit and tag, including configurable files

  • @semantic-release/github: Publish a GitHub release

What's the best strategy?

All the pull requests merged should be merged following the conventional-commits standard in that way we'll create a history since the latest release. (if some user is not following the standard is a best practice to squash merge to overwrite the pull request history, and add a new commit name)

So when we're ready to deploy our version we just have to move up to Github Actions tab and deploy manually the version.

Screenshot 2020-10-26 at 12 37 44

Screenshot 2020-10-26 at 12 37 48

What happens once we triggered that manual action?

yarn release will be executed and of course all the above steps mentioned.

Will publish to npm the package, create a CHANGELOG.md, update the package.json version, create a git tag, and a commit with all the changes since the latest release (changelog, package.json..)

If some user has specified that some commit fixes any issue and in the commit appears the id of the issue, automatically semantic-release-bot will close that issue πŸ†’

Examples

I use this strategy on big libraries like http://github.com/rematch/rematch/, and other tiny libraries like https://github.com/semoal/themeprovider-storybook, and for me fits perfectly =)

Pending tasks

  • Create a secret on project settings with a valid npm token to publish to npm. (I can't do it by permissions, can't access to project settings)
    NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

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.