UNPKG

@fcc-cdc/it-events

Version:
99 lines (98 loc) 5.36 kB
"use strict"; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.push(_); } else if (_ = accept(result)) { if (kind === "field") initializers.push(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataCrawler = exports.textFrom = exports.textOf = void 0; const path_1 = require("path"); const yaml_1 = require("yaml"); const utility_1 = require("../utility"); const textOf = (node) => { var _a; return (_a = node === null || node === void 0 ? void 0 : node.textContent) === null || _a === void 0 ? void 0 : _a.trim(); }; exports.textOf = textOf; const textFrom = (root, selector) => (0, exports.textOf)(root === null || root === void 0 ? void 0 : root.querySelector(selector)); exports.textFrom = textFrom; let DataCrawler = (() => { var _a; let _instanceExtraInitializers = []; let _saveList_decorators; return _a = class DataCrawler { makeYAML(list) { return (0, yaml_1.stringify)(list); } async saveList(URI) { var _a, e_1, _b, _c; const list = [], folder = (0, path_1.join)(process.cwd(), 'temp', new URL(URI).pathname); try { for (var _d = true, _e = __asyncValues(this.getList(URI)), _f; _f = await _e.next(), _a = _f.done, !_a;) { _c = _f.value; _d = false; try { const item = _c; console.log(item); list.push(item); } finally { _d = true; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) await _b.call(_e); } finally { if (e_1) throw e_1.error; } } const file = await (0, utility_1.saveFile)(this.makeYAML(list), folder, 'index.yml'); return { list, folder, file }; } constructor() { __runInitializers(this, _instanceExtraInitializers); } }, (() => { _saveList_decorators = [utility_1.logTime]; __esDecorate(_a, null, _saveList_decorators, { kind: "method", name: "saveList", static: false, private: false, access: { has: obj => "saveList" in obj, get: obj => obj.saveList } }, null, _instanceExtraInitializers); })(), _a.baseURI = '', _a; })(); exports.DataCrawler = DataCrawler;