From 293925543afafcc2c58545e3269676ad5d97e265 Mon Sep 17 00:00:00 2001 From: Justin Hall Date: Sat, 27 Mar 2021 10:06:13 -0600 Subject: [PATCH] Update Emotion recipe to better leverage the installer package --- recipes/emotion/index.ts | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/recipes/emotion/index.ts b/recipes/emotion/index.ts index 16af0c9854..89bf3431d3 100644 --- a/recipes/emotion/index.ts +++ b/recipes/emotion/index.ts @@ -1,4 +1,10 @@ -import {addImport, paths, RecipeBuilder} from "@blitzjs/installer" +import { + addBabelPlugin, + addImport, + findModuleExportsExpressions, + paths, + RecipeBuilder, +} from "@blitzjs/installer" import j from "jscodeshift" import {Collection} from "jscodeshift/src/Collection" import {join} from "path" @@ -22,36 +28,6 @@ function applyGlobalStyles(program: Collection) { return program } -function findModuleExportsExpressions(program: Collection) { - return program.find(j.AssignmentExpression).filter((path) => { - const {left, right} = path.value - return ( - left.type === "MemberExpression" && - left.object.type === "Identifier" && - left.property.type === "Identifier" && - left.property.name === "exports" && - right.type === "ObjectExpression" - ) - }) -} - -function addBabelPlugin(program: Collection) { - findModuleExportsExpressions(program).forEach((moduleExportsExpression) => { - j(moduleExportsExpression) - .find(j.ObjectProperty, {key: {name: "plugins"}}) - .forEach((plugins) => { - const pluginsArrayExpression = plugins.node.value - if (pluginsArrayExpression.type !== "ArrayExpression") { - return - } - - pluginsArrayExpression.elements.push(j.stringLiteral("@emotion")) - }) - }) - - return program -} - function replaceBabelPreset(program: Collection) { findModuleExportsExpressions(program).forEach((moduleExportsExpression) => { j(moduleExportsExpression)