If you’re not familiar with
npx, it’s a tool installed alongside
npmwhich allows execution of command-line Node.js packages without first having to
npm install --global <package-name>.
For example, running
npm init react-app will use
npx to grab
create-react-app, then execute its script specified in its
bin property of its
package.json. In other words,
npm init react-app is the same as invoking
Since the scaffolding tool Yeoman has a large ecosystem already, I thought it might be cool to piggyback on the new(-ish) functionality of
To run any Yeoman generator, all you need to do (given
npm v6.1.0+ and Node.js v8.0.0+) is execute:
$ npm init yo foo
foo refers to package
generator-foo. A more concrete example—to run Yeoman’s own generator-generator, would be this:
$ npm init yo generator
npx does its thing, you’ll be prompted to to complete the wizard.
It also supports subgenerators, e.g.:
$ npm init yo generator:subgenerator
subgenerator subgenerator of the
generator generator. Yep.
For The Curious
create-yo’s executable, which in turn invokes
npx (via libnpx) to run
yo’s executable. It uses
--package option to grab your generator. It is not fancy.
I'm happy to make this work with Yarn if possible (and would accept a PR to that effect), but don't use Yarn, so I won't be implementing it myself.
npm init yo <generator> instead of
npm install -g yo generator-<generator>; yo <generator>.