diff --git a/bin/cli.js b/bin/cli.js index b6c9752..43dc38f 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -123,6 +123,13 @@ function Cli() { ) .action((target, command) => runTransform(target, command, program)); + program + .command("add-prop ") + .description("adds a new prop and value to the specified component") + .action((target, component, prop, value, command) => + runTransform(target, command, program, { component, prop, value }) + ); + program .command("rename-prop ") .description( diff --git a/transforms/add-prop/README.md b/transforms/add-prop/README.md new file mode 100644 index 0000000..a324b95 --- /dev/null +++ b/transforms/add-prop/README.md @@ -0,0 +1,46 @@ +# add-prop + +This universal codemod provides possibility to add any prop to any component. + +```diff +- ++ + +``` +## Usage + +`npx carbon-codemod add-prop ` + +### Examples + +### String +`npx carbon-codemod add-prop src carbon-react/lib/components/button ml "16px"` + +```diff +- ++ +``` + +### Number +`npx carbon-codemod add-prop src carbon-react/lib/components/button ml 2` + +```diff +- ++ +``` + +### Boolean - True +`npx carbon-codemod add-prop src carbon-react/lib/components/button hasBorder true` + +```diff +- ++ +``` + +### Boolean - False +`npx carbon-codemod add-prop src carbon-react/lib/components/button hasBorder false` + +```diff +- ++ +``` \ No newline at end of file diff --git a/transforms/add-prop/__testfixtures__/BooleanFalse.input.js b/transforms/add-prop/__testfixtures__/BooleanFalse.input.js new file mode 100644 index 0000000..45b4254 --- /dev/null +++ b/transforms/add-prop/__testfixtures__/BooleanFalse.input.js @@ -0,0 +1,3 @@ +import Button from "carbon-react/lib/components/button"; + +export const asFalse = () =>