21

Background:

We are using yarn in this project and we don't want to write our package.json scripts with a mix of npm/yarn commands.

I have a root directory which contains a few subfolders.

Each holds a different service.

I want to create a script in the root folder that npm install each of the services, one by one.

Question:

Do you know what would be the yarn alternative to npm install <folder>?

I'm looking for something like this psuedo command: yarn <folder>

Community
  • 1
  • 1
ueeieiie
  • 1,412
  • 2
  • 15
  • 42

3 Answers3

40

You could use --cwd there is a git issue about this :

yarn --cwd "your/path" script

You can also use cd :

cd "your/path" && yarn script
ibenjelloun
  • 7,425
  • 2
  • 29
  • 53
3

To run yarn install on every subdirectory you can do something like:

"scripts": {
  ...
  "install:all": "for D in */; do yarn --cwd \"${D}\"; done"
}

where

install:all is just the name of the script, you can name it whatever you please

D Is the name of the directory at the current iteration

*/ Specifies where you want to look for subdirectories. directory/*/ will list all directories inside directory/ and directory/*/*/ will list all directories two levels in.

yarn -cwd install all dependencies in the given folder

You could also run several commands, for example:

for D in */; do echo \"Installing stuff on ${D}\" && yarn --cwd \"${D}\"; done

will print "Installing stuff on your_subfolder/" on every iteration.

whtlnv
  • 2,109
  • 1
  • 25
  • 26
1

To run multiple commands in a single subfolder:

cd your/path && yarn && yarn some-script
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232