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.
Clone your repo locally:
git clone [email protected]:Fullscript/js-transforms.git
Go into the folder
cd js-transforms
Install the dependencies
yarn install
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.
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
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*'
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
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
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*'
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.