plopjs / plop

Consistency Made Simple
http://plopjs.com
MIT License
7.06k stars 277 forks source link

Action `type: "modify"`'s `pattern` property should be built as a Handlebars template #406

Closed sethidden closed 3 months ago

sethidden commented 9 months ago

Say you want to turn:

// many other similar looking imports above, but I want to modify specifically {{ importName }}
import {
 foo,
 bar,
} from './{{ importName }}'

into

import {
 foo,
 bar,
 {{ methodName }}, // baz
} from './{{ importName }}'

To do that, you'll need to do

actions: (data) => [
  {
    type: "modify",
    pattern: `} from "./${data.importName}";`,
    path: "src/index.ts",
    template: '  {{methodName}},\n} from "./{{ importName }}";',
  },
]

What I'm proposing is that this should be possible to do without having to turn the "actions" array into a function that returns an array. Above it's done purely to create my own dynamic template for the pattern property because pattern is not transformed using Handlebars, so I need to do it manually using data.methodName

Alternatively, you can close this issue and tell me to reorganize my imports in such a way where this magic isn't necessary :P

sethidden commented 3 months ago

Stale