1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const yaml_1 = require("@stoplight/yaml");
|
5 | const fs_1 = require("fs");
|
6 | const fetch = require("node-fetch");
|
7 | function doRead(name, encoding) {
|
8 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
9 | if (name.startsWith('http')) {
|
10 | const result = yield fetch(name);
|
11 | return yaml_1.parseWithPointers(yield result.text());
|
12 | }
|
13 | else if (fs_1.existsSync(name)) {
|
14 | try {
|
15 | return yaml_1.parseWithPointers(fs_1.readFileSync(name, encoding));
|
16 | }
|
17 | catch (ex) {
|
18 | throw new Error(`Could not read ${name}: ${ex.message}`);
|
19 | }
|
20 | }
|
21 | throw new Error(`${name} does not exist`);
|
22 | });
|
23 | }
|
24 | function readParsable(name, encoding) {
|
25 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
26 | try {
|
27 | return doRead(name, encoding);
|
28 | }
|
29 | catch (ex) {
|
30 | throw new Error(`Could not parse ${name}: ${ex.message}`);
|
31 | }
|
32 | });
|
33 | }
|
34 | exports.readParsable = readParsable;
|
35 |
|
\ | No newline at end of file |