2

How do I pass a parameter? When I run "yarn generate" it will make both a "-p" and a "test" directory. But it works well when I run "mkdir -p test" in bash. I tried to [-p] as well but it only creates that directory.

"scripts": {
    "generate": "mkdir -p test"
  }
0

1 Answer 1

3

Although I could not reproduce the issue that you mentioned (my config: node v8.11.1 and yarn v1.2.1, latest MacOS), according to the yarn docs, you can pass the arguments to yarn script by appending them normally, like so:

yarn generate -p test

In this case your npm (yarn) scripts config (in the package.json, I assume) would look like

"scripts": {
    "generate": "mkdir"
}

If you're using Windows, you indeed won't have the mkdir -p flag (read this). In order to make what you want (check if the folder does not exist and if so, create one) you'd need to use some cmd commands. So your package.json will contain smth like

"scripts": { 
    "generate": "IF NOT EXIST test mkdir test" 
}
Sign up to request clarification or add additional context in comments.

7 Comments

I run on windows. Yes it's in the package.json and it looks like it does in my question :) I want to create a folder and the parameter -p is for ignore createing the folder if it already exist. But when I run it with yarn it creates both a "test" and a "-p" folder
Well, then it's a completely different issue, because -p is not supported in Windows' mkdir. stackoverflow.com/questions/905226/… And in order to make what you want you'd need to use some cmd commands, like here stackoverflow.com/questions/21033801/… So your package.json will contain smth like "scripts": { "generate": "IF NOT EXIST test mkdir test" }
I'm afraid in order to make it work on mac you'll need another npm (package.json) script
it should work with this? "scripts": { "generate-pc": "IF NOT EXIST test mkdir test", "generate-mac": "mkdir -p test"}
yes,looks like it :) Tested first script on Windows and the second on Mac, they seem to work as expected!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.