Add support for HTTPs URLs in --init
This commit is contained in:
parent
97aca6c7cf
commit
ce1f0f7f1f
@ -2,6 +2,7 @@
|
||||
|
||||
## HEAD
|
||||
|
||||
- @cosmjs/cli: Now supports HTTPs URLs for `--init` code sources.
|
||||
- @cosmjs/cosmwasm: Rename `CosmWasmClient.getNonce` method to `.getSequence`.
|
||||
- @cosmjs/cosmwasm: Remove `RestClient` class in favour of new modular
|
||||
`LcdClient` class from @cosmjs/sdk38.
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import axios from "axios";
|
||||
import * as fs from "fs";
|
||||
import { join } from "path";
|
||||
import yargs from "yargs";
|
||||
@ -6,12 +7,13 @@ import { TsRepl } from "./tsrepl";
|
||||
|
||||
import colors = require("colors/safe");
|
||||
|
||||
export function main(originalArgs: readonly string[]): void {
|
||||
export async function main(originalArgs: readonly string[]): Promise<void> {
|
||||
const args = yargs
|
||||
.options({
|
||||
// User options (we get --help and --version for free)
|
||||
init: {
|
||||
describe: "Read initial TypeScript code from files",
|
||||
describe:
|
||||
"Read initial TypeScript code from the given sources. This can be URLs (supported schemes: https) or local file paths.",
|
||||
type: "array",
|
||||
},
|
||||
code: {
|
||||
@ -161,9 +163,14 @@ export function main(originalArgs: readonly string[]): void {
|
||||
}
|
||||
|
||||
if (args.init) {
|
||||
for (const path of args.init.map((arg) => arg.toString())) {
|
||||
if (args.debug) console.info(`Adding file: '${path}' ...`);
|
||||
init += fs.readFileSync(path, "utf8") + "\n";
|
||||
for (const source of args.init.map((arg) => arg.toString())) {
|
||||
if (args.debug) console.info(`Adding code from: '${source}' ...`);
|
||||
if (source.startsWith("https://")) {
|
||||
const response = await axios.get(source);
|
||||
init += response.data + "\n";
|
||||
} else {
|
||||
init += fs.readFileSync(source, "utf8") + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user