Skip to content

Instantly share code, notes, and snippets.

@eps1lon
Created May 13, 2020 15:51
Show Gist options
  • Save eps1lon/ff6235d53d269d7d05ddb0e8d9d6c688 to your computer and use it in GitHub Desktop.
Save eps1lon/ff6235d53d269d7d05ddb0e8d9d6c688 to your computer and use it in GitHub Desktop.
mui docs layout
// Press ctrl+space for code completion
export default function transformer(file, api, options = {}) {
const j = api.jscodeshift;
const root = j(file.source);
const { layout = "AppFrame" } = options;
let isDocsPage = false;
root.find(j.ExportDefaultDeclaration).forEach((path) => {
isDocsPage = path.node.declaration.params.length > 0;
});
if (isDocsPage) {
const layoutDeclaration = j.importDeclaration([j.importDefaultSpecifier(j.identifier(layout))], j.literal(`docs/src/modules/components/layout/${layout}`), "value");
root.find(j.ImportDeclaration).at(-1).insertAfter(layoutDeclaration);
const body = root.find(j.Program).get("body");
body.value.push("\n");
j(body.get(body.value.length - 1)).insertAfter(
j.expressionStatement(j.assignmentExpression("=", j.memberExpression(j.identifier("Page"), j.identifier("Layout")), j.identifier(layout)))
);
}
return root.toSource();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment