@sps-woodland/codemods 8.53.11 → 8.53.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/transform.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function R(n,e){n.find(e.JSXOpeningElement).filter(s=>s.node.name.name==="KeyValueSetItem").forEach(s=>{const{itemKeyProp:a,titleColorProp:i,otherAttrs:o}=s.node.attributes.reduce((m,d)=>{switch(d.name.name){case"itemKey":m.itemKeyProp=d;break;case"titleColor":m.titleColorProp=d;break;default:m.otherAttrs.push(d)}return m},{itemKeyProp:null,titleColorProp:null,otherAttrs:[]});if(!i)return;const t=i.value.expression.property.name==="DARK"?e.jsxAttribute(e.jsxIdentifier("itemKey"),e.jsxExpressionContainer(e.arrowFunctionExpression([],e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Box"),[e.jsxAttribute(e.jsxIdentifier("color"),e.literal("grey-dark"))],!1),e.jsxClosingElement(e.jsxIdentifier("Box")),[a.value.type==="JSXExpressionContainer"?a.value.expression.body:e.jsxText(a.value.value)])))):a;e(s).replaceWith(e.jsxOpeningElement(s.node.name,[t,...o],s.node.selfClosing))})}function L(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsMicroBlock").forEach(s=>{const{messageProp:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="message"?o.messageProp=t:o.otherAttrs.push(t),o),{messageProp:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsMicroBlock"),[e.jsxAttribute(e.jsxIdentifier("micro"),null),...i],!1),e.jsxClosingElement(e.jsxIdentifier("SpsMicroBlock")),[e.jsxText(a.value.value)]))})}function x(n,e,c){const s=n.find(e.ImportDeclaration),a=new Map;for(const i of Object.keys(c.byOldPackage)){const o=c.byOldPackage[i];s.filter(t=>t.value?.type==="ImportDeclaration"&&t.node.source.value===i).forEach(t=>{const m=new Set,d=t.node.specifiers.filter(u=>o.hasOwnProperty(u.imported.name)?(m.add(u.imported.name),!1):!0),p=d.length===0,I=e(t);p||I.replaceWith(e.importDeclaration(d,t.node.source,t.node.importKind));const S=Array.from(m).reduce((u,l)=>{const{newName:r,newPackage:E}=o[l];return u.hasOwnProperty(E)||(u[E]=[]),u[E].push(r),u},{});for(const u of Object.keys(S)){const l=S[u];if(a.has(u)){const r=a.get(u),E=l.map(h=>e.importSpecifier(e.identifier(h))),f=e.importDeclaration([...r.node.specifiers,...E],r.node.source);a.set(u,f),e(r).replaceWith(f)}else{const r=e.importDeclaration(l.map(E=>e.importSpecifier(e.identifier(E))),e.literal(u));a.set(u,r),I.insertAfter(r)}}p&&I.remove()})}}function b(n,e,c){const s=n.find(e.JSXOpeningElement),a=n.find(e.JSXClosingElement);for(const[i,,o]of c.list)s.filter(t=>t.node.name.name===i).forEach(t=>{let{attributes:m}=t.node;if(c.props.hasOwnProperty(o)){const d=c.props[o];m=m.map(p=>d.hasOwnProperty(p.name.name)?e.jsxAttribute(e.jsxIdentifier(p.name.name),e.literal(d[p.name.name][p.value.expression.property.name])):p)}e(t).replaceWith(e.jsxOpeningElement(e.jsxIdentifier(o),m,t.node.selfClosing))}),a.filter(t=>t.node.name.name===i).forEach(t=>{e(t).replaceWith(e.jsxClosingElement(e.jsxIdentifier(o),t.node.attributes,t.node.selfClosing))})}const g=[["SpsButton","@spscommerce/ds-react","Button","@sps-woodland/buttons"],["SpsCardV2","@spscommerce/ds-react","Card","@sps-woodland/cards"],["SpsCardV2Header","@spscommerce/ds-react","CardHeader","@sps-woodland/cards"],["SpsCardV2Title","@spscommerce/ds-react","CardTitle","@sps-woodland/cards"],["SpsCardV2Footer","@spscommerce/ds-react","CardFooter","@sps-woodland/cards"],["SpsClickableTag","@spscommerce/ds-react","ClickableTag","@sps-woodland/tags"],["SpsContentRow","@spscommerce/ds-react","ContentRow","@sps-woodland/content-row"],["SpsContentRowCol","@spscommerce/ds-react","ContentRowCol","@sps-woodland/content-row"],["SpsContentRowExpansion","@spscommerce/ds-react","ContentRowExpansion","@sps-woodland/content-row"],["SpsInsights","@spscommerce/ds-react","InsightCardSet","@sps-woodland/cards"],["SpsInsightTile","@spscommerce/ds-react","InsightCard","@sps-woodland/cards"],["SpsScrollableContainer","@spscommerce/ds-react","ScrollableContainer","@sps-woodland/cards"],["SpsApp","@spscommerce/ds-react","AppRoot","@sps-woodland/core"],["SpsI","@spscommerce/ds-react","Icon","@sps-woodland/core"],["SpsSpinner","@spscommerce/ds-react","Spinner","@sps-woodland/core"],["SpsVerticalRule","@spscommerce/ds-react","VerticalRule","@sps-woodland/core"],["SpsVr","@spscommerce/ds-react","Vr","@sps-woodland/core"],["I18nContext","@spscommerce/ds-react","I18nContext","@sps-woodland/core"],["bindProps","@spscommerce/ds-react","bindProps","@sps-woodland/core"],["contentOf","@spscommerce/ds-react","contentOf","@sps-woodland/core"],["Provide","@spscommerce/ds-react","Provide","@sps-woodland/core"],["selectChildren","@spscommerce/ds-react","selectChildren","@sps-woodland/core"],["usePatchReducer","@spscommerce/ds-react","usePatchReducer","@sps-woodland/core"],["SpsFeedbackBlock","@spscommerce/ds-react","FeedbackBlock","@sps-woodland/feedback-block"],["SpsMicroBlock","@spscommerce/ds-react","FeedbackBlock","@sps-woodland/feedback-block"],["SpsKeyValueList","@spscommerce/ds-react","KeyValueSet","@sps-woodland/key-value-set"],["SpsKeyValueListItem","@spscommerce/ds-react","KeyValueSetItem","@sps-woodland/key-value-set"],["SpsKeyValueTag","@spscommerce/ds-react","KeyValueTag","@sps-woodland/tags"],["KeyValueTag","@spscommerce/tags","SplitTag","@sps-woodland/tags"],["SpsAdvancedSearch","@spscommerce/ds-react","AdvancedSearch","@sps-woodland/list-bar"],["SpsListToolbar","@spscommerce/ds-react","ListBar","@sps-woodland/list-bar"],["SpsListToolbarSearch","@spscommerce/ds-react","ListBarSearch","@sps-woodland/list-bar"],["SpsListToolbarSearchInfo","@spscommerce/ds-react","ListBarSearchInfo","@sps-woodland/list-bar"],["SpsListToolbarSortBy","@spscommerce/ds-react","ListBarSortBy","@sps-woodland/list-bar"],["SpsSearchResultsBarV2","@spscommerce/ds-react","SearchResultsBar","@sps-woodland/list-bar"],["SpsPageTitle","@spscommerce/ds-react","PageTitle","@sps-woodland/page-title"],["SpsPageSubtitle","@spscommerce/ds-react","PageSubtitle","@sps-woodland/page-title"],["PageTitle","@sps-woodland/page-title","Title","@sps-woodland/core"],["PageSubtitle","@sps-woodland/page-title","Title","@sps-woodland/core"],["SpsProductBar","@spscommerce/ds-react","ProductBar","@sps-woodland/product-bar"],["SpsProductBarTab","@spscommerce/ds-react","ProductBarTab","@sps-woodland/product-bar"],["SpsSlackLink","@spscommerce/ds-react","SlackLink","@sps-woodland/slack-link"],["SpsProgressBar","@spscommerce/ds-react","ProgressBar","@sps-woodland/progress-indicators"],["SpsProgressRing","@spscommerce/ds-react","ProgressRing","@sps-woodland/progress-indicators"],["SpsSteppedProgressBar","@spscommerce/ds-react","SteppedProgressBar","@sps-woodland/progress-indicators"],["SpsTabsV2","@spscommerce/ds-react","Tabs","@sps-woodland/tabs"],["SpsTileList","@spscommerce/ds-react","ContentTileList","@sps-woodland/content-tiles"],["SpsTile","@spscommerce/ds-react","ContentTile","@sps-woodland/content-tiles"],["SpsFilterTile","@spscommerce/ds-react","FilterTile","@sps-woodland/filter-tiles"],["SpsFilterTileList","@spscommerce/ds-react","FilterTileSet","@sps-woodland/filter-tiles"],["SpsSideNav","@spscommerce/ds-react","SideNav","@sps-woodland/side-nav"],["SpsSortingHeader","@spscommerce/ds-react","SortingHeader","@sps-woodland/sorting-header"],["SpsSortingHeaderCell","@spscommerce/ds-react","SortingHeaderCell","@sps-woodland/sorting-header"],["SpsTag","@spscommerce/ds-react","Tag","@sps-woodland/tags"],["SpsIllustrations","@spscommerce/ds-illustrations","Illustrations","@sps-woodland/illustrations"],["SpsZeroState","@spscommerce/ds-react","ZeroState","@sps-woodland/zero-state"],["SpsMicroZeroState","@spscommerce/ds-react","ZeroState","@sps-woodland/zero-state"],["rem","@spscommerce/ds-tokens","rem","@sps-woodland/tokens"],["border","@spscommerce/ds-tokens","border","@sps-woodland/tokens"],["grid","@spscommerce/ds-tokens","grid","@sps-woodland/tokens"],["sprinkles","@spscommerce/ds-tokens","sprinkles","@sps-woodland/tokens"],["Sprinkles","@spscommerce/ds-tokens","Sprinkles","@sps-woodland/tokens"],["Tokens","@spscommerce/ds-tokens","Tokens","@sps-woodland/tokens"]],T={ANGLE_LEFT:"angle-left",ANGLE_RIGHT:"angle-right",ARCHIVE:"archive",ARCHIVE_CIRCLE:"archive-circle",ARROW_DOWN:"arrow-down",ARROW_LEFT:"arrow-left",ARROW_LEFT_CIRCLE:"arrow-left-circle",ARROW_RIGHT:"arrow-right",ARROW_RIGHT_CIRCLE:"arrow-right-circle",ARROW_UP:"arrow-up",ASTERISK:"asterisk",ASTERISK_CIRCLE:"asterisk-circle",BAN:"ban",BAN_CIRCLE:"ban-circle",BARCODE:"barcode",BELL:"bell",BELL_FILLED:"bell-filled",BOLT:"bolt",BOOK:"book",BUILDING:"building",BURST:"burst",BURST_BOLT:"burst-bolt",CALENDAR:"calendar",CALENDAR_BLANK:"calendar-blank",CALENDAR_BLANK_CIRCLE:"calendar-blank-circle",CALENDAR_SELECT:"calendar-select",CAMERA:"camera",CHART_AREA:"chart-area",CHART_BAR:"chart-bar",CHART_LINE:"chart-line",CHART_PIE:"chart-pie",CHECKMARK:"checkmark",CHECKMARK_CIRCLE:"checkmark-circle",CHEVRON_DOWN:"chevron-down",CHEVRON_LEFT:"chevron-left",CHEVRON_RIGHT:"chevron-right",CHEVRON_UP:"chevron-up",CIRCLE_OUTLINE:"circle-outline",CLOCK:"clock",CLOCK_CIRCLE:"clock-circle",CODE_FORK:"code-fork",COLUMN_SWITCHER:"column-switcher",COMMENT_BUBBLE:"comment-bubble",COMMENT_BUBBLE_QUESTION:"comment-bubble-question",CONVERSATION:"conversation",CREDIT_CARD:"credit-card",DASHBOARD:"dashboard",DATABASE:"database",DESCENDING_ELLIPSES_CIRCLE:"descending-ellipses-circle",DISK:"disk",DISK_CIRCLE:"disk-circle",DOLLAR_SIGN:"dollar-sign",DOUBLE_ANGLE_LEFT:"double-angle-left",DOUBLE_ANGLE_RIGHT:"double-angle-right",DOWNLOAD_CLOUD:"download-cloud",DRILL:"drill",DUPLICATE:"duplicate",ELLIPSES:"ellipses",ENVELOPE:"envelope",EXCHANGE:"exchange",EXCLAMATION_CIRCLE:"exclamation-circle",EXCLAMATION_TRIANGLE:"exclamation-triangle",EXPAND_COLLAPSE:"expand-collapse",EYE:"eye",EYE_SLASH:"eye-slash",FILE:"file",FILE_DUPLICATE:"file-duplicate",FILE_PDF:"file-pdf",FILE_PRESENTATION:"file-presentation",FILE_SIZE:"file-size",FILE_SOLID:"file-solid",FILE_SOLID_TEXT:"file-solid-text",FILE_SPREADSHEET:"file-spreadsheet",FILE_TEXT:"file-text",FILTER:"filter",FLAG:"flag",FOLDER:"folder",FOLDER_OPEN:"folder-open",FOLDER_SOLID:"folder-solid",FOLDER_SOLID_OPEN:"folder-solid-open",GEAR:"gear",GLOBE:"globe",GRID:"grid",GROUP:"group",HAND_STOP:"hand-stop",HANDSHAKE:"handshake",HAT:"hat",HEART:"heart",HISTORY:"history",INBOX:"inbox",INCOMING:"incoming",INFO_CIRCLE:"info-circle",INTERCOM:"intercom",ITEM_TAG:"item-tag",KEY:"key",LIFE_PRESERVER:"life-preserver",LIGHTBULB:"lightbulb",LINK:"link",LINKEDIN:"linkedin",LIST:"list",LIST_CARDS:"list-cards",LIST_COLUMNS:"list-columns",LIST_SUMMARY:"list-summary",LIST_TABLE:"list-table",LOCATION:"location",LOCKED:"locked",LOCKED_CIRCLE:"locked-circle",MAP:"map",MAP_MARKER:"map-marker",MAXIMIZE:"maximize",MINIMIZE:"minimize",MINUS:"minus",MINUS_CIRCLE:"minus-circle",NEW_FILE:"new-file",NEW_SCREEN:"new-screen",OUTGOING:"outgoing",PAPER_PLANE:"paper-plane",PENCIL:"pencil",PHOTO:"photo",PIN:"pin",PINTEREST:"pinterest",PLAY:"play",PLUS_CIRCLE:"plus-circle",PLUS_SIGN:"plus-sign",PRESENTATION:"presentation",PRINTER:"printer",QR_CODE:"qr-code",QUESTION_CIRCLE:"question-circle",QUOTE_LEFT:"quote-left",QUOTE_RIGHT:"quote-right",RANDOM:"random",REFRESH:"refresh",RIGHT_CIRCLE:"right-circle",ROCKET:"rocket",SEARCH:"search",SEARCH_PLUS:"search-plus",SHARE:"share",SHOPPING_CART:"shopping-cart",SORT_ALPHA_ASC:"sort-alpha-asc",SORT_ALPHA_DESC:"sort-alpha-desc",SORT_NUM_ASC:"sort-num-asc",SORT_NUM_DESC:"sort-num-desc",STAR:"star",STAR_OUTLINE:"star-outline",STATUS_ARCHIVED:"status-archived",STATUS_CANCELLED:"status-cancelled",STATUS_ERROR:"status-error",STATUS_IN_PROCESS:"status-in-process",STATUS_IN_TRANSIT:"status-in-transit",STATUS_LOCKED:"status-locked",STATUS_NEW:"status-new",STATUS_OK:"status-ok",STATUS_ON_HOLD:"status-on-hold",STATUS_OUTDATED:"status-outdated",STATUS_REJECTED:"status-rejected",STATUS_SAVED:"status-saved",STATUS_SAVING:"status-saving",STATUS_TEMPLATE:"status-template",STATUS_WARNING:"status-warning",TABLE:"table",TABS:"tabs",TAG:"tag",TEMPLATE_CIRCLE:"template-circle",THUMBS_DOWN:"thumbs-down",THUMBS_DOWN_OUTLINE:"thumbs-down-outline",THUMBS_UP:"thumbs-up",THUMBS_UP_OUTLINE:"thumbs-up-outline",TRASH:"trash",TRUCK_SHIPPING:"truck-shipping",TWITTER:"twitter",UNDO:"undo",UNLOCKED:"unlocked",UPLOAD_CLOUD:"upload-cloud",USER:"user",USER_IMPERSONATION:"user-impersonation",WRENCH:"wrench",X:"x",X_CIRCLE:"x-circle"},O={Icon:{icon:T,size:{EXTRA_SMALL:"xs",SMALL:"sm",MEDIUM:"md",LARGE:"lg",EXTRA_LARGE:"lg"}},InsightCard:{icon:T,kind:{GENERAL:"general",SUCCESS:"success",ERROR:"error",WARNING:"warning",PROCESSING:"processing"}},Spinner:{size:{SMALL:"sm",MEDIUM:"md",LARGE:"lg"}},FeedbackBlock:{kind:{TIP:"tip",SUCCESS:"success",WARNING:"warning",ERROR:"error",INFO:"info"}},Tag:{kind:{DEFAULT:"default",KEY:"key",WARNING:"warning",ERROR:"error",PENDING:"pending",SUCCESS:"success",INFO:"info"}},ClickableTag:{kind:{BLUE:"blue",GRAY:"gray"}},Button:{icon:T,kind:{DEFAULT:"default",LINK:"link",ICON:"icon",CONFIRM:"confirm",DELETE:"delete",KEY:"key"},type:{BUTTON:"button",SUBMIT:"submit"}},SteppedProgressBar:{color:{PURPLE:"purple",BLUE:"blue",ORANGE:"orange",RED:"red",GRAY:"grey"}},ProgressRing:{size:{SMALL:"sm",MEDIUM:"md",LARGE:"lg"}}};function w(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="Tag").forEach(s=>{const{iconProp:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="icon"?o.iconProp=t:o.otherAttrs.push(t),o),{iconProp:null,otherAttrs:[]});a&&e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Tag"),[e.jsxAttribute(e.jsxIdentifier("icon"),null),...i],!1),e.jsxClosingElement(e.jsxIdentifier("Tag"))))})}function k(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="KeyValueTag").forEach(s=>{const{iconProp:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="icon"?o.iconProp=t:o.otherAttrs.push(t),o),{iconProp:null,otherAttrs:[]});a&&e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("KeyValueTag"),[e.jsxAttribute(e.jsxIdentifier("icon"),null),...i],!1),e.jsxClosingElement(e.jsxIdentifier("KeyValueTag"))))})}function N(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsMicroZeroState").forEach(s=>{const{attrs:a}=s.value.openingElement.attributes.reduce((i,o)=>(i.attrs.push(o),i),{attrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsMicroZeroState"),[e.jsxAttribute(e.jsxIdentifier("micro"),null),...a],!0)))})}function _(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsProductBar").forEach(s=>{const{productName:a,nameClick:i,logoSrc:o,productLink:t,otherAttrs:m}=s.value.openingElement.attributes.reduce((d,p)=>{switch(p.name.name){case"productName":d.productName=p;break;case"onProductNameClick":d.nameClick=p;break;case"productLogoSrc":d.logoSrc=p;break;case"productNameHref":d.productLink=p;break;case"tabs":break;case"activeTabs":break;case"onTabChange":break;default:d.otherAttrs.push(p)}return d},{productName:null,nameClick:null,logoSrc:null,productLink:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsProductBar"),[...m],!1),e.jsxClosingElement(e.jsxIdentifier("SpsProductBar")),[e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProductBarName"),[a&&e.jsxAttribute(e.jsxIdentifier("name"),e.literal(a.value.value)),o&&e.jsxAttribute(e.jsxIdentifier("logoSrc"),e.literal(o.value.value)),i&&e.jsxAttribute(e.jsxIdentifier("onClick"),i.value),t&&e.jsxAttribute(e.jsxIdentifier("href"),e.literal(t.value.value))].filter(Boolean),!0)),...s.node.children]))})}function P(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="ProductBarTab").forEach(s=>{const{clickHandler:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="onClick"?o.clickHandler=t:o.otherAttrs.push(t),o),{clickHandler:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProductBarTab"),[a&&e.jsxAttribute(e.jsxIdentifier("onPress"),a.value),...i].filter(Boolean),!1),e.jsxClosingElement(e.jsxIdentifier("ProductBarTab")),[...s.node.children]))})}function B(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="Title").forEach(s=>{const{attrs:a}=s.value.openingElement.attributes.reduce((i,o)=>(i.attrs.push(o),i),{attrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Title"),[e.jsxAttribute(e.jsxIdentifier("size"),e.literal("xl")),...a],!1),e.jsxClosingElement(e.jsxIdentifier("Title")),[...s.node.children]))})}function v(n,e){if(n.find(e.ImportDeclaration,{source:{value:"@sps-woodland/illustrations"}}).length){const c=[];let s=n.find(e.JSXExpressionContainer,{expression:{object:{object:{name:"Illustrations"}}}});s.length||(s=n.find(e.JSXExpressionContainer,{expression:{object:{object:{name:"SpsIllustrations"}}}})),s.forEach(a=>{e(a).replaceWith(i=>{const o=i.value.expression.object.property.name.toUpperCase(),{name:t}=i.value.expression.property,m=`${t}_${o}`;return c.push(m),e.jsxExpressionContainer(e.identifier(m))})}),n.find(e.ImportSpecifier,{imported:{name:"Illustrations"}}).replaceWith(c.map(a=>e.importSpecifier(e.identifier(a))))}}function D(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SteppedProgressBar").forEach(s=>{const{stepsCount:a,completedStepsCount:i,color:o,title:t,showStepsCounter:m,disabled:d,data:p}=s.value.openingElement.attributes.reduce((l,r)=>{switch(r.name.name){case"title":l.title=r;case"showStepsCounter":l.showStepsCounter=r;case"stepsCount":l.stepsCount=r;case"completedStepsCount":l.completedStepsCount=r;case"data":l.data=r;case"color":l.color=r;case"disabled":l.disabled=r}return l},{title:"",stepsCount:null,completedStepsCount:null,data:[],color:"",showStepsCounter:!1,disabled:!1,otherAttrs:[]});let I=[],S={};try{p.value.expression.elements.forEach(r=>{S={},r.properties.forEach(E=>{S[E.key.name]=E.value.value||E.value.property.name,I.push(S)})})}catch{}try{n.find(e.VariableDeclarator).forEach(r=>{r.value.id.name===p.value.expression.name&&r.value.init.elements.forEach(E=>{S={},E.properties.forEach(f=>{S[f.key.name]=f.value.value||f.value.property.name,I.push(S)})})})}catch{}try{n.find(e.AssignmentExpression).filter(r=>r.value.left.name===p.value.expression.name).forEach(r=>{r.value.right.elements.forEach(E=>{S={},E.properties.forEach(f=>{S[f.key.name]=f.value.value||f.value.property.name,I.push(S)})})})}catch{}let u=[];for(let l=0;l<a.value.expression.value;l++){let r=I.filter(E=>E.index===l);u.push(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProgressBarStep"),[l<i.value.expression.value&&!(r.length&&r[0].index===l&&r[0].skipped)?e.jsxAttribute(e.jsxIdentifier("completed"),null):e.jsxAttribute(e.jsxIdentifier(""),null),r.length&&r[0].index===l&&r[0].title?e.jsxAttribute(e.jsxIdentifier("title"),e.literal(r[0].title)):e.jsxAttribute(e.jsxIdentifier(""),null),r.length&&r[0].index===l&&r[0].description?e.jsxAttribute(e.jsxIdentifier("description"),e.literal(r[0].description)):e.jsxAttribute(e.jsxIdentifier(""),null),r.length&&r[0].index===l&&r[0].icon?e.jsxAttribute(e.jsxIdentifier("icon"),e.literal(r[0].icon.toLowerCase())):e.jsxAttribute(e.jsxIdentifier(""),null)],!0)))}e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProgressBar"),[e.jsxAttribute(e.jsxIdentifier("progressColor"),o.value),e.jsxAttribute(e.jsxIdentifier("title"),t.value),e.jsxAttribute(e.jsxIdentifier("showStepsCounter"),m.value),e.jsxAttribute(e.jsxIdentifier("disabled"),d.value)],!1),e.jsxClosingElement(e.jsxIdentifier("ProgressBar")),u))})}const U=g.reduce((n,[e,c,s,a])=>{let i=n[c];return i||(i={},n[c]=i),i[e]={newName:s,newPackage:a},n},{}),C={list:g,byOldPackage:U,props:O};function A(n,{jscodeshift:e},c){const s=e(n.source);return N(s,e),_(s,e),L(s,e),x(s,e,C),b(s,e,C),P(s,e),R(s,e),w(s,e),k(s,e),B(s,e),v(s,e),D(s,e),s.toSource(c?.woodland?.output)}A.parser="tsx";module.exports=A;
|
|
1
|
+
"use strict";function R(n,e){n.find(e.JSXOpeningElement).filter(s=>s.node.name.name==="KeyValueSetItem").forEach(s=>{const{itemKeyProp:a,titleColorProp:i,otherAttrs:o}=s.node.attributes.reduce((m,d)=>{switch(d.name.name){case"itemKey":m.itemKeyProp=d;break;case"titleColor":m.titleColorProp=d;break;default:m.otherAttrs.push(d)}return m},{itemKeyProp:null,titleColorProp:null,otherAttrs:[]});if(!i)return;const t=i.value.expression.property.name==="DARK"?e.jsxAttribute(e.jsxIdentifier("itemKey"),e.jsxExpressionContainer(e.arrowFunctionExpression([],e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Box"),[e.jsxAttribute(e.jsxIdentifier("color"),e.literal("grey-dark"))],!1),e.jsxClosingElement(e.jsxIdentifier("Box")),[a.value.type==="JSXExpressionContainer"?a.value.expression.body:e.jsxText(a.value.value)])))):a;e(s).replaceWith(e.jsxOpeningElement(s.node.name,[t,...o],s.node.selfClosing))})}function L(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsMicroBlock").forEach(s=>{const{messageProp:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="message"?o.messageProp=t:o.otherAttrs.push(t),o),{messageProp:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsMicroBlock"),[e.jsxAttribute(e.jsxIdentifier("micro"),null),...i],!1),e.jsxClosingElement(e.jsxIdentifier("SpsMicroBlock")),[e.jsxText(a.value.value)]))})}function x(n,e,c){const s=n.find(e.ImportDeclaration),a=new Map;for(const i of Object.keys(c.byOldPackage)){const o=c.byOldPackage[i];s.filter(t=>t.value?.type==="ImportDeclaration"&&t.node.source.value===i).forEach(t=>{const m=new Set,d=t.node.specifiers.filter(u=>o.hasOwnProperty(u.imported.name)?(m.add(u.imported.name),!1):!0),p=d.length===0,I=e(t);p||I.replaceWith(e.importDeclaration(d,t.node.source,t.node.importKind));const S=Array.from(m).reduce((u,l)=>{const{newName:r,newPackage:E}=o[l];return u.hasOwnProperty(E)||(u[E]=[]),u[E].push(r),u},{});for(const u of Object.keys(S)){const l=S[u];if(a.has(u)){const r=a.get(u),E=l.map(h=>e.importSpecifier(e.identifier(h))),f=e.importDeclaration([...r.node.specifiers,...E],r.node.source);a.set(u,f),e(r).replaceWith(f)}else{const r=e.importDeclaration(l.map(E=>e.importSpecifier(e.identifier(E))),e.literal(u));a.set(u,r),I.insertAfter(r)}}p&&I.remove()})}}function b(n,e,c){const s=n.find(e.JSXOpeningElement),a=n.find(e.JSXClosingElement);for(const[i,,o]of c.list)s.filter(t=>t.node.name.name===i).forEach(t=>{let{attributes:m}=t.node;if(c.props.hasOwnProperty(o)){const d=c.props[o];m=m.map(p=>d.hasOwnProperty(p.name.name)?e.jsxAttribute(e.jsxIdentifier(p.name.name),e.literal(d[p.name.name][p.value.expression.property.name])):p)}e(t).replaceWith(e.jsxOpeningElement(e.jsxIdentifier(o),m,t.node.selfClosing))}),a.filter(t=>t.node.name.name===i).forEach(t=>{e(t).replaceWith(e.jsxClosingElement(e.jsxIdentifier(o),t.node.attributes,t.node.selfClosing))})}const g=[["SpsButton","@spscommerce/ds-react","Button","@sps-woodland/buttons"],["SpsCardV2","@spscommerce/ds-react","Card","@sps-woodland/cards"],["SpsCardV2Header","@spscommerce/ds-react","CardHeader","@sps-woodland/cards"],["SpsCardV2Title","@spscommerce/ds-react","CardTitle","@sps-woodland/cards"],["SpsCardV2Footer","@spscommerce/ds-react","CardFooter","@sps-woodland/cards"],["SpsClickableTag","@spscommerce/ds-react","ClickableTag","@sps-woodland/tags"],["SpsContentRow","@spscommerce/ds-react","ContentRow","@sps-woodland/content-row"],["SpsContentRowCol","@spscommerce/ds-react","ContentRowCol","@sps-woodland/content-row"],["SpsContentRowExpansion","@spscommerce/ds-react","ContentRowExpansion","@sps-woodland/content-row"],["SpsInsights","@spscommerce/ds-react","InsightCardSet","@sps-woodland/cards"],["SpsInsightTile","@spscommerce/ds-react","InsightCard","@sps-woodland/cards"],["SpsScrollableContainer","@spscommerce/ds-react","ScrollableContainer","@sps-woodland/cards"],["SpsApp","@spscommerce/ds-react","AppRoot","@sps-woodland/core"],["SpsI","@spscommerce/ds-react","Icon","@sps-woodland/core"],["SpsSpinner","@spscommerce/ds-react","Spinner","@sps-woodland/core"],["SpsVerticalRule","@spscommerce/ds-react","VerticalRule","@sps-woodland/core"],["SpsVr","@spscommerce/ds-react","Vr","@sps-woodland/core"],["I18nContext","@spscommerce/ds-react","I18nContext","@sps-woodland/core"],["bindProps","@spscommerce/ds-react","bindProps","@sps-woodland/core"],["contentOf","@spscommerce/ds-react","contentOf","@sps-woodland/core"],["Provide","@spscommerce/ds-react","Provide","@sps-woodland/core"],["selectChildren","@spscommerce/ds-react","selectChildren","@sps-woodland/core"],["usePatchReducer","@spscommerce/ds-react","usePatchReducer","@sps-woodland/core"],["SpsFeedbackBlock","@spscommerce/ds-react","FeedbackBlock","@sps-woodland/feedback-block"],["SpsMicroBlock","@spscommerce/ds-react","FeedbackBlock","@sps-woodland/feedback-block"],["SpsKeyValueList","@spscommerce/ds-react","KeyValueSet","@sps-woodland/key-value-set"],["SpsKeyValueListItem","@spscommerce/ds-react","KeyValueSetItem","@sps-woodland/key-value-set"],["SpsKeyValueTag","@spscommerce/ds-react","KeyValueTag","@sps-woodland/tags"],["KeyValueTag","@spscommerce/tags","SplitTag","@sps-woodland/tags"],["SpsAdvancedSearch","@spscommerce/ds-react","AdvancedSearch","@sps-woodland/list-bar"],["SpsListToolbar","@spscommerce/ds-react","ListBar","@sps-woodland/list-bar"],["SpsListToolbarSearch","@spscommerce/ds-react","ListBarSearch","@sps-woodland/list-bar"],["SpsListToolbarSearchInfo","@spscommerce/ds-react","ListBarSearchInfo","@sps-woodland/list-bar"],["SpsListToolbarSortBy","@spscommerce/ds-react","ListBarSortBy","@sps-woodland/list-bar"],["SpsSearchResultsBarV2","@spscommerce/ds-react","SearchResultsBar","@sps-woodland/list-bar"],["SpsPageTitle","@spscommerce/ds-react","PageTitle","@sps-woodland/page-title"],["SpsPageSubtitle","@spscommerce/ds-react","PageSubtitle","@sps-woodland/page-title"],["PageTitle","@sps-woodland/page-title","Title","@sps-woodland/core"],["PageSubtitle","@sps-woodland/page-title","Title","@sps-woodland/core"],["SpsProductBar","@spscommerce/ds-react","ProductBar","@sps-woodland/product-bar"],["SpsProductBarTab","@spscommerce/ds-react","ProductBarTab","@sps-woodland/product-bar"],["SpsSlackLink","@spscommerce/ds-react","SlackLink","@sps-woodland/slack-link"],["SpsProgressBar","@spscommerce/ds-react","ProgressBar","@sps-woodland/progress-indicators"],["SpsProgressRing","@spscommerce/ds-react","ProgressRing","@sps-woodland/progress-indicators"],["SpsSteppedProgressBar","@spscommerce/ds-react","SteppedProgressBar","@sps-woodland/progress-indicators"],["SpsTabsV2","@spscommerce/ds-react","Tabs","@sps-woodland/tabs"],["SpsTileList","@spscommerce/ds-react","ContentTileList","@sps-woodland/content-tiles"],["SpsTile","@spscommerce/ds-react","ContentTile","@sps-woodland/content-tiles"],["SpsFilterTile","@spscommerce/ds-react","FilterTile","@sps-woodland/filter-tiles"],["SpsFilterTileList","@spscommerce/ds-react","FilterTileSet","@sps-woodland/filter-tiles"],["SpsSideNav","@spscommerce/ds-react","SideNav","@sps-woodland/side-nav"],["SpsSortingHeader","@spscommerce/ds-react","SortingHeader","@sps-woodland/sorting-header"],["SpsSortingHeaderCell","@spscommerce/ds-react","SortingHeaderCell","@sps-woodland/sorting-header"],["SpsTag","@spscommerce/ds-react","Tag","@sps-woodland/tags"],["SpsIllustrations","@spscommerce/ds-illustrations","Illustrations","@sps-woodland/illustrations"],["SpsZeroState","@spscommerce/ds-react","ZeroState","@sps-woodland/zero-state"],["SpsMicroZeroState","@spscommerce/ds-react","ZeroState","@sps-woodland/zero-state"],["rem","@spscommerce/ds-tokens","rem","@sps-woodland/tokens"],["border","@spscommerce/ds-tokens","border","@sps-woodland/tokens"],["grid","@spscommerce/ds-tokens","grid","@sps-woodland/tokens"],["sprinkles","@spscommerce/ds-tokens","sprinkles","@sps-woodland/tokens"],["Sprinkles","@spscommerce/ds-tokens","Sprinkles","@sps-woodland/tokens"],["Tokens","@spscommerce/ds-tokens","Tokens","@sps-woodland/tokens"]],T={ANGLE_LEFT:"angle-left",ANGLE_RIGHT:"angle-right",ARCHIVE:"archive",ARCHIVE_CIRCLE:"archive-circle",ARROW_DOWN:"arrow-down",ARROW_LEFT:"arrow-left",ARROW_LEFT_CIRCLE:"arrow-left-circle",ARROW_RIGHT:"arrow-right",ARROW_RIGHT_CIRCLE:"arrow-right-circle",ARROW_UP:"arrow-up",ASTERISK:"asterisk",ASTERISK_CIRCLE:"asterisk-circle",BAN:"ban",BAN_CIRCLE:"ban-circle",BARCODE:"barcode",BELL:"bell",BELL_FILLED:"bell-filled",BOLT:"bolt",BOOK:"book",BUILDING:"building",BURST:"burst",BURST_BOLT:"burst-bolt",CALENDAR:"calendar",CALENDAR_BLANK:"calendar-blank",CALENDAR_BLANK_CIRCLE:"calendar-blank-circle",CALENDAR_SELECT:"calendar-select",CAMERA:"camera",CHART_AREA:"chart-area",CHART_BAR:"chart-bar",CHART_LINE:"chart-line",CHART_PIE:"chart-pie",CHECKMARK:"checkmark",CHECKMARK_CIRCLE:"checkmark-circle",CHEVRON_DOWN:"chevron-down",CHEVRON_LEFT:"chevron-left",CHEVRON_RIGHT:"chevron-right",CHEVRON_UP:"chevron-up",CIRCLE_OUTLINE:"circle-outline",CLOCK:"clock",CLOCK_CIRCLE:"clock-circle",CODE_FORK:"code-fork",COLUMN_SWITCHER:"column-switcher",COMMENT_BUBBLE:"comment-bubble",COMMENT_BUBBLE_QUESTION:"comment-bubble-question",CONVERSATION:"conversation",CREDIT_CARD:"credit-card",DASHBOARD:"dashboard",DATABASE:"database",DESCENDING_ELLIPSES_CIRCLE:"descending-ellipses-circle",DISK:"disk",DISK_CIRCLE:"disk-circle",DOLLAR_SIGN:"dollar-sign",DOUBLE_ANGLE_LEFT:"double-angle-left",DOUBLE_ANGLE_RIGHT:"double-angle-right",DOWNLOAD_CLOUD:"download-cloud",DRILL:"drill",DUPLICATE:"duplicate",ELLIPSES:"ellipses",ENVELOPE:"envelope",EXCHANGE:"exchange",EXCLAMATION_CIRCLE:"exclamation-circle",EXCLAMATION_TRIANGLE:"exclamation-triangle",EXPAND_COLLAPSE:"expand-collapse",EYE:"eye",EYE_SLASH:"eye-slash",FILE:"file",FILE_DUPLICATE:"file-duplicate",FILE_PDF:"file-pdf",FILE_PRESENTATION:"file-presentation",FILE_SIZE:"file-size",FILE_SOLID:"file-solid",FILE_SOLID_TEXT:"file-solid-text",FILE_SPREADSHEET:"file-spreadsheet",FILE_TEXT:"file-text",FILTER:"filter",FLAG:"flag",FOLDER:"folder",FOLDER_OPEN:"folder-open",FOLDER_SOLID:"folder-solid",FOLDER_SOLID_OPEN:"folder-solid-open",GEAR:"gear",GLOBE:"globe",GRID:"grid",GROUP:"group",HAND_STOP:"hand-stop",HANDSHAKE:"handshake",HAT:"hat",HEART:"heart",HISTORY:"history",INBOX:"inbox",INCOMING:"incoming",INFO_CIRCLE:"info-circle",INTERCOM:"intercom",ITEM_TAG:"item-tag",KEY:"key",LIFE_PRESERVER:"life-preserver",LIGHTBULB:"lightbulb",LINK:"link",LINKEDIN:"linkedin",LIST:"list",LIST_CARDS:"list-cards",LIST_COLUMNS:"list-columns",LIST_SUMMARY:"list-summary",LIST_TABLE:"list-table",LOCATION:"location",LOCKED:"locked",LOCKED_CIRCLE:"locked-circle",MAP:"map",MAP_MARKER:"map-marker",MAXIMIZE:"maximize",MINIMIZE:"minimize",MINUS:"minus",MINUS_CIRCLE:"minus-circle",NEW_FILE:"new-file",NEW_SCREEN:"new-screen",OUTGOING:"outgoing",PAPER_PLANE:"paper-plane",PENCIL:"pencil",PHOTO:"photo",PIN:"pin",PINTEREST:"pinterest",PLAY:"play",PLUS_CIRCLE:"plus-circle",PLUS_SIGN:"plus-sign",PRESENTATION:"presentation",PRINTER:"printer",QR_CODE:"qr-code",QUESTION_CIRCLE:"question-circle",QUOTE_LEFT:"quote-left",QUOTE_RIGHT:"quote-right",RANDOM:"random",REFRESH:"refresh",RIGHT_CIRCLE:"right-circle",ROCKET:"rocket",SEARCH:"search",SEARCH_PLUS:"search-plus",SHARE:"share",SHOPPING_CART:"shopping-cart",SORT_ALPHA_ASC:"sort-alpha-asc",SORT_ALPHA_DESC:"sort-alpha-desc",SORT_NUM_ASC:"sort-num-asc",SORT_NUM_DESC:"sort-num-desc",STAR:"star",STAR_OUTLINE:"star-outline",STATUS_ARCHIVED:"status-archived",STATUS_CANCELLED:"status-cancelled",STATUS_ERROR:"status-error",STATUS_IN_PROCESS:"status-in-process",STATUS_IN_TRANSIT:"status-in-transit",STATUS_LOCKED:"status-locked",STATUS_NEW:"status-new",STATUS_OK:"status-ok",STATUS_ON_HOLD:"status-on-hold",STATUS_OUTDATED:"status-outdated",STATUS_REJECTED:"status-rejected",STATUS_SAVED:"status-saved",STATUS_SAVING:"status-saving",STATUS_TEMPLATE:"status-template",STATUS_WARNING:"status-warning",TABLE:"table",TABS:"tabs",TAG:"tag",TEMPLATE_CIRCLE:"template-circle",THUMBS_DOWN:"thumbs-down",THUMBS_DOWN_OUTLINE:"thumbs-down-outline",THUMBS_UP:"thumbs-up",THUMBS_UP_OUTLINE:"thumbs-up-outline",TRASH:"trash",TRUCK_SHIPPING:"truck-shipping",TWITTER:"twitter",UNDO:"undo",UNLOCKED:"unlocked",UPLOAD_CLOUD:"upload-cloud",USER:"user",USER_IMPERSONATION:"user-impersonation",WRENCH:"wrench",X:"x",X_CIRCLE:"x-circle"},O={Icon:{icon:T,size:{EXTRA_SMALL:"xs",SMALL:"sm",MEDIUM:"md",LARGE:"lg",EXTRA_LARGE:"lg"}},InsightCard:{icon:T,kind:{GENERAL:"general",SUCCESS:"success",ERROR:"error",WARNING:"warning",PROCESSING:"processing"}},Spinner:{size:{SMALL:"sm",MEDIUM:"md",LARGE:"lg"}},FeedbackBlock:{kind:{TIP:"tip",SUCCESS:"success",WARNING:"warning",ERROR:"error",INFO:"info"}},Tag:{kind:{DEFAULT:"default",KEY:"key",WARNING:"warning",ERROR:"error",PENDING:"pending",SUCCESS:"success",INFO:"info"}},ClickableTag:{kind:{BLUE:"blue",GRAY:"gray"}},Button:{icon:T,kind:{DEFAULT:"default",LINK:"link",ICON:"icon",CONFIRM:"confirm",DELETE:"delete",KEY:"key"},type:{BUTTON:"button",SUBMIT:"submit"}},SteppedProgressBar:{color:{PURPLE:"purple",BLUE:"blue",ORANGE:"orange",RED:"red",GRAY:"grey"}},ProgressRing:{size:{SMALL:"sm",MEDIUM:"md",LARGE:"lg"}}};function w(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="Tag").forEach(s=>{const{iconProp:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="icon"?o.iconProp=t:o.otherAttrs.push(t),o),{iconProp:null,otherAttrs:[]});a&&e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Tag"),[e.jsxAttribute(e.jsxIdentifier("icon"),null),...i],!1),e.jsxClosingElement(e.jsxIdentifier("Tag"))))})}function k(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="KeyValueTag").forEach(s=>{const{iconProp:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="icon"?o.iconProp=t:o.otherAttrs.push(t),o),{iconProp:null,otherAttrs:[]});a&&e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("KeyValueTag"),[e.jsxAttribute(e.jsxIdentifier("icon"),null),...i],!1),e.jsxClosingElement(e.jsxIdentifier("KeyValueTag"))))})}function N(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsMicroZeroState").forEach(s=>{const{attrs:a}=s.value.openingElement.attributes.reduce((i,o)=>(i.attrs.push(o),i),{attrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsMicroZeroState"),[e.jsxAttribute(e.jsxIdentifier("micro"),null),...a],!0)))})}function _(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsProductBar").forEach(s=>{const{productName:a,nameClick:i,logoSrc:o,productLink:t,otherAttrs:m}=s.value.openingElement.attributes.reduce((d,p)=>{switch(p.name.name){case"productName":d.productName=p;break;case"onProductNameClick":d.nameClick=p;break;case"productLogoSrc":d.logoSrc=p;break;case"productNameHref":d.productLink=p;break;case"tabs":break;case"activeTabs":break;case"onTabChange":break;default:d.otherAttrs.push(p)}return d},{productName:null,nameClick:null,logoSrc:null,productLink:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsProductBar"),[...m],!1),e.jsxClosingElement(e.jsxIdentifier("SpsProductBar")),[e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProductBarName"),[a&&e.jsxAttribute(e.jsxIdentifier("name"),e.literal(a.value.value)),o&&e.jsxAttribute(e.jsxIdentifier("logoSrc"),e.literal(o.value.value)),i&&e.jsxAttribute(e.jsxIdentifier("onClick"),i.value),t&&e.jsxAttribute(e.jsxIdentifier("href"),e.literal(t.value.value))].filter(Boolean),!0)),...s.node.children]))})}function P(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="ProductBarTab").forEach(s=>{const{clickHandler:a,otherAttrs:i}=s.value.openingElement.attributes.reduce((o,t)=>(t.name.name==="onClick"?o.clickHandler=t:o.otherAttrs.push(t),o),{clickHandler:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProductBarTab"),[a&&e.jsxAttribute(e.jsxIdentifier("onPress"),a.value),...i].filter(Boolean),!1),e.jsxClosingElement(e.jsxIdentifier("ProductBarTab")),[...s.node.children]))})}function B(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="Title").forEach(s=>{const{attrs:a}=s.value.openingElement.attributes.reduce((i,o)=>(i.attrs.push(o),i),{attrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Title"),[e.jsxAttribute(e.jsxIdentifier("size"),e.literal("xl")),...a],!1),e.jsxClosingElement(e.jsxIdentifier("Title")),[...s.node.children]))})}function v(n,e){if(n.find(e.ImportDeclaration,{source:{value:"@sps-woodland/illustrations"}}).length){const c=[];let s=n.find(e.JSXExpressionContainer,{expression:{object:{object:{name:"Illustrations"}}}});s.length||(s=n.find(e.JSXExpressionContainer,{expression:{object:{object:{name:"SpsIllustrations"}}}})),s.forEach(a=>{e(a).replaceWith(i=>{const o=i.value.expression.object.property.name.toUpperCase(),{name:t}=i.value.expression.property,m=`${t}_${o}`;return c.push(m),e.jsxExpressionContainer(e.identifier(m))})}),n.find(e.ImportSpecifier,{imported:{name:"Illustrations"}}).replaceWith(c.map(a=>e.importSpecifier(e.identifier(a))))}}function D(n,e){n.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SteppedProgressBar").forEach(s=>{const{stepsCount:a,completedStepsCount:i,color:o,title:t,showStepsCounter:m,disabled:d,data:p}=s.value.openingElement.attributes.reduce((l,r)=>{switch(r.name.name){case"title":l.title=r;case"showStepsCounter":l.showStepsCounter=r;case"stepsCount":l.stepsCount=r;case"completedStepsCount":l.completedStepsCount=r;case"data":l.data=r;case"color":l.color=r;case"disabled":l.disabled=r}return l},{title:"",stepsCount:null,completedStepsCount:null,data:[],color:"",showStepsCounter:!1,disabled:!1,otherAttrs:[]}),I=[];let S={};try{p.value.expression.elements.forEach(r=>{S={},r.properties.forEach(E=>{S[E.key.name]=E.value.value||E.value.property.name,I.push(S)})})}catch{}try{n.find(e.VariableDeclarator).forEach(r=>{r.value.id.name===p.value.expression.name&&r.value.init.elements.forEach(E=>{S={},E.properties.forEach(f=>{S[f.key.name]=f.value.value||f.value.property.name,I.push(S)})})})}catch{}try{n.find(e.AssignmentExpression).filter(r=>r.value.left.name===p.value.expression.name).forEach(r=>{r.value.right.elements.forEach(E=>{S={},E.properties.forEach(f=>{S[f.key.name]=f.value.value||f.value.property.name,I.push(S)})})})}catch{}const u=[];for(let l=0;l<a.value.expression.value;l++){const r=I.filter(E=>E.index===l);u.push(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProgressBarStep"),[l<i.value.expression.value&&!(r.length&&r[0].index===l&&r[0].skipped)?e.jsxAttribute(e.jsxIdentifier("completed"),null):e.jsxAttribute(e.jsxIdentifier(""),null),r.length&&r[0].index===l&&r[0].title?e.jsxAttribute(e.jsxIdentifier("title"),e.literal(r[0].title)):e.jsxAttribute(e.jsxIdentifier(""),null),r.length&&r[0].index===l&&r[0].description?e.jsxAttribute(e.jsxIdentifier("description"),e.literal(r[0].description)):e.jsxAttribute(e.jsxIdentifier(""),null),r.length&&r[0].index===l&&r[0].icon?e.jsxAttribute(e.jsxIdentifier("icon"),e.literal(r[0].icon.toLowerCase())):e.jsxAttribute(e.jsxIdentifier(""),null)],!0)))}e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProgressBar"),[e.jsxAttribute(e.jsxIdentifier("progressColor"),o.value),e.jsxAttribute(e.jsxIdentifier("title"),t.value),e.jsxAttribute(e.jsxIdentifier("showStepsCounter"),m.value),e.jsxAttribute(e.jsxIdentifier("disabled"),d.value)],!1),e.jsxClosingElement(e.jsxIdentifier("ProgressBar")),u))})}const U=g.reduce((n,[e,c,s,a])=>{let i=n[c];return i||(i={},n[c]=i),i[e]={newName:s,newPackage:a},n},{}),C={list:g,byOldPackage:U,props:O};function A(n,{jscodeshift:e},c){const s=e(n.source);return N(s,e),_(s,e),L(s,e),x(s,e,C),b(s,e,C),P(s,e),R(s,e),w(s,e),k(s,e),B(s,e),v(s,e),D(s,e),s.toSource(c?.woodland?.output)}A.parser="tsx";module.exports=A;
|
|
@@ -41,16 +41,17 @@ const jscodeshift = jscodeshiftModule.default ?? jscodeshiftModule;
|
|
|
41
41
|
// assume the mapping is "same name", some are exceptions.
|
|
42
42
|
//
|
|
43
43
|
// jsSubpath: subpath used for the bare package import, e.g.
|
|
44
|
-
// from "@sps-woodland/
|
|
44
|
+
// from "@sps-woodland/tags" -> from "@sps-woodland/core/tags"
|
|
45
45
|
// cssSubpath: subpath used when importing "<wrapperName>/style.css" — for
|
|
46
46
|
// every package this matches jsSubpath EXCEPT "buttons", whose CSS still
|
|
47
47
|
// lives under the plural "buttons" path even though the JS export is the
|
|
48
48
|
// singular "button".
|
|
49
|
+
//
|
|
50
|
+
// "cards" is deliberately NOT in this map — see CARDS_EXPORT_SUBPATH below.
|
|
49
51
|
const WRAPPER_TO_CORE = {
|
|
50
52
|
"action-bar": { jsSubpath: "action-bar", cssSubpath: "action-bar" },
|
|
51
53
|
"add-to-list": { jsSubpath: "add-to-list", cssSubpath: "add-to-list" },
|
|
52
54
|
"buttons": { jsSubpath: "button", cssSubpath: "buttons" }, // exception: singular JS, plural CSS
|
|
53
|
-
"cards": { jsSubpath: "cards", cssSubpath: "cards" },
|
|
54
55
|
"column-manager": { jsSubpath: "column-manager", cssSubpath: "column-manager" },
|
|
55
56
|
"content-row": { jsSubpath: "content-row", cssSubpath: "content-row" },
|
|
56
57
|
"content-tiles": { jsSubpath: "content-tiles", cssSubpath: "content-tiles" },
|
|
@@ -81,26 +82,83 @@ const WRAPPER_TO_CORE = {
|
|
|
81
82
|
// itself), @sps-woodland/tokens, @sps-woodland/illustrations,
|
|
82
83
|
// @sps-woodland/codemods (these ship real, independent code, not re-exports).
|
|
83
84
|
|
|
85
|
+
// "cards" is a multi-family wrapper: it re-exports three independent core
|
|
86
|
+
// families under one legacy package name (see
|
|
87
|
+
// packages/@sps-woodland/cards/src/index.ts) —
|
|
88
|
+
// export * from "@sps-woodland/core/cards";
|
|
89
|
+
// export * from "@sps-woodland/core/insight-card";
|
|
90
|
+
// export * from "@sps-woodland/core/scrollable-container";
|
|
91
|
+
// — and its style.css is a concatenation of all three families' style.css
|
|
92
|
+
// (see that package's build:css script). A single wrapper->subpath mapping
|
|
93
|
+
// would route every named import and every style.css import to just one of
|
|
94
|
+
// the three, silently dropping the other two. Route by the specific export
|
|
95
|
+
// name instead, and always expand its style.css into all three families'.
|
|
96
|
+
const CARDS_EXPORT_SUBPATH = {
|
|
97
|
+
Card: "cards",
|
|
98
|
+
CardHeader: "cards",
|
|
99
|
+
CardFooter: "cards",
|
|
100
|
+
CardTitle: "cards",
|
|
101
|
+
InsightCard: "insight-card",
|
|
102
|
+
InsightCardSet: "insight-card",
|
|
103
|
+
ScrollableContainer: "scrollable-container",
|
|
104
|
+
};
|
|
105
|
+
const CARDS_CSS_SUBPATHS = ["cards", "insight-card", "scrollable-container"];
|
|
106
|
+
|
|
84
107
|
const SCOPE = "@sps-woodland";
|
|
85
108
|
const JS_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
|
|
86
109
|
const CSS_EXTENSIONS = new Set([".css", ".scss", ".sass", ".less"]);
|
|
87
110
|
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", "lib", "coverage"]);
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
// Splits "@sps-woodland/cards/style.css" into { name: "cards", subRest:
|
|
113
|
+
// "/style.css" } (subRest is "" for a bare "@sps-woodland/<name>" import).
|
|
114
|
+
function splitScopedSpecifier(source) {
|
|
115
|
+
if (!source.startsWith(`${SCOPE}/`)) return null;
|
|
116
|
+
const rest = source.slice(SCOPE.length + 1);
|
|
92
117
|
const slashIdx = rest.indexOf("/");
|
|
93
118
|
const name = slashIdx === -1 ? rest : rest.slice(0, slashIdx);
|
|
94
|
-
const subRest = slashIdx === -1 ? "" : rest.slice(slashIdx);
|
|
119
|
+
const subRest = slashIdx === -1 ? "" : rest.slice(slashIdx);
|
|
120
|
+
return { name, subRest };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function resolveNewSource(oldSource) {
|
|
124
|
+
const parts = splitScopedSpecifier(oldSource);
|
|
125
|
+
if (!parts) return null;
|
|
95
126
|
|
|
96
|
-
const mapping = WRAPPER_TO_CORE[name];
|
|
127
|
+
const mapping = WRAPPER_TO_CORE[parts.name];
|
|
97
128
|
if (!mapping) return null; // not a known wrapper package — leave untouched
|
|
98
129
|
|
|
99
|
-
if (subRest === "") return `${SCOPE}/core/${mapping.jsSubpath}`;
|
|
100
|
-
if (subRest === "/style.css") return `${SCOPE}/core/${mapping.cssSubpath}/style.css`;
|
|
130
|
+
if (parts.subRest === "") return `${SCOPE}/core/${mapping.jsSubpath}`;
|
|
131
|
+
if (parts.subRest === "/style.css") return `${SCOPE}/core/${mapping.cssSubpath}/style.css`;
|
|
101
132
|
// Unknown deep subpath (rare) — map using the JS subpath and preserve
|
|
102
133
|
// whatever followed the package name, best-effort.
|
|
103
|
-
return `${SCOPE}/core/${mapping.jsSubpath}${subRest}`;
|
|
134
|
+
return `${SCOPE}/core/${mapping.jsSubpath}${parts.subRest}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// "cards" can't be resolved to a single new source string (see
|
|
138
|
+
// CARDS_EXPORT_SUBPATH above) — it needs to become several ImportDeclarations
|
|
139
|
+
// instead of having its source literal swapped in place. Returns the
|
|
140
|
+
// replacement declarations, or null if this import can't be split safely
|
|
141
|
+
// (a default/namespace import, an unrecognized named export, or a deep
|
|
142
|
+
// subpath) — callers leave those untouched and flag them for manual review.
|
|
143
|
+
function splitCardsImportDeclaration(j, node, subRest) {
|
|
144
|
+
if (subRest === "/style.css") {
|
|
145
|
+
return CARDS_CSS_SUBPATHS.map((sub) => j.importDeclaration([], j.literal(`${SCOPE}/core/${sub}/style.css`)));
|
|
146
|
+
}
|
|
147
|
+
if (subRest !== "") return null; // unrecognized deep subpath
|
|
148
|
+
|
|
149
|
+
const specifiers = node.specifiers;
|
|
150
|
+
if (specifiers.length === 0) return null; // bare side-effect import, nothing to route by
|
|
151
|
+
|
|
152
|
+
const bySubpath = new Map(); // subpath -> specifier[], insertion order
|
|
153
|
+
for (const spec of specifiers) {
|
|
154
|
+
if (spec.type !== "ImportSpecifier") return null; // default or namespace import
|
|
155
|
+
const sub = CARDS_EXPORT_SUBPATH[spec.imported.name];
|
|
156
|
+
if (!sub) return null; // not a recognized cards/insight-card/scrollable-container export
|
|
157
|
+
if (!bySubpath.has(sub)) bySubpath.set(sub, []);
|
|
158
|
+
bySubpath.get(sub).push(spec);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return [...bySubpath.entries()].map(([sub, specs]) => j.importDeclaration(specs, j.literal(`${SCOPE}/core/${sub}`)));
|
|
104
162
|
}
|
|
105
163
|
|
|
106
164
|
// Parses the file with jscodeshift (Babel/TSX parser) and rewrites only the
|
|
@@ -131,6 +189,21 @@ function transformSource(source) {
|
|
|
131
189
|
// Static: import ... from "@sps-woodland/<name>"
|
|
132
190
|
root.find(j.ImportDeclaration).forEach((p) => {
|
|
133
191
|
const node = p.node.source;
|
|
192
|
+
const value = node.value;
|
|
193
|
+
const parts = typeof value === "string" ? splitScopedSpecifier(value) : null;
|
|
194
|
+
|
|
195
|
+
if (parts && parts.name === "cards") {
|
|
196
|
+
const newDecls = splitCardsImportDeclaration(j, p.node, parts.subRest);
|
|
197
|
+
if (newDecls) {
|
|
198
|
+
const oldSource = `${SCOPE}/cards${parts.subRest}`;
|
|
199
|
+
p.replace(...newDecls);
|
|
200
|
+
changes.push({ oldSource, newSource: newDecls.map((d) => d.source.value).join(", ") });
|
|
201
|
+
} else {
|
|
202
|
+
unknown.add("cards");
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
134
207
|
maybeRewrite(node, (newValue) => {
|
|
135
208
|
node.value = newValue;
|
|
136
209
|
delete node.raw;
|
|
@@ -175,7 +248,40 @@ function transformCssSource(source) {
|
|
|
175
248
|
const changes = []; // { oldSource, newSource }
|
|
176
249
|
const unknown = new Set();
|
|
177
250
|
|
|
178
|
-
const output = source.replace(CSS_IMPORT_RE, (match, prefix, quote, name, rest) => {
|
|
251
|
+
const output = source.replace(CSS_IMPORT_RE, (match, prefix, quote, name, rest, offset, string) => {
|
|
252
|
+
if (name === "cards") {
|
|
253
|
+
if (rest !== "/style.css" && rest !== "/lib/style.css") {
|
|
254
|
+
unknown.add(`cards${rest}`);
|
|
255
|
+
return match;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// One @import can't become three without knowing what immediately
|
|
259
|
+
// follows the match (a plain ";", or url()'s ")" then ";") — a media
|
|
260
|
+
// query or anything else there would need to apply to all three
|
|
261
|
+
// splits, which we can't infer safely, so leave those for manual review.
|
|
262
|
+
const isUrl = /url\(\s*$/.test(prefix);
|
|
263
|
+
const tail = string.slice(offset + match.length);
|
|
264
|
+
if (!(isUrl ? /^\s*\)\s*;/ : /^\s*;/).test(tail)) {
|
|
265
|
+
unknown.add(`cards${rest} (unexpected trailing syntax after the @import — split into ${CARDS_CSS_SUBPATHS.length} imports manually)`);
|
|
266
|
+
return match;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const oldSource = `${SCOPE}/cards${rest}`;
|
|
270
|
+
const closeParen = isUrl ? ")" : "";
|
|
271
|
+
const statements = CARDS_CSS_SUBPATHS.map((sub, i) => {
|
|
272
|
+
const newPath = `${SCOPE}/core/${sub}/style.css`;
|
|
273
|
+
const isLast = i === CARDS_CSS_SUBPATHS.length - 1;
|
|
274
|
+
// The last split keeps whatever terminator (")" / ";" / media query)
|
|
275
|
+
// already follows the original match in the source untouched.
|
|
276
|
+
return `${prefix}${quote}${newPath}${quote}${isLast ? "" : `${closeParen};`}`;
|
|
277
|
+
});
|
|
278
|
+
changes.push({
|
|
279
|
+
oldSource,
|
|
280
|
+
newSource: CARDS_CSS_SUBPATHS.map((sub) => `${SCOPE}/core/${sub}/style.css`).join(", "),
|
|
281
|
+
});
|
|
282
|
+
return statements.join("\n");
|
|
283
|
+
}
|
|
284
|
+
|
|
179
285
|
const mapping = WRAPPER_TO_CORE[name];
|
|
180
286
|
if (!mapping) {
|
|
181
287
|
unknown.add(name);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sps-woodland/codemods",
|
|
3
3
|
"description": "SPS Woodland Design System codemods",
|
|
4
|
-
"version": "8.53.
|
|
4
|
+
"version": "8.53.13",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/woodland/tree/master/packages/@sps-woodland/codemods",
|
|
Binary file
|
|
Binary file
|