plopjs / plop

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

`No plopfile found` with NPX package #443

Closed JulSeb42 closed 1 month ago

JulSeb42 commented 1 month ago

Hello,

I'm building a React app boilerplate generator with an NPX package. The CLI works when I'm inside the package folder, but when I'm inside another folder I get this error:

[PLOP] No plopfile found

Any idea why?

This is the command I run for the CLI:

npx julseb-plop-utils

You can find the repo here: https://github.com/JulSeb42/julseb-plop-utils And the npm package here: https://www.npmjs.com/package/julseb-plop-utils

Thanks!

crutchcorn commented 1 month ago

It's this:

https://github.com/JulSeb42/julseb-plop-utils/blob/master/index.js#L10

You need to resolve from process.cwd(), not __dirname. Dirname resolves from the file's location on disk, in your case node_modules

JulSeb42 commented 1 month ago

Nope I'm getting the same error. This is my new line:

configPath: `${process.cwd()}/scripts/plopfile.js`,

I tried to log the cwd in the return function, I get a path to my local folder

JulSeb42 commented 1 month ago

I could find the solution, this is my new index.js, now the command works as expected:

const __dirname = dirname(fileURLToPath(import.meta.url))

Plop.prepare(
    {
        cwd: argv.cwd,
        configPath: path.join(__dirname, "scripts/plopfile.js"),
        preload: argv.preload || [],
        completion: argv.completion,
    },
    env => Plop.execute(env, run)
)

Thanks!