diff --git a/@navikt/aksel/src/codemod/migrations.ts b/@navikt/aksel/src/codemod/migrations.ts index 8474db4c94..ebd2f7df14 100644 --- a/@navikt/aksel/src/codemod/migrations.ts +++ b/@navikt/aksel/src/codemod/migrations.ts @@ -123,6 +123,12 @@ export const migrations: { value: "prop-deprecate", path: "darkside/prop-deprecate/prop-deprecate", }, + { + description: + "Update Box to to BoxNew (future Box) using the new token system", + value: "box-to-boxnew", + path: "box-to-boxnew/box-to-boxnew", + }, ], }; diff --git a/@navikt/aksel/src/codemod/transforms/box-to-boxnew/box-to-boxnew.ts b/@navikt/aksel/src/codemod/transforms/box-to-boxnew/box-to-boxnew.ts new file mode 100644 index 0000000000..a77386464f --- /dev/null +++ b/@navikt/aksel/src/codemod/transforms/box-to-boxnew/box-to-boxnew.ts @@ -0,0 +1,32 @@ +import type { API, FileInfo } from "jscodeshift"; +import { getLineTerminator } from "../../utils/lineterminator"; +import renameProps from "../../utils/rename-props"; +import { findComponentImport, findJSXElement } from "../spacing/spacing.utils"; + +// to look up in replacements +const deprecationMap = ["background", "borderColor", "shadow"]; + +export default function transformer(file: FileInfo, api: API) { + const j = api.jscodeshift; + const root = j(file.source); + + const toSourceOptions = getLineTerminator(file.source); + + const sourceName = findComponentImport({ + file, + j, + name: "Box", + packageType: "react", + }); + + if (!sourceName) { + return; + } + + for (const prop of deprecationMap) { + const jsx = findJSXElement({ root, j, name: sourceName }); + // conditional renameProps() + } + + return root.toSource(toSourceOptions); +} diff --git a/@navikt/aksel/src/codemod/transforms/box-to-boxnew/tests/box.input.js b/@navikt/aksel/src/codemod/transforms/box-to-boxnew/tests/box.input.js new file mode 100644 index 0000000000..e67edad889 --- /dev/null +++ b/@navikt/aksel/src/codemod/transforms/box-to-boxnew/tests/box.input.js @@ -0,0 +1,10 @@ +export const MyComponent = () => { + return ( <> + + this is a box with props that need migration + + + this is a box without + + ); +} diff --git a/@navikt/aksel/src/codemod/transforms/box-to-boxnew/tests/box.output.js b/@navikt/aksel/src/codemod/transforms/box-to-boxnew/tests/box.output.js new file mode 100644 index 0000000000..abe00256ac --- /dev/null +++ b/@navikt/aksel/src/codemod/transforms/box-to-boxnew/tests/box.output.js @@ -0,0 +1,10 @@ +export const MyComponent = () => { + return ( <> + + this is a box with props that need migration + + + this is a box without + + ); +}