Skip to content

Fullscript/js-transforms

 
 

Repository files navigation

js-transforms

Welcome to Fullscript's repository for JS transforms. This repo contains transforms for large codebase refactors. It internally uses babel for parsing code and recast for transforming the resulting Abstract Syntax Tree (AST).

NOTE: This code is provided as is, we don't guarantee that we will support any feature requests or bug fixes.

Installation

Step 1

Clone your repo locally:

git clone [email protected]:Fullscript/js-transforms.git

Step 2

Go into the folder

cd js-transforms

Step 3

Install the dependencies

yarn install

Usage

You can find all available CLI options by running the followin:

yarn transform --help

Or if you prefer to read the available options here, jump to the CLI section.

Available Transforms

colorsToTheme

Used for converting colors to Emotion theme/tokens.

yarn transform colorsToTheme '../hw-admin/app/javascript/**/*.styles.ts*' --options COLOR.TO.REPLACE THEME.TOKEN.REPLACEMENT

Example:

yarn transform colorsToTheme '../hw-admin/app/javascript/**/*.styles.ts*' --options colors.green.base theme.success.textBase

createMockToObjectParams

Was used for converting

createMock("Patient", { firstName: "John" });

// TO

createMock({ typeName: "Patient", overrides: { firstName: "John" } });

Usage:

yarn transform createMockToObjectParams '../hw-admin/app/javascript/**/*.spec.ts*'

createFragmentToCreateMock

For converting create*Fragment calls to equivalent createMock calls. Requires you to specify the create*Fragment to convert along with its equivalent GQL type.

Usage:

yarn transform createFragmentToCreateMock '../hw-admin/app/javascript/**/*.spec.ts*' --options <create*Fragment> <GQLType>

Example:

yarn transform createFragmentToCreateMock '../hw-admin/app/javascript/**/*.spec.ts*' --options createPatientFragment Patient

lTranslations

For converting t("common:foobar") to the equivalent l translation t(l.common.foobar)

Usage:

yarn transform lTranslations '../hw-admin/app/javascript/<namespace>/**/*.ts*' --options <importPathForl>

Example:

yarn transform lTranslation '../hw-admin/app/javascript/patient/**/*.ts*' --options @patient/locales

addEslintDisableComment

To temporarily suppress custom eslint rule to prevent using the manually declared GraphQL hook

Usage:

yarn transform addEslintDisableComment '../hw-admin/app/javascript/<namespace>/**/*.ts*' 

Example:

yarn transform addEslintDisableComment '../hw-admin/app/javascript/patient/**/*.query.ts*'

CLI

The CLI usage is as follows:

yarn transform <transformName> <filesToTransformAsGlob> --dry-run --options
  • transformName: Any of the transforms specified in Available Transforms
  • filesToTransformAsGlob: A glob pattern in quotations identifying files to run the transform against. Ex: '../projectDir/src/**/*.tsx'
  • --dry-run or -d for short: Output transform result to console rather than writing changes to files. Useful during development.
  • --options: An array of optional parameters to pass into the specified transform. Some transforms require additional user input, this is how you specify that. See colorsToTheme for an example.

About

JS code transforms used to speed up lengthy refactors

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

  • JavaScript 99.8%
  • TypeScript 0.2%