1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const log_1 = require("./log");
|
4 | const path_1 = require("./path");
|
5 | const deps = {
|
6 | m: {},
|
7 | get HTTP() { return this.m.HTTP = this.m.HTTP || require('http-call').default; },
|
8 | get loadJSONFile() { return this.m.loadJSONFile = this.m.loadJSONFile || require('load-json-file'); },
|
9 | get writeJSONFile() { return this.m.writeJSONFile = this.m.writeJSONFile || require('write-json-file'); },
|
10 | };
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function readJSON(filepaths) {
|
17 | async function readJSONHTTP(url) {
|
18 | const { body } = await deps.HTTP.get(url);
|
19 | return body;
|
20 | }
|
21 | if (typeof filepaths === 'string' && filepaths.match(/https?:/))
|
22 | return readJSONHTTP(filepaths);
|
23 | const filepath = path_1.join(filepaths);
|
24 | log_1.log('readJSON', filepath);
|
25 | return deps.loadJSONFile(filepath);
|
26 | }
|
27 | exports.readJSON = readJSON;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function writeJSON(filepaths, data, options = {}) {
|
33 | const filepath = path_1.join(filepaths);
|
34 | log_1.log('writeJSON', filepath);
|
35 | return deps.writeJSONFile(filepath, data, Object.assign({ indent: ' ' }, options));
|
36 | }
|
37 | exports.writeJSON = writeJSON;
|