forked from MapComplete/MapComplete
Porting fixes from stale branch
This commit is contained in:
parent
a9b6223e4d
commit
03d801733b
4 changed files with 24 additions and 19 deletions
|
@ -1,5 +1,6 @@
|
|||
import {lstatSync, readdirSync, readFileSync} from "fs";
|
||||
import {Utils} from "../Utils";
|
||||
|
||||
Utils.runningFromConsole = true
|
||||
import * as https from "https";
|
||||
import * as fs from "fs";
|
||||
|
@ -56,12 +57,12 @@ export default class ScriptUtils {
|
|||
|
||||
const headers = options?.headers ?? {}
|
||||
headers.accept = "application/json"
|
||||
|
||||
|
||||
const urlObj = new URL(url)
|
||||
https.get({
|
||||
host: urlObj.host,
|
||||
path: urlObj.pathname + urlObj.search,
|
||||
|
||||
|
||||
port: urlObj.port,
|
||||
headers: headers
|
||||
}, (res) => {
|
||||
|
@ -88,9 +89,9 @@ export default class ScriptUtils {
|
|||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static erasableLog(...text) {
|
||||
process.stdout.write("\r "+text.join(" ")+" \r")
|
||||
process.stdout.write("\r " + text.join(" ") + " \r")
|
||||
}
|
||||
|
||||
public static sleep(ms) {
|
||||
|
@ -107,14 +108,15 @@ export default class ScriptUtils {
|
|||
public static getLayerFiles(): { parsed: LayerConfigJson, path: string }[] {
|
||||
return ScriptUtils.readDirRecSync("./assets/layers")
|
||||
.filter(path => path.indexOf(".json") > 0)
|
||||
.filter(path => path.indexOf(".proto.json") < 0)
|
||||
.filter(path => path.indexOf("license_info.json") < 0)
|
||||
.map(path => {
|
||||
try {
|
||||
const contents = readFileSync(path, "UTF8")
|
||||
if(contents === ""){
|
||||
throw "The file "+path+" is empty, did you properly save?"
|
||||
if (contents === "") {
|
||||
throw "The file " + path + " is empty, did you properly save?"
|
||||
}
|
||||
|
||||
|
||||
const parsed = JSON.parse(contents);
|
||||
return {parsed: parsed, path: path}
|
||||
} catch (e) {
|
||||
|
@ -130,8 +132,8 @@ export default class ScriptUtils {
|
|||
.map(path => {
|
||||
try {
|
||||
const contents = readFileSync(path, "UTF8");
|
||||
if(contents === ""){
|
||||
throw "The file "+path+" is empty, did you properly save?"
|
||||
if (contents === "") {
|
||||
throw "The file " + path + " is empty, did you properly save?"
|
||||
}
|
||||
const parsed = JSON.parse(contents);
|
||||
return {parsed: parsed, path: path}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue