2017-07-05 08:35:51 -04:00
|
|
|
let fs = require('../core/fs.js');
|
2017-07-02 13:33:11 -04:00
|
|
|
|
2018-04-20 17:17:49 -04:00
|
|
|
let PluginManager = require('live-plugin-manager').PluginManager;
|
|
|
|
|
2017-07-05 18:26:44 -04:00
|
|
|
class Npm {
|
|
|
|
|
|
|
|
constructor(options) {
|
|
|
|
this.logger = options.logger;
|
|
|
|
}
|
|
|
|
|
2018-04-20 19:52:51 -04:00
|
|
|
getPackageVersion(packageName, version, callback) {
|
2018-04-20 17:17:49 -04:00
|
|
|
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
|
|
|
|
|
|
|
|
let manager = new PluginManager({pluginsPath: packageDirectory});
|
|
|
|
|
2018-04-20 19:45:57 -04:00
|
|
|
if (fs.existsSync(packageDirectory + packageName)) {
|
|
|
|
return callback(null, packageDirectory + packageName);
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:17:49 -04:00
|
|
|
this.logger.info("downloading " + packageName + " " + version + "....");
|
2018-05-08 17:49:46 -04:00
|
|
|
this.logger.info(__("downloading {{packageName}} {{version}}....", {packageName: packageName, version: version}));
|
2018-04-20 17:17:49 -04:00
|
|
|
manager.install(packageName, version).then((result) => {
|
2018-04-20 19:52:51 -04:00
|
|
|
callback(null , result.location);
|
|
|
|
}).catch(callback);
|
2017-07-02 13:33:11 -04:00
|
|
|
}
|
2017-07-05 18:26:44 -04:00
|
|
|
}
|
2017-07-02 13:33:11 -04:00
|
|
|
|
2017-07-05 18:26:44 -04:00
|
|
|
module.exports = Npm;
|