Skip to content

Commit

Permalink
refactor(scraper): use typed rest client
Browse files Browse the repository at this point in the history
Typed rest client is already available as a result of dependency of Github toolchains

So instead of including additional axios, we'll use already existing lib
  • Loading branch information
rumblefrog committed Nov 16, 2019
1 parent ab5eeee commit 27193c7
Show file tree
Hide file tree
Showing 75 changed files with 28 additions and 7,547 deletions.
18 changes: 12 additions & 6 deletions lib/scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const versioning_1 = require("./structures/versioning");
const axios_1 = __importDefault(require("axios"));
const HttpClient_1 = require("typed-rest-client/HttpClient");
const await_to_js_1 = __importDefault(require("await-to-js"));
const client = new HttpClient_1.HttpClient('setup-sp');
function getVersions() {
return __awaiter(this, void 0, void 0, function* () {
const [err, res] = yield await_to_js_1.default(axios_1.default.get(constants_1.ENDPOINT));
const [err, res] = yield await_to_js_1.default(client.get(constants_1.ENDPOINT));
if (err || !res || res.message.statusCode !== 200) {
throw new Error(`Failed to pull major minor versions from ${constants_1.ENDPOINT}`);
}
let versions = {};
if (err) {
return versions;
}
const body = yield res.readBody();
let match, promises = [];
while ((match = constants_1.MM_REGEX.exec(res.data)) !== null) {
while ((match = constants_1.MM_REGEX.exec(body)) !== null) {
match[1] = match[1].replace('/', '');
if (match[1].length <= 0) {
continue;
Expand All @@ -39,12 +44,13 @@ function getVersions() {
exports.getVersions = getVersions;
function getBuilds(endpoint, versions, major, minor) {
return __awaiter(this, void 0, void 0, function* () {
const [err, res] = yield await_to_js_1.default(axios_1.default.get(endpoint));
if (err) {
const [err, res] = yield await_to_js_1.default(client.get(endpoint));
if (err || !res || res.message.statusCode !== 200) {
throw new Error(`Failed to pull builds from ${endpoint}`);
}
const body = yield res.readBody();
let match;
while ((match = constants_1.BUILD_REGEX.exec(res.data)) !== null) {
while ((match = constants_1.BUILD_REGEX.exec(body)) !== null) {
let platform = versioning_1.parsePlatform(match[2]);
if (process.platform == 'win32' && platform != versioning_1.Platform.Windows) {
continue;
Expand Down
6 changes: 0 additions & 6 deletions node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

348 changes: 0 additions & 348 deletions node_modules/axios/CHANGELOG.md

This file was deleted.

19 changes: 0 additions & 19 deletions node_modules/axios/LICENSE

This file was deleted.

Loading

0 comments on commit 27193c7

Please sign in to comment.