@sps-woodland/codemods 0.0.3 → 7.0.0

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 P(s,e,t){const o=s.find(e.ImportDeclaration),r=new Map;for(const c of Object.keys(t.byOldPackage)){const{oldNames:l,newPackages:n}=t.byOldPackage[c];o.filter(d=>d.node.source.value===c).forEach(d=>{const k=e(d).replaceWith(e.importDeclaration(d.node.specifiers.filter(a=>!l.has(a.imported.name)),d.node.source));for(const a of Object.keys(n)){const p=n[a];if(r.has(a)){const i=r.get(a),m=e.importDeclaration([...i.node.specifiers,...p.map(w=>e.importSpecifier(e.identifier(w)))],i.node.source);r.set(a,m),e(i).replaceWith(m)}else{const i=e.importDeclaration(p.map(m=>e.importSpecifier(e.identifier(m))),e.literal(a));r.set(a,i),k.insertAfter(i)}}})}}function u(s,e,t){const o=s.find(e.JSXOpeningElement),r=s.find(e.JSXClosingElement);for(const{oldName:c,newName:l}of t.list)o.filter(n=>n.node.name.name===c).forEach(n=>{e(n).replaceWith(e.jsxOpeningElement(e.jsxIdentifier(l),n.node.attributes,n.node.selfClosing))}),r.filter(n=>n.node.name.name===c).forEach(n=>{e(n).replaceWith(e.jsxClosingElement(e.jsxIdentifier(l),n.node.attributes,n.node.selfClosing))})}const g=[{oldName:"SpsCardV2",newName:"Card",newPackage:"@woodland/cards",oldPackage:"@spscommerce/ds-react"}],N=g.reduce((s,e)=>{let t=s[e.oldPackage];t||(s[e.oldPackage]=t={oldNames:new Set,newPackages:{}}),t.oldNames.add(e.oldName);let o=t.newPackages[e.newPackage];return o||(t.newPackages[e.newPackage]=o=[]),o.push(e.newName),s},{}),f={list:g,byOldPackage:N};function h(s,{jscodeshift:e},t){const o=e(s.source);return P(o,e,f),u(o,e,f),o.toSource()}module.exports=h;
1
+ "use strict";function L(l,e){l.find(e.JSXOpeningElement).filter(s=>s.node.name.name==="KeyValueSetItem").forEach(s=>{const{itemKeyProp:a,titleColorProp:n,otherAttrs:r}=s.node.attributes.reduce((c,i)=>{switch(i.name.name){case"itemKey":c.itemKeyProp=i;break;case"titleColor":c.titleColorProp=i;break;default:c.otherAttrs.push(i)}return c},{itemKeyProp:null,titleColorProp:null,otherAttrs:[]});if(!n)return;const t=n.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,...r],s.node.selfClosing))})}function g(l,e){l.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsMicroBlock").forEach(s=>{const{messageProp:a,otherAttrs:n}=s.value.openingElement.attributes.reduce((r,t)=>{switch(t.name.name){case"message":r.messageProp=t;break;default:r.otherAttrs.push(t)}return r},{messageProp:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsMicroBlock"),[e.jsxAttribute(e.jsxIdentifier("micro"),null),...n],!1),e.jsxClosingElement(e.jsxIdentifier("SpsMicroBlock")),[e.jsxText(a.value.value)]))})}function O(l,e,o){const s=l.find(e.ImportDeclaration),a=new Map;for(const n of Object.keys(o.byOldPackage)){const r=o.byOldPackage[n];s.filter(t=>{var c;return((c=t.value)==null?void 0:c.type)==="ImportDeclaration"&&t.node.source.value===n}).forEach(t=>{const c=new Set,i=t.node.specifiers.filter(p=>r.hasOwnProperty(p.imported.name)?(c.add(p.imported.name),!1):!0),d=i.length===0,S=e(t);d||S.replaceWith(e.importDeclaration(i,t.node.source));const I=Array.from(c).reduce((p,u)=>{const{newName:m,newPackage:E}=r[u];return p.hasOwnProperty(E)||(p[E]=[]),p[E].push(m),p},{});for(const p of Object.keys(I)){const u=I[p];if(a.has(p)){const m=a.get(p),E=u.map(f=>e.importSpecifier(e.identifier(f))),T=e.importDeclaration([...m.node.specifiers,...E],m.node.source);a.set(p,T),e(m).replaceWith(T)}else{const m=e.importDeclaration(u.map(E=>e.importSpecifier(e.identifier(E))),e.literal(p));a.set(p,m),S.insertAfter(m)}}d&&S.remove()})}}function h(l,e,o){const s=l.find(e.JSXOpeningElement),a=l.find(e.JSXClosingElement);for(const[n,,r]of o.list)s.filter(t=>t.node.name.name===n).forEach(t=>{let{attributes:c}=t.node;if(o.props.hasOwnProperty(r)){const i=o.props[r];c=c.map(d=>i.hasOwnProperty(d.name.name)?e.jsxAttribute(e.jsxIdentifier(d.name.name),e.literal(i[d.name.name][d.value.expression.property.name])):d)}e(t).replaceWith(e.jsxOpeningElement(e.jsxIdentifier(r),c,t.node.selfClosing))}),a.filter(t=>t.node.name.name===n).forEach(t=>{e(t).replaceWith(e.jsxClosingElement(e.jsxIdentifier(r),t.node.attributes,t.node.selfClosing))})}const R=[["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"],["SpsPageTitle","@spscommerce/ds-react","PageTitle","@sps-woodland/page-title"],["SpsPageSubtitle","@spscommerce/ds-react","PageSubtitle","@sps-woodland/page-title"],["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"],["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"],["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"]],C={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"},_={Icon:{icon:C,size:{EXTRA_SMALL:"xs",SMALL:"sm",MEDIUM:"md",LARGE:"lg",EXTRA_LARGE:"lg"}},InsightCard:{icon:C,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"}}};function k(l,e){l.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="Tag").forEach(s=>{const{iconProp:a,otherAttrs:n}=s.value.openingElement.attributes.reduce((r,t)=>{switch(t.name.name){case"icon":r.iconProp=t;break;default:r.otherAttrs.push(t)}return r},{iconProp:null,otherAttrs:[]});a&&e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("Tag"),[e.jsxAttribute(e.jsxIdentifier("icon"),null),...n],!1),e.jsxClosingElement(e.jsxIdentifier("Tag"))))})}function N(l,e){l.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="KeyValueTag").forEach(s=>{const{iconProp:a,otherAttrs:n}=s.value.openingElement.attributes.reduce((r,t)=>{switch(t.name.name){case"icon":r.iconProp=t;break;default:r.otherAttrs.push(t)}return r},{iconProp:null,otherAttrs:[]});a&&e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("KeyValueTag"),[e.jsxAttribute(e.jsxIdentifier("icon"),null),...n],!1),e.jsxClosingElement(e.jsxIdentifier("KeyValueTag"))))})}function b(l,e){l.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsMicroZeroState").forEach(s=>{const{attrs:a}=s.value.openingElement.attributes.reduce((n,r)=>(n.attrs.push(r),n),{attrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsMicroZeroState"),[e.jsxAttribute(e.jsxIdentifier("micro"),null),...a],!0)))})}function w(l,e){l.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="SpsProductBar").forEach(s=>{const{productName:a,nameClick:n,logoSrc:r,productLink:t,otherAttrs:c}=s.value.openingElement.attributes.reduce((i,d)=>{switch(d.name.name){case"productName":i.productName=d;break;case"onProductNameClick":i.nameClick=d;break;case"productLogoSrc":i.logoSrc=d;break;case"productNameHref":i.productLink=d;break;case"tabs":break;case"activeTabs":break;case"onTabChange":break;default:i.otherAttrs.push(d)}return i},{productName:null,nameClick:null,logoSrc:null,productLink:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("SpsProductBar"),[...c],!1),e.jsxClosingElement(e.jsxIdentifier("SpsProductBar")),[e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProductBarName"),[e.jsxAttribute(e.jsxIdentifier("name"),e.literal(a.value.value)),e.jsxAttribute(e.jsxIdentifier("logoSrc"),e.literal(r.value.value)),n&&e.jsxAttribute(e.jsxIdentifier("onClick"),n.value),t&&e.jsxAttribute(e.jsxIdentifier("href"),e.literal(t.value.value))].filter(Boolean),!0)),...s.node.children]))})}function P(l,e){l.find(e.JSXElement).filter(s=>s.value.openingElement.name.name==="ProductBarTab").forEach(s=>{const{clickHandler:a,otherAttrs:n}=s.value.openingElement.attributes.reduce((r,t)=>{switch(t.name.name){case"onClick":r.clickHandler=t;break;default:r.otherAttrs.push(t)}return r},{clickHandler:null,otherAttrs:[]});e(s).replaceWith(e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("ProductBarTab"),[e.jsxAttribute(e.jsxIdentifier("onPress"),a.value),...n],!1),e.jsxClosingElement(e.jsxIdentifier("ProductBarTab")),[...s.node.children]))})}const x=R.reduce((l,[e,o,s,a])=>{let n=l[o];return n||(n={},l[o]=n),n[e]={newName:s,newPackage:a},l},{}),A={list:R,byOldPackage:x,props:_};function D(l,{jscodeshift:e}){const o=e(l.source);return b(o,e),w(o,e),g(o,e),O(o,e,A),h(o,e,A),P(o,e),L(o,e),k(o,e),N(o,e),o.toSource()}module.exports=D;
package/main.js CHANGED
@@ -1,23 +1,97 @@
1
1
  #!/usr/bin/env node
2
+ const fs = require("fs");
3
+ const glob = require("glob");
4
+ const path = require("path");
2
5
  const yargs = require("yargs");
3
6
  const { run } = require("jscodeshift/src/Runner")
4
7
 
8
+ const WOODLAND_CONFIG_FILENAME = "woodland.config.json";
9
+
5
10
  const yargv = yargs
6
- .usage("Usage: $0 [options]")
7
- .option("verbose", {
8
- alias: "v",
9
- type: "boolean",
10
- description: "Print additional details to console"
11
+ .usage("Usage: $0 [options] [...globs]")
12
+ .options({
13
+ "dry-run": {
14
+ alias: "d",
15
+ type: "boolean",
16
+ description: "Perform a dry run, printing transformation output to the console and not writing to any files",
17
+ },
18
+ "dry-no-print": {
19
+ type: "boolean",
20
+ description: "Suppress printing transformation output in a dry run",
21
+ },
22
+ "ignore": {
23
+ type: "array",
24
+ },
25
+ "verbose": {
26
+ alias: "v",
27
+ type: "boolean",
28
+ description: "Print additional details to console",
29
+ },
30
+ "vv": {
31
+ type: "boolean",
32
+ description: "Print even more additional details to console (includes --verbose)"
33
+ }
11
34
  })
12
35
  .help("help")
13
36
  .alias("help", "h").argv;
14
37
 
15
- console.log(yargv);
38
+ if (yargv.vv) {
39
+ Object.assign(yargv, {
40
+ verbose: true,
41
+ v: true,
42
+ });
43
+ console.log("Received parameters:", yargv);
44
+ }
45
+
46
+ const config = {
47
+ dryRun: false,
48
+ dryNoPrint: false,
49
+ files: ["**/*.+(t|j)s*(x)"],
50
+ ignore: [],
51
+ verbose: false,
52
+ };
53
+
54
+ if (fs.existsSync(WOODLAND_CONFIG_FILENAME)) {
55
+ const woodlandConfig = JSON.parse(fs.readFileSync(WOODLAND_CONFIG_FILENAME));
56
+ if (woodlandConfig.hasOwnProperty("codemods")) {
57
+ Object.assign(config, woodlandConfig.codemods);
58
+ }
59
+ }
60
+
61
+ if (yargv._.length > 0) {
62
+ config.files = yargv._;
63
+ }
64
+
65
+ for (const key of Object.keys(yargv)) {
66
+ if (config.hasOwnProperty(key)) {
67
+ config[key] = yargv[key];
68
+ }
69
+ }
70
+
71
+ // ALWAYS ignore node_modules
72
+ config.ignore.push("node_modules/**/*");
73
+
74
+ if (yargv.vv) {
75
+ console.log("Resolved config:");
76
+ console.log(JSON.stringify(config, null, 4));
77
+ }
78
+
79
+ const transformFile = path.resolve(__dirname, "./dist/transform.js")
80
+
81
+ const targets = config.files
82
+ .map((globStr) => glob.sync(globStr, {
83
+ ignore: config.ignore,
84
+ }))
85
+ .reduce((acc, list) => acc.concat(list), []);
86
+ if (config.verbose) {
87
+ console.log("Matched the following files to be modded:");
88
+ console.log(JSON.stringify(targets, null, 4));
89
+ }
16
90
 
17
- run("node_modules/@sps-woodland/codemods/dist/transform.js", ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"], {
18
- dry: true,
19
- print: true,
20
- verbose: 1,
21
- }).then((result) => {
22
- console.log(result);
91
+ run(transformFile, targets, {
92
+ dry: config.dryRun,
93
+ print: config.dryRun && !config.dryNoPrint,
94
+ verbose: config.verbose,
95
+ extensions: "tsx",
96
+ parser: "tsx"
23
97
  });
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@sps-woodland/codemods",
3
3
  "description": "SPS Woodland Design System codemods",
4
- "version": "0.0.3",
4
+ "version": "7.0.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/spscommerce/woodland/tree/master/packages/@sps-woodland/codemods",
8
8
  "homepage": "https://github.com/spscommerce/woodland/tree/master/packages/@sps-woodland/codemods#readme",
9
+ "scripts": {
10
+ "build": "vite build",
11
+ "clean": "git clean -fdX",
12
+ "pub": "pnpm pack && npm publish"
13
+ },
9
14
  "main": "./main.js",
10
15
  "bin": "./main.js",
11
16
  "publishConfig": {
@@ -16,12 +21,8 @@
16
21
  "@babel/preset-env": "^7.1.6",
17
22
  "chalk": "^2.4.1",
18
23
  "concat-stream": "^1.6.2",
24
+ "glob": "^8.0.3",
19
25
  "jscodeshift": "^0.13.1",
20
26
  "yargs": "^12.0.2"
21
- },
22
- "scripts": {
23
- "build": "vite build",
24
- "clean": "git clean -fdX",
25
- "pub": "pnpm pack && npm publish"
26
27
  }
27
- }
28
+ }
Binary file
package/vite.config.js CHANGED
@@ -4,7 +4,7 @@ import { defineConfig } from "vite";
4
4
  export default defineConfig({
5
5
  build: {
6
6
  lib: {
7
- entry: path.resolve(__dirname, "src/transform.js"),
7
+ entry: path.resolve(__dirname, "src/transform.ts"),
8
8
  formats: ["cjs"],
9
9
  fileName: "transform",
10
10
  },