mobile-cli-lib
Version:
common lib used by different CLI
55 lines (54 loc) • 2.56 kB
JavaScript
;
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var plugins_source_base_1 = require("./plugins-source-base");
var Future = require("fibers/future");
var NpmRegistryPluginsSource = (function (_super) {
__extends(NpmRegistryPluginsSource, _super);
function NpmRegistryPluginsSource($progressIndicator, $logger, $httpClient, $childProcess, $hostInfo, $npmService, $errors) {
_super.call(this, $progressIndicator, $logger);
this.$httpClient = $httpClient;
this.$childProcess = $childProcess;
this.$hostInfo = $hostInfo;
this.$npmService = $npmService;
this.$errors = $errors;
}
Object.defineProperty(NpmRegistryPluginsSource.prototype, "progressIndicatorMessage", {
get: function () {
return "Searching for plugin in http://registry.npmjs.org.";
},
enumerable: true,
configurable: true
});
NpmRegistryPluginsSource.prototype.getPlugins = function (page, count) {
return Future.fromResult(page === 1 ? this.plugins : null);
};
NpmRegistryPluginsSource.prototype.initializeCore = function (projectDir, keywords) {
var _this = this;
return (function () {
var plugin = _this.getPluginFromNpmRegistry(keywords[0]).wait();
_this.plugins = plugin ? [plugin] : null;
}).future()();
};
NpmRegistryPluginsSource.prototype.prepareScopedPluginName = function (plugin) {
return plugin.replace("/", "%2F");
};
NpmRegistryPluginsSource.prototype.getPluginFromNpmRegistry = function (plugin) {
var _this = this;
return (function () {
var dependencyInfo = _this.$npmService.getDependencyInformation(plugin);
var pluginName = _this.$npmService.isScopedDependency(plugin) ? _this.prepareScopedPluginName(dependencyInfo.name) : dependencyInfo.name;
var result = _this.$npmService.getPackageJsonFromNpmRegistry(pluginName, dependencyInfo.version).wait();
if (!result) {
return null;
}
result.author = (result.author && result.author.name) || result.author;
return result;
}).future()();
};
return NpmRegistryPluginsSource;
}(plugins_source_base_1.PluginsSourceBase));
exports.NpmRegistryPluginsSource = NpmRegistryPluginsSource;