README
smash-package-installer
A tiny npm package installer used by smash-cli.
Install
npm i --save smash-package-installer
or
yarn add smash-package-installer
Usage
PackageInstaller.install(packageName[, options])
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)
const PackageInstaller = require('smash-package-installer');
const { error } = PackageInstaller.createEmptyPackageJson(installationDir);
if(error) {
console.log(error);
} else {
// TODO
}
PackageInstaller.isInstalledVersionUsable(wantedVersion, installedVersion)
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