UNPKG

smash-package-installer

Version:
68 lines (53 loc) 1.63 kB
# smash-package-installer A tiny npm package installer used by smash-cli. # Install ```bash npm i --save smash-package-installer ``` or ```bash yarn add smash-package-installer ``` # Usage ## `PackageInstaller.install(packageName[, options])` ```javascript const PackageInstaller = require('smash-package-installer'); const packageName = 'react'; // or ['react', 'react-dom'] const { error, stdout } = PackageInstaller.install(packageName, { ///////////////////// // Default options // ///////////////////// // saveProd: true, // save in the dependencies. // saveDev: false, // save in the devDependencies. // saveOptional: false, // save in the optionalDependencies. // noSave: false, // installationDir: process.cwd(), noSave: true, installationDir, // Make sure that you have a package.json file here. }); if(error) { console.log(error); } else { // TODO } ``` ## `PackageInstaller.createEmptyPackageJson(installationDir)` ```javascript const PackageInstaller = require('smash-package-installer'); const { error } = PackageInstaller.createEmptyPackageJson(installationDir); if(error) { console.log(error); } else { // TODO } ``` ## `PackageInstaller.isInstalledVersionUsable(wantedVersion, installedVersion)` ```javascript const PackageInstaller = require('smash-package-installer'); const wantedVersion = '^1.3.0'; const installedVersion = '1.0.0'; const isUsable = PackageInstaller.isInstalledVersionUsable(wantedVersion, installedVersion); console.log(isUsable); // true ``` # Links - [smash-cli](https://github.com/chenhaihong/smash-cli)