multi-npm v1.0.8
Multiple node Package Manager (MPM)
An open-source library to manage multiple packages.
mpm enable you to clone, install, sync, build and link your packages in a multi-package / component solution.
It is perfect to be used as a dev tool in a micro-services environment.
Instead of cloning multiple repositories / packages, navigating to each one, installing it, building,
starting it manually and configure how each package "talks" with the other in your local dev environment,
you can use simple mpm install, mpm link, and mpm start commands to install all your packages, link, and start those.
The library if fully customizable and gives you full control via the multi-package.json file.
There you define the packages, their scripts and more.

Platforms
Currenly supported only for Mac OS and Linux. You are welcomed to contribute more support ;)
Installation
npm install -g multi-npm
Usage
- Initiate an mpm project
$ mkdir <your-projects-folder> $ cd <your-projects-folder> $ mpm init - Follow the
mpm initinstructions to create yourmulti-package.json - Install your packages
$ mpm install - Run
$ mpm link - Run
$ mpm start - Sync (git-wise)
$ mpm pull - Add whichever commands and scripts you would like.
The mutli-package.json file:
The multi-package.json file holds the packages configuration for the different scripts.
{
"packages": {
"package1": {
"name": "package1",
"repository": "https://github.com/<package1>.git",
"branch": "<The desired working branch to sync with>",
"scripts": {
"install": "git clone https://github.com/<package1>.git <package1> && cd <package1> && git checkout <working-branch> && npm install",
"pull": "git stash && git pull --rebase && git stash pop && npm install"
}
},
"package2": {
"name": "package2",
"repository": "https://github.com/<package2>.git",
"branch": "<The desired working branch to sync with>",
"scripts": {
"install": "git clone https://github.com/<package1>.git <package2> && cd <package2> && git checkout <working-branch> && npm install && node **do-something-important-after-install.js**",
"pull": "git stash && git pull --rebase && git stash pop && npm install"
}
}
},
"scripts": {
"build": "node my-custom-build-script.js"
}
}It has 2 sections:
1. packages: an object with all the packages configuration.
Each package configuration has a name key, and scripts section.
The repository and branch keys are not required, and are added during the "wizard"-like mpm init process.
The important section is the scripts section, in which the different custom scripts are defined.
When running mpm install for example, mpm iterates through the install scripts (defined in the multi-package.json) for each package and run it (synchronized).
In case the script is not defined in the multi-package.json file, but it is a valid npm script (e.g. update), mpm would run it as well.
Meaning, all npm scripts are inherently supported, unless overriden by the multi-package.json file.
Running mpm my-script will run all matching scripts in the multi-package.json packages sections.
Important note: In case of an overlap between a script name defined in the
packagessection, and a script defined in thescriptssection, thescriptswill run, and thepackagesscripts will not.
init: Initiates themulti-package.jsonfile.start: Runs the start script of the different packages (as defined in themulti-package.jsonfile) - each in its own terminal tab.link: Create symlinks between all your local packages. see below. e.g. runningmpm startfor 5 packages, opens 5 different terminal tabs, navigates to each package in the corresponding tab, and run the start script for it. You may pass a-por--packageparameter to run specific packages (e.g.mpm start -p package1 -p package4)
scripts: Holds the custom scripts you may want to add to mpm. In the initialmulti-package.jsonfile created in the init process, this section is empty. You may add scripts you can run viampm myCustomeScript.
Linking of local packages
mpm provides an option to create all the symlinks between your packages automatically using mpm link.
Assuming npm install had been run for each package, it goes throught all the node_modules of each package,
and replaces the packages that are also found in the root mpm folder with a symlink to the local package.
for example:
root
|
- lib1
- package1
|
-lib1
-lib2
...
- package2
- ...In the example above, mpm link would replace lib1 inside package1/node_modules with a symlink to root/lib1.
It achieves the same result as runnin npm install '../lib1' from within root/package1 folder.
That way, the package.json file reamins unchanged for package1 and commits can be done without any staging problems.