Smart-Spike / mono

A mono repo for managing multiple projects
0 stars 0 forks source link

Mono

This repo is managed as a monorepo that is composed of:

The mono repo is managed by Lerna using Yarn workspaces.

Getting started

Install any root dev dependencies and bootstrap all packages:

$ yarn install
$ npx lerna bootstrap

This will...


NOTE: prefixing the command with npx means that you don’t need to globally install lerna.


Adding dependencies

Published dependencies from e.g. npm can be added to individual package(s) either by running the normal yarn commands inside the relevant package. It's recommended to re-run npx lerna bootstrap after doing this so that lerna can re-link any packages.

However to add a dependency to multiple packages/projects or to add a local package you can run:

npx lerna add <package>[@version] [--dev] [--scope=<package|project>]

E.g. to add babel-cli as a dev dependency to all packages you would run npx lerna add babel-cli --dev. Or to add it to only specific projects or packages you could run npx lerna add babel-cli --scope=@namespace/pkg-a --scope=project-awesome. Lerna can then make use of hoisting to move the dependency to the root level node_modules directory and avoid duplication.

Running npm scripts

Any package or project script can be run from the root by using:

npx lerna run <script> -- [..args]

For example to run the test script for a specific package you would use:

npx lerna run test --scope=@mono/package-a

If you omitted the --scope argument the test script would be run for all packages and projects.

For long-running processes it is preferable to use lerna exec rather than lerna run For example:

npx lerna exec --scope=project-foo -- yarn run start