| 154 | } |
| 155 | |
| 156 | async function readJson(file: string, token?: string) { |
| 157 | if (isURL(file)) { |
| 158 | const headers = token |
| 159 | ? { |
| 160 | Authorization: `token ${token}` |
| 161 | } |
| 162 | : {} |
| 163 | return ( |
| 164 | await got({ |
| 165 | url: file, |
| 166 | method: 'GET', |
| 167 | headers, |
| 168 | responseType: 'json' |
| 169 | }) |
| 170 | ).body |
| 171 | } else { |
| 172 | const data = readFileSync(file, { encoding: 'utf8' }) |
| 173 | if (typeof data == 'string') |
| 174 | try { |
| 175 | return JSON.parse(data) |
| 176 | } catch (e) { |
| 177 | error(e instanceof Error ? e.stack || e.message : e + '') |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | async function request(url: string) { |
| 183 | const headers = token |