Skip to content

Commit

Permalink
Merge pull request #1641 from hollaex/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
abeikverdi authored Sep 4, 2022
2 parents e8456b6 + b049e1f commit 05d11d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"multicoin-address-validator": "0.5.5",
"node-cron": "2.0.3",
"nodemailer": "6.4.6",
"npm": "5.7.1",
"npm-programmatic": "0.0.12",
"npm": "8.19.1",
"npmi": "4.0.0",
"otp": "0.1.3",
"pg": "6.4.2",
"pg-hstore": "2.3.2",
Expand Down
60 changes: 39 additions & 21 deletions server/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { Plugin } = require('../db/models');
const path = require('path');
const fs = require('fs');
const latestVersion = require('latest-version');
const npm = require('npm-programmatic');
const npmi = require('npmi');
const sequelize = require('sequelize');
const _eval = require('eval');
const toolsLib = require('hollaex-tools-lib');
Expand Down Expand Up @@ -76,30 +76,48 @@ const getInstalledLibrary = async (name, version) => {

const installLibrary = async (library) => {
const [name, version = 'latest'] = library.split('@');
const options = {
name,
version,
path: '.',
forceInstall: false,
npmLoad: {
loglevel: 'silent'
}
};

try {
const data = await getInstalledLibrary(name, version);
return data;
} catch (err) {
loggerPlugin.verbose(
'plugins/index/installLibrary',
`${name} version ${version} installing`
);

await npm.install([`${name}@${version}`], {
cwd: path.resolve(__dirname, '../'),
save: true,
output: true
});

npmi(options, function (err, result) {
if (err) {
if (err.code === npmi.LOAD_ERR) {
loggerPlugin.error(
'plugins/installLibrary',
`Error installing packages for plugin ${name}`,
err.code,
err.message
);
}
else if (err.code === npmi.INSTALL_ERR) {
loggerPlugin.error(
'plugins/installLibrary',
`Error installing packages for plugin ${name}`,
err.code,
err.message
);
}
throw new Error(err.message);
}

loggerPlugin.verbose(
'plugins/index/installLibrary',
`${name} version ${version} installed`
// installed
loggerPlugin.info(
'plugins/installLibrary',
`Successful installation of packages for plugin ${name}`,
options.name+'@'+options.version+' installed successfully in '+path.resolve(options.path)
);
});

const lib = require(name);
return lib;
}
const lib = require(name);
return lib;
};

checkStatus()
Expand Down

0 comments on commit 05d11d6

Please sign in to comment.