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