Created
May 13, 2020 15:51
-
-
Save eps1lon/ff6235d53d269d7d05ddb0e8d9d6c688 to your computer and use it in GitHub Desktop.
mui docs layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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