Run yarn/npm scripts from a subfolder's package.json

Viewed 19

I maintain a monorepo for the react-querybuilder package. I'm merging in the documentation website code under the /website directory, but not as a workspace (those are in /packages/*).

The /website directory has its own package.json with the docusaurus * scripts (start/build/deploy/etc.). I'd like to have scripts in the root /package.json that execute the scripts in /website/package.json. Currently I have something like this in /package.json:

{
  "scripts": {
    "website:install": "cd website && yarn",
    "website:start": "cd website && yarn start",
    "website:build": "cd website && yarn build",
    "website:deploy": "cd website && yarn deploy"
  }
}

Is there a better, more generic way to do that? This way I have to name every script twice, once in /package.json and once in /website/package.json.

(I tried --cwd, but that doesn't actually run scripts defined in that other directory's package.json. It runs the scripts defined in the root package.json from the other directory. E.g., yarn --cwd website build is effectively the same as yarn build, at least in my case.)

I thought there might be a yarn flag like --cwd (--pkg? --config?) that actually runs the scripts defined in the other directory, or maybe you'd have to specify a file.

Am I missing something?

0 Answers
Related