generate / generate-license

Generate a license file from the command line when Generate is installed globally, or use this generator as a plugin or sub-generator in your own generator project.
MIT License
91 stars 10 forks source link

Not working with npx #8

Open Graham42 opened 6 years ago

Graham42 commented 6 years ago

Instead of installing anything globally, I've moved to use npx which comes with npm 5, which is default with node 8

Expected this to work:

$ npx -p generate -p generate-license gen license

Instead I get this error trace

$ npx -p generate -p generate-license gen license
npx: installed 1432 in 18.068s
[14:41:45] starting generate
[14:41:45] ✔ running tasks: [ 'license' ]
Error: Cannot find generator: "license" in "/home/grahamm/<project_dir>"
    at Generate.<anonymous> (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/base-generators/index.js:499:18)
    at iterate (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/async-each-series/index.js:8:5)
    at Function.module.exports (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/async-each-series/index.js:20:3)
    at Generate.generate (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/base-generators/index.js:492:15)
    at /home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/base-generators/index.js:475:18
    at iterate (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/async-each-series/index.js:8:5)
    at Function.module.exports (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/async-each-series/index.js:20:3)
    at Generate.generate (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/base-generators/index.js:474:24)
    at Generate.generate (/home/grahamm/.npm/_npx/7206/lib/node_modules/generate/node_modules/base-generators/index.js:463:23)
    at /home/grahamm/.npm/_npx/7206/lib/node_modules/generate/bin/generate.js:117:11
jonschlinkert commented 6 years ago

What is npx? Is that a license supported by https://github.com/github/choosealicense.com (as stated on the readme)?

jonschlinkert commented 6 years ago

Oh, I see, npx is something else. I don't know anything about npm, so I might need to rely on someone else to help.

That error message isn't very helpful, I'll look into why it's happening, but it might be something to do with npx

Graham42 commented 6 years ago

For reference, this is npx https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b

doowb commented 6 years ago

@Graham42 I just looked into this some.

When using npx with the -p flag, npx will download the package into a temporary "global" folder. The way generate works is that it will look for modules in the actual npm global folder, local node_modules folder, and for a local generator.js file. Since npx is putting generate-license into a temporary folder, generate doesn't know where to find it.

I tried this out by installing generate-license locally: npm i generate-license, then I was able to run npx like this: npx -p generate gen license.

I'm not sure if there's anything we can do since npx is creating temporary directories sometimes.