2017-08-15 15:03:21 +00:00
|
|
|
"use strict";
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const plugins = require("./smartnpm.plugins");
|
|
|
|
// classes
|
|
|
|
const smartnpm_classes_npmpackage_1 = require("./smartnpm.classes.npmpackage");
|
|
|
|
class NpmRegistry {
|
|
|
|
constructor() {
|
|
|
|
this.searchDomain = 'https://api.npms.io/v2/search?q=';
|
|
|
|
}
|
|
|
|
search(searchObjectArg) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let searchString = '';
|
|
|
|
let addToSearchString = (addStringArg) => {
|
|
|
|
searchString = `${searchString}+${addStringArg}`;
|
|
|
|
};
|
|
|
|
// name
|
|
|
|
if (searchObjectArg.name) {
|
|
|
|
searchString = `${searchObjectArg.name}`;
|
|
|
|
}
|
|
|
|
// metadata
|
|
|
|
if (searchObjectArg.author) {
|
|
|
|
addToSearchString(`author:${searchObjectArg.author}`);
|
|
|
|
}
|
|
|
|
if (searchObjectArg.maintainer) {
|
|
|
|
addToSearchString(`maintainer:${searchObjectArg.maintainer}`);
|
|
|
|
}
|
|
|
|
if (searchObjectArg.scope) {
|
|
|
|
addToSearchString(`scope:${searchObjectArg.scope}`);
|
|
|
|
}
|
|
|
|
// status
|
|
|
|
if (searchObjectArg.deprecated) {
|
|
|
|
if (searchObjectArg.deprecated === true) {
|
|
|
|
addToSearchString(`is:deprecated`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addToSearchString(`not:deprecated`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (searchObjectArg.unstable) {
|
|
|
|
if (searchObjectArg.unstable === true) {
|
|
|
|
addToSearchString(`is:unstable`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addToSearchString(`not:unstable`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (searchObjectArg.insecure) {
|
|
|
|
if (searchObjectArg.insecure === true) {
|
|
|
|
addToSearchString(`is:insecure`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addToSearchString(`not:insecure`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// search behaviour
|
|
|
|
if (searchObjectArg.boostExact) {
|
|
|
|
addToSearchString(`boost-exact:${searchObjectArg.boostExact}`);
|
|
|
|
}
|
|
|
|
if (searchObjectArg.scoreEffect) {
|
|
|
|
addToSearchString(`score-effect:${searchObjectArg.scoreEffect}`);
|
|
|
|
}
|
|
|
|
// analytics
|
|
|
|
if (searchObjectArg.qualityWeight) {
|
|
|
|
addToSearchString(`author:${searchObjectArg.qualityWeight}`);
|
|
|
|
}
|
|
|
|
if (searchObjectArg.popularityWeight) {
|
|
|
|
addToSearchString(`author:${searchObjectArg.popularityWeight}`);
|
|
|
|
}
|
|
|
|
if (searchObjectArg.maintenanceWeight) {
|
|
|
|
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
|
|
|
}
|
2018-09-01 14:13:37 +00:00
|
|
|
plugins.smartlog.defaultLogger.info(`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`);
|
2018-02-14 22:51:08 +00:00
|
|
|
let body;
|
|
|
|
try {
|
2018-09-01 14:13:37 +00:00
|
|
|
let response = (yield plugins.smartrequest.getJson(this.searchDomain + searchString, {}));
|
2018-02-14 22:51:08 +00:00
|
|
|
body = response.body;
|
|
|
|
}
|
|
|
|
catch (_a) {
|
|
|
|
// we do nothing
|
|
|
|
}
|
|
|
|
// lets create the packageArray
|
2017-08-15 15:03:21 +00:00
|
|
|
let packageArray = [];
|
2018-02-14 22:51:08 +00:00
|
|
|
// if request failed just return it empty
|
|
|
|
if (!body || typeof body === 'string') {
|
2017-09-13 15:33:07 +00:00
|
|
|
return packageArray;
|
|
|
|
}
|
2017-08-15 15:03:21 +00:00
|
|
|
for (let packageArg of body.results) {
|
|
|
|
let localPackage = new smartnpm_classes_npmpackage_1.NpmPackage(packageArg.package);
|
|
|
|
packageArray.push(localPackage);
|
|
|
|
}
|
|
|
|
return packageArray;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.NpmRegistry = NpmRegistry;
|
2018-09-01 14:13:37 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1yZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmNsYXNzZXMubnBtcmVnaXN0cnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDhDQUE2QztBQUs3QyxVQUFVO0FBQ1YsK0VBQTBEO0FBRTFELE1BQWEsV0FBVztJQUF4QjtRQUNVLGlCQUFZLEdBQUcsa0NBQWtDLENBQUE7SUF5RTNELENBQUM7SUF4RU8sTUFBTSxDQUFFLGVBQThCOztZQUMxQyxJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7WUFDckIsSUFBSSxpQkFBaUIsR0FBRyxDQUFDLFlBQW9CLEVBQUUsRUFBRTtnQkFDL0MsWUFBWSxHQUFHLEdBQUcsWUFBWSxJQUFJLFlBQVksRUFBRSxDQUFBO1lBQ2xELENBQUMsQ0FBQTtZQUVELE9BQU87WUFDUCxJQUFJLGVBQWUsQ0FBQyxJQUFJLEVBQUU7Z0JBQUUsWUFBWSxHQUFHLEdBQUcsZUFBZSxDQUFDLElBQUksRUFBRSxDQ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