Summary
I am trying to pass command-line options to my plop script, but it instead provides an error message:
/usr/local/Cellar/node/22.9.0_1/bin/node: bad option: --plopfile=plopfile.ts
ELIFECYCLE Command failed with exit code 9.
I am using a TypeScript plopfile, inspired by #423 and documented here.
How to Reproduce
Create a package.json
{
"name": "plop-cmd-bug",
"type": "module",
"scripts": {
"plop": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts"
},
"dependencies": {
"plop": "^4.0.1",
"typescript": "^5.6.3"
},
"devDependencies": {
"cross-env": "^7.0.3",
"tsx": "^4.19.1"
},
"packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
}
Create a plopfile.ts
import type { NodePlopAPI } from "plop";
export default function (plop: NodePlopAPI) {
plop.setGenerator("sample", {
description: "Sample Generator to show bug with command line arguments.",
prompts: [
{
type: "input",
name: "name",
message: "Project Name:",
},
{
type: "input",
name: "title",
message: "Project Title:",
},
],
actions: ["No operation necessary"],
});
}
Install dependencies
Validate that Prompts Work Fine
Run the plop script and answer the prompts. It will look something like this:
$ pnpm plop sample
> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample"
? Project Name: my-name
? Project Title: My Title
ℹ No operation necessary
Use Command Line Parameters to Bypass Prompts 🐛
Run the plop script with answers to bypass the prompts. It will look something like this:
$ pnpm plop sample -- --name my-name --title "My Title"
> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample" "--" "--name" "my-name" "--title" "My Title"
/usr/local/Cellar/node/22.9.0_1/bin/node: bad option: --plopfile=plopfile.ts
ELIFECYCLE Command failed with exit code 9.
Interesting Note 🤔
If you only supply name and not title, then it works fine:
$ pnpm plop sample -- --name my-name
> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample" "--" "--name" "my-name"
? Project Title: My Title
ℹ No operation necessary
Also, if you remove the title from the prompts and simply have the one name prompt left, then that will work fine too:
$ pnpm plop sample -- --name my-name
> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample" "--" "--name" "my-name"
ℹ No operation necessary
Please help 🛟
Summary
I am trying to pass command-line options to my plop script, but it instead provides an error message:
I am using a TypeScript plopfile, inspired by #423 and documented here.
How to Reproduce
Create a
package.json{ "name": "plop-cmd-bug", "type": "module", "scripts": { "plop": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts" }, "dependencies": { "plop": "^4.0.1", "typescript": "^5.6.3" }, "devDependencies": { "cross-env": "^7.0.3", "tsx": "^4.19.1" }, "packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4" }Create a
plopfile.tsInstall dependencies
Validate that Prompts Work Fine
Run the
plopscript and answer the prompts. It will look something like this:Use Command Line Parameters to Bypass Prompts 🐛
Run the
plopscript with answers to bypass the prompts. It will look something like this:Interesting Note 🤔
If you only supply
nameand nottitle, then it works fine:Also, if you remove the
titlefrom thepromptsand simply have the onenameprompt left, then that will work fine too:Please help 🛟