-
Notifications
You must be signed in to change notification settings - Fork 246
Description
Motivation ("The Why")
Most publicly available NPM packages are usually also open source and provide a link to their code repository through the repository field in their package.json file.
However, starting to work on the code for a package is not exactly a quick thing to do . You first have to find it (it doesn't necessarily have to live on GitHub) and then manually install the dependencies before you may begin.
I came up with a much simpler solution: npm clone
How
Cloning from a source
npm clone <packageName>
would go look into the repository configuration of packageName on the NPM registry (default, can be overridden with --registry as usual) and clones it from there with whatever program can be found that might make sense (git, svn, hg?).
It would look at the repository.type set in the package.json.
"type": "git"-> use git"type": "svn"-> use something like TortoiseSVN.
npm clone <URL>
would clone from the given URL and, if it's an NPM package (package.json or package-lock.json was found), then do the same as above.
After cloning
Unless an option like --no-install is given, npm clone could then install the dependencies for that package or run a script!
Options
| Option | Parameters | Default | Meaning |
|---|---|---|---|
-d / --dest |
<path> |
The current directory | Where to clone the code to |
-w / --work-dir |
<path> |
The root directory of the repository | Where to run the npm commands (such as npm install) inside the cloned worktree |
-s / --script |
<script> |
A script to run after cloning | |
-n / --no-install |
No automatic install will be run |
Note: These options names are mere suggestions. If you can come up with something that makes more sense, please let me know.
Example
| Command | Result |
|---|---|
npm clone express -s test |
Clones the source of the express package and runs tests. |
npm clone typescript -n |
Clones TypeScript from GitHub and then does nothing. |
npm clone https://github.com/badges/shields -w gh-badges |
Clones the shields repository from GitHub and installs the dependencies of the gh-badges package in the gh-badges directory. |
Current Behaviour
You have to do these things:
- Find out where the code lives.
- Clone it from there.
- Install the dependencies.
Desired Behaviour
Run npm clone <package> with whatever options suit your case and you're good to go.
References
- Original post featuring this idea in the archived NPM forums.