Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 box migration #3669

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions @navikt/aksel/src/codemod/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const MyComponent = () => {
return ( <>
<Box background="bg-subtle" borderColor="border-alt-1" shadow="large">
this is a box with props that need migration
</Box>
<Box borderWidth="4" padding={{ lg: "10", sm: "8" }} height="200rem">
this is a box without
</Box>
</> );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const MyComponent = () => {
return ( <>
<Box background="bg-neutral-soft" borderColor="border-meta-purple" shadow="large">
this is a box with props that need migration
</Box>
<Box borderWidth="4" padding={{ lg: "10", sm: "8" }} height="200rem">
this is a box without
</Box>
</> );
}
Loading