Generate npm/yarn install commands base on package.json
- Node.js ≥ 6.0.0, and npm
- UNIX-like shell, e.g. sh, bash, zsh
npm install --global generate-npm-install
This will generate npm install --save-{prod,bundle,optional,dev}
or yarn add {,--optional,--dev}
commands base on package.json
in working directory
generate-npm-install # output contains: npm install --save... package1 package2 ...
NPM_TAG=latest generate-npm-install # output contains: npm install --save... package1@latest package2@latest ...
USE_YARN=true generate-npm-install # output contains: yarn add ...
This will generate npm install
commands for /path/to/directory/package.json
generate-npm-install /path/to/directory
NPM_TAG=latest generate-npm-install /path/to/directory
This will execute generated npm install
commands
generate-npm-install | sh
NPM_TAG=latest generate-npm-install | sh
generate-npm-install /path/to/directory | sh
NPM_TAG=latest generate-npm-install /path/to/directory | sh
const generateNpmInstall = require('generate-npm-install')
generateNpmInstall(options: {
process: {
env: {
TAG?: string,
NPM_TAG: string = TAG,
USE_YARN: string = 'false'
}
} = require('process'),
fs: {
readFileSync: (filename: string) => {
toString: (encoding: string = 'utf8') => string
}
} = require('fs'),
path: {
resolve: (...args: string[]) => string
} = require('path'),
directory: string = process.cwd()
}): string
options.process
: object, default toprocess
options.process.env
: object, default to{}
options.process.env.NPM_TAG
: string, default tooptions.process.env.TAG
options.process.env.TAG
: string, default toundefined
options.process.env.USE_YARN
: string, default to'false'
options.fs
: object, default tofs
options.fs.readFileSync
: functionoptions.path
: object, default topath
options.path.resolve
: functionoptions.directory
: string, path to a directory, default tooptions.process.cwd()
- Returns a string contains UNIX shell script