soft-add-dependencies v2.0.0
soft-add-dependencies
⚡️ Add dependencies to your package.json without installing them.
sort-add-dependencies is a small package to add dependencies without installing them. It has a powerful yet easy JavaScript and TypeScript API, with chainable methods, promise support, and strong typings, but it also has a CLI to add packages from your terminal!
Table of Contents
Usage
CLI
Explanations
soft-add-dependencies works great in the cli. You first need to install it:
$ npm i soft-add-dependencies [-g]And then run it with npx if it is installed locally, or simply by calling soft-add-dependencies:
$ npx soft-add-dependencies
$ soft-add-dependenciesYou first have to put the path to the package json. If it is not set, it will default to ./package.json. If no such file exist, it will create one. Then you have to enter all the dependencies you want to add, separated by a space.
You can also add flags and options:
- If you add the
--overwriteflag, it will overwrite the version of the package if already installed. - You can specify the package type with
--save-mode <dep/dev/peer/optional>.
Examples
$ soft-add-dependencies ./project/package.json eslint eslint-plugin-foo -m dev
$ soft-add-dependencies zlib-sync sodium --overwrite --mode optionalCode
API
enum SaveMode
Normal:'dependencies'Dev:'devDependencies'Peer:'peerDependencies'Optional:'optionalDependencies'
class SoftAddDependencies(optionsOrDestination)
Parameters:
- An object with the following fields:
destination(mandatory) (string): The destination pathoverwrite(optional) (boolean): If it should overwrite the version if the package is already presentpackages(optional) (string[]): List of packages to installsaveMode(optional) (SaveMode): The mode to save the dependencies
- A
string, which is the destination path
NOTE: If the provided destination is absolute, then it will be used. Otherwise, it will be used relatively to the current working directory (process.cwd())
SoftAddDependencies#overwrite()
- Parameters: None
- Returns:
this - Set the
overwriteproperty to true
SoftAddDependencies#add(...dependencies)
- Parameters:
...dependencies(string[]): The dependencies to add - Returns:
this - Add the given dependencies to the list
SoftAddDependencies#as(mode)
- Parameters:
mode(SaveMode): The mode to save the dependencies - Returns:
this - Set the
saveModeproperty to the mode given in the parameter
SoftAddDependencies#run()
- Parameters: None
- Returns:
Promise<void> - Run the installation process.
Examples
You can also use soft-add-dependencies directly inside your JavaScript/TypeScript code.
import SoftAddDependencies, { SaveMode } from 'soft-add-dependencies';
// Using options in the constructor:
await new SoftAddDependencies({
destination: './project/package.json',
packages: ['@babel/core', '@babel/node', '@babel/preset-env'],
overwrite: true,
saveMode: SaveMode.Dev,
}).run();
// Or using the chainable API:
await new SoftAddDependencies('./project/package.json')
.add('@babel/core', '@babel/node', '@babel/preset-env')
.overwrite()
.as(SaveMode.Optional)
.run();License
Copyright © 2020 Elliot 'noftaly' Maisl. Licensed under the MIT license, see the license.