embark-area-51/lib/versions/npm.js

28 lines
748 B
JavaScript
Raw Normal View History

let fs = require('../core/fs.js');
2018-04-20 21:17:49 +00:00
let PluginManager = require('live-plugin-manager').PluginManager;
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});
if (fs.existsSync(packageDirectory + packageName)) {
return callback(null, packageDirectory + packageName);
}
2018-04-20 21:17:49 +00:00
this.logger.info("downloading " + packageName + " " + version + "....");
manager.install(packageName, version).then((result) => {
2018-04-20 23:52:51 +00:00
callback(null , result.location);
}).catch(callback);
}
}
module.exports = Npm;