ueeieiie
ueeieiie

Reputation: 1562

Is there's a command for yarn to install a subfolder?

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>

Upvotes: 23

Views: 22338

Answers (3)

whtlnv
whtlnv

Reputation: 2217

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.

Upvotes: 3

Fellow Stranger
Fellow Stranger

Reputation: 34063

To run multiple commands in a single subfolder:

cd your/path && yarn && yarn some-script

Upvotes: 1

ibenjelloun
ibenjelloun

Reputation: 7733

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

Upvotes: 43

Related Questions