"working"

This commit is contained in:
wjtje 2023-01-15 23:28:02 +01:00 committed by Pieter Vander Vennet
parent 8fc56f7487
commit cc0c925b81
27 changed files with 4743 additions and 17591 deletions

View file

@ -147,7 +147,7 @@ export default class OsmFeatureSource {
this.rawDataHandlers.forEach((handler) =>
handler(osmJson, Tiles.tile_index(z, x, y))
)
const geojson = <FeatureCollection<any, { id: string }>>OsmToGeoJson.default(
const geojson = <FeatureCollection<any, { id: string }>>OsmToGeoJson(
osmJson,
// @ts-ignore
{

View file

@ -7,7 +7,7 @@ import { RegexTag } from "./RegexTag"
import SubstitutingTag from "./SubstitutingTag"
import { Or } from "./Or"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { isRegExp } from "util"
// import { isRegExp } from "util"
import * as key_counts from "../../assets/key_totals.json"
type Tags = Record<string, string>
@ -94,13 +94,14 @@ export class TagUtils {
if (allowRegex && tagsFilter instanceof RegexTag) {
const key = tagsFilter.key
if (isRegExp(key)) {
console.error(
"Invalid type to flatten the multiAnswer: key is a regex too",
tagsFilter
)
throw "Invalid type to FlattenMultiAnswer"
}
// TODO: Fixme
// if (isRegExp(key)) {
// console.error(
// "Invalid type to flatten the multiAnswer: key is a regex too",
// tagsFilter
// )
// throw "Invalid type to FlattenMultiAnswer"
// }
const keystr = <string>key
if (keyValues[keystr] === undefined) {
keyValues[keystr] = []

View file

@ -1,4 +1,4 @@
import * as mangrove from "mangrove-reviews"
// import * as mangrove from "mangrove-reviews"
import { UIEventSource } from "../UIEventSource"
import { Review } from "./Review"
import { Utils } from "../../Utils"
@ -15,13 +15,13 @@ export class MangroveIdentity {
if (str === "") {
return
}
mangrove.jwkToKeypair(JSON.parse(str)).then((keypair) => {
self.keypair = keypair
mangrove.publicToPem(keypair.publicKey).then((pem) => {
console.log("Identity loaded")
self.kid.setData(pem)
})
})
// mangrove.jwkToKeypair(JSON.parse(str)).then((keypair) => {
// self.keypair = keypair
// mangrove.publicToPem(keypair.publicKey).then((pem) => {
// console.log("Identity loaded")
// self.kid.setData(pem)
// })
// })
})
try {
if (!Utils.runningFromConsole && (mangroveIdentity.data ?? "") === "") {
@ -42,12 +42,12 @@ export class MangroveIdentity {
throw "Identity already defined - not creating a new one"
}
const self = this
mangrove.generateKeypair().then((keypair) => {
self.keypair = keypair
mangrove.keypairToJwk(keypair).then((jwk) => {
self._mangroveIdentity.setData(JSON.stringify(jwk))
})
})
// mangrove.generateKeypair().then((keypair) => {
// self.keypair = keypair
// mangrove.keypairToJwk(keypair).then((jwk) => {
// self._mangroveIdentity.setData(JSON.stringify(jwk))
// })
// })
}
}
@ -127,39 +127,39 @@ export default class MangroveReviews {
this._lastUpdate = new Date()
const self = this
mangrove
.getReviews({ sub: this.GetSubjectUri() })
.then((data) => {
const reviews = []
const reviewsByUser = []
for (const review of data.reviews) {
const r = review.payload
// mangrove
// .getReviews({ sub: this.GetSubjectUri() })
// .then((data) => {
// const reviews = []
// const reviewsByUser = []
// for (const review of data.reviews) {
// const r = review.payload
console.log(
"PublicKey is ",
self._mangroveIdentity.kid.data,
"reviews.kid is",
review.kid
)
const byUser = self._mangroveIdentity.kid.map(
(data) => data === review.signature
)
const rev: Review = {
made_by_user: byUser,
date: new Date(r.iat * 1000),
comment: r.opinion,
author: r.metadata.nickname,
affiliated: r.metadata.is_affiliated,
rating: r.rating, // percentage points
}
// console.log(
// "PublicKey is ",
// self._mangroveIdentity.kid.data,
// "reviews.kid is",
// review.kid
// )
// const byUser = self._mangroveIdentity.kid.map(
// (data) => data === review.signature
// )
// const rev: Review = {
// made_by_user: byUser,
// date: new Date(r.iat * 1000),
// comment: r.opinion,
// author: r.metadata.nickname,
// affiliated: r.metadata.is_affiliated,
// rating: r.rating, // percentage points
// }
;(rev.made_by_user ? reviewsByUser : reviews).push(rev)
}
self._reviews.setData(reviewsByUser.concat(reviews))
})
.catch((e) => {
console.error("Could not download review for ", e)
})
// ;(rev.made_by_user ? reviewsByUser : reviews).push(rev)
// }
// self._reviews.setData(reviewsByUser.concat(reviews))
// })
// .catch((e) => {
// console.error("Could not download review for ", e)
// })
return this._reviews
}
@ -192,13 +192,13 @@ export default class MangroveReviews {
this._reviews.ping()
}
} else {
mangrove.signAndSubmitReview(this._mangroveIdentity.keypair, payload).then(() => {
if (callback) {
callback()
}
this._reviews.data.push(r)
this._reviews.ping()
})
// mangrove.signAndSubmitReview(this._mangroveIdentity.keypair, payload).then(() => {
// if (callback) {
// callback()
// }
// this._reviews.data.push(r)
// this._reviews.ping()
// })
}
}
}

View file

@ -72,7 +72,7 @@
</div>
<script src="./all_themes_index.ts"></script>
<script type="module" src="./all_themes_index.ts"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"></script>
<script>

22049
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,9 @@
"bugs": "https://github.com/pietervdvn/MapComplete/issues",
"homepage": "https://mapcomplete.osm.be",
"main": "index.js",
"type": "module",
"scripts": {
"vitedev": "vite",
"start": "npm run generate:layeroverview && npm run strt",
"strt": "export NODE_OPTIONS=--max_old_space_size=8364 && parcel serve *.html UI/** Logic/** assets/*.json assets/svg/* assets/templates/* assets/generated/* assets/layers/*/*.svg assets/layers/*/*/*/*.svg assets/layers/*/*.jpg assets/layers/*/*.png assets/layers/*/*.css assets/tagRenderings/*.json assets/themes/*/*.svg assets/themes/*/*.ttf assets/themes/*/*/*.ttf assets/themes/*/*.otf assets/themes/*/*/*.otf assets/themes/*/*.css assets/themes/*/*.jpg assets/themes/*/*.woff assets/themes/*/*.png vendor/* vendor/*/* assets/tagRenderings/*.svg",
"strttest": "export NODE_OPTIONS=--max_old_space_size=8364 && parcel serve test.html assets/templates/*.svg assets/templates/fonts/*.ttf",
@ -92,7 +94,6 @@
"leaflet-simple-map-screenshoter": "^0.4.5",
"libphonenumber-js": "^1.10.8",
"lz-string": "^1.4.4",
"mangrove-reviews": "^0.1.3",
"opening_hours": "^3.6.0",
"osm-auth": "^1.0.2",
"osmtogeojson": "^3.0.0-beta.5",
@ -116,7 +117,7 @@
"@types/leaflet-providers": "^1.2.0",
"@types/lz-string": "^1.3.34",
"@types/mocha": "^9.1.0",
"@types/node": "^7.10.14",
"@types/node": "^18.11.18",
"@types/papaparse": "^5.3.1",
"@types/prompt-sync": "^4.1.0",
"@types/wikidata-sdk": "^6.1.0",
@ -126,7 +127,6 @@
"dependency-cruiser": "^10.4.0",
"fs": "0.0.1-security",
"mocha": "^9.2.2",
"parcel": "^1.2.4",
"prettier": "2.7.1",
"read-file": "^0.2.0",
"sharp": "^0.30.5",
@ -134,6 +134,7 @@
"ts2json-schema": "^1.4.0",
"tslint": "^6.1.3",
"tslint-no-circular-imports": "^0.7.0",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"vite": "^4.0.4"
}
}

View file

@ -1,5 +1,5 @@
import * as fs from "fs"
import { existsSync, lstatSync, readdirSync, readFileSync } from "fs"
// import * as fs from "fs"
// import { existsSync, lstatSync, readdirSync, readFileSync } from "fs"
import { Utils } from "../Utils"
import * as https from "https"
import { LayoutConfigJson } from "../Models/ThemeConfig/Json/LayoutConfigJson"
@ -19,21 +19,21 @@ export default class ScriptUtils {
* @param maxDepth
*/
public static readDirRecSync(path, maxDepth = 999): string[] {
const result = []
const result: string[] = []
if (maxDepth <= 0) {
return []
}
for (const entry of readdirSync(path)) {
const fullEntry = path + "/" + entry
const stats = lstatSync(fullEntry)
if (stats.isDirectory()) {
// Subdirectory
// @ts-ignore
result.push(...ScriptUtils.readDirRecSync(fullEntry, maxDepth - 1))
} else {
result.push(fullEntry)
}
}
// for (const entry of readdirSync(path)) {
// const fullEntry = path + "/" + entry
// const stats = lstatSync(fullEntry)
// if (stats.isDirectory()) {
// // Subdirectory
// // @ts-ignore
// result.push(...ScriptUtils.readDirRecSync(fullEntry, maxDepth - 1))
// } else {
// result.push(fullEntry)
// }
// }
return result
}
@ -78,7 +78,8 @@ export default class ScriptUtils {
.filter((path) => path.indexOf("license_info.json") < 0)
.map((path) => {
try {
const contents = readFileSync(path, "UTF8")
// const contents = readFileSync(path, { encoding: "utf8" })
const contents = ""
if (contents === "") {
throw "The file " + path + " is empty, did you properly save?"
}
@ -101,7 +102,8 @@ export default class ScriptUtils {
public static getThemeFiles(): { parsed: LayoutConfigJson; path: string }[] {
return this.getThemePaths().map((path) => {
try {
const contents = readFileSync(path, "UTF8")
// const contents = readFileSync(path, { encoding: "utf8" })
const contents = ""
if (contents === "") {
throw "The file " + path + " is empty, did you properly save?"
}
@ -122,20 +124,25 @@ export default class ScriptUtils {
}
public static async ReadSvg(path: string): Promise<any> {
if (!existsSync(path)) {
throw "File not found: " + path
}
const root = await xml2js.parseStringPromise(readFileSync(path, "UTF8"))
return root.svg
// if (!existsSync(path)) {
// throw "File not found: " + path
// }
// const root = await xml2js.parseStringPromise(readFileSync(path, { encoding: "utf8" }))
// return root.svg
return ""
}
public static ReadSvgSync(path: string, callback: (svg: any) => void): any {
xml2js.parseString(readFileSync(path, "UTF8"), { async: false }, (err, root) => {
if (err) {
throw err
}
callback(root["svg"])
})
// xml2js.parseString(
// readFileSync(path, { encoding: "utf8" }),
// { async: false },
// (err, root) => {
// if (err) {
// throw err
// }
// callback(root["svg"])
// }
// )
}
private static async DownloadJSON(url: string, headers?: any): Promise<any> {

View file

@ -54,9 +54,9 @@ function main(args: string[]): void {
)
return
}
const reference = JSON.parse(readFileSync("./langs/en.json", "UTF8"))
const reference = JSON.parse(readFileSync("./langs/en.json", { encoding: "utf8" }))
const path = `./langs/${l}.json`
const file = JSON.parse(readFileSync(path, "UTF8"))
const file = JSON.parse(readFileSync(path, { encoding: "utf8" }))
fixSection(file[sectionName], reference[sectionName], l)
writeFileSync(path, JSON.stringify(file, null, " ") + "\n")
}

View file

@ -51,7 +51,7 @@ function rewrite(obj, key) {
const stuff = fs.readFileSync(
"/home/pietervdvn/Documents/Freelance/ToerismeVlaanderen 2021-09/TeImporteren/allchannels-bike_rental.json",
"UTF8"
{ encoding: "utf8" }
)
const data: any[] = JSON.parse(stuff)

View file

@ -138,7 +138,7 @@ async function main(wipeCache = false) {
console.log("Reusing the cached file")
}
const data = JSON.parse(readFileSync(cacheFile, "UTF8"))
const data = JSON.parse(readFileSync(cacheFile, { encoding: "utf8" }))
const perId = WikidataUtils.extractLanguageData(data, WikidataUtils.languageRemapping)
const nativeList = getNativeList(perId)
writeFileSync("./assets/language_native.json", JSON.stringify(nativeList, null, " "))

View file

@ -15,7 +15,7 @@ function main(args) {
const spec = args[1]
const output = args[2]
const data = JSON.parse(fs.readFileSync(path, "UTF8"))
const data = JSON.parse(fs.readFileSync(path, { encoding: "utf8" }))
let filter: TagsFilter
try {
filter = TagUtils.Tag(JSON.parse(spec))

View file

@ -63,7 +63,7 @@ function main() {
const path = args[0]
const iconClass = args[1] ?? "small"
const targetFile = args[2] ?? path + ".autoconverted.json"
const parsed = JSON.parse(readFileSync(path, "UTF8"))
const parsed = JSON.parse(readFileSync(path, { encoding: "utf8" }))
const converted = new ConvertImagesToIcon(iconClass).convertStrict(
parsed,
"While running the fixImagesInTagRenderings-script"

View file

@ -99,7 +99,7 @@ function WalkScheme<T>(
function extractMeta(typename: string, path: string) {
const themeSchema = JSON.parse(
readFileSync("./Docs/Schemas/" + typename + ".schema.json", "UTF-8")
readFileSync("./Docs/Schemas/" + typename + ".schema.json", { encoding: "utf8" })
)
const withTypes = WalkScheme((schemePart) => {
if (schemePart.description === undefined) {
@ -126,7 +126,7 @@ function main() {
for (const path of allSchemas) {
const dir = path.substring(0, path.lastIndexOf("/"))
const name = path.substring(path.lastIndexOf("/"), path.length - "JSC.ts".length)
let content = readFileSync(path, "UTF-8")
let content = readFileSync(path, { encoding: "utf8" })
content = content.substring("export default ".length)
let parsed = JSON.parse(content)
parsed["additionalProperties"] = false
@ -137,7 +137,7 @@ function main() {
def["additionalProperties"] = false
}
}
writeFileSync(dir + "/" + name + ".schema.json", JSON.stringify(parsed, null, " "), "UTF8")
writeFileSync(dir + "/" + name + ".schema.json", JSON.stringify(parsed, null, " "), { encoding: "utf8" })
}
extractMeta("LayoutConfigJson", "layoutconfigmeta")

View file

@ -212,7 +212,7 @@ function loadAllTiles(
}
// We read the raw OSM-file and convert it to a geojson
const rawOsm = JSON.parse(readFileSync(filename, "UTF8"))
const rawOsm = JSON.parse(readFileSync(filename, { encoding: "utf8" }))
// Create and save the geojson file - which is the main chunk of the data
const geojson = OsmToGeoJson.default(rawOsm)

View file

@ -138,7 +138,7 @@ export default class GenerateImageAnalysis extends Script {
if (!file.endsWith(".json")) {
continue
}
const attr = <LicenseInfo>JSON.parse(fs.readFileSync(file, "UTF8"))
const attr = <LicenseInfo>JSON.parse(fs.readFileSync(file, { encoding: "utf8" }))
const license = attr.licenseShortName
if (license === undefined || attr.artist === undefined) {

View file

@ -125,7 +125,7 @@ class LayerOverviewUtils {
writeFileSync(
"./assets/generated/theme_overview.json",
JSON.stringify(sorted, null, " "),
"UTF8"
{ encoding: "utf8" }
)
}
@ -136,7 +136,7 @@ class LayerOverviewUtils {
writeFileSync(
`${LayerOverviewUtils.themePath}${theme.id}.json`,
JSON.stringify(theme, null, " "),
"UTF8"
{ encoding: "utf8" }
)
}
@ -147,7 +147,7 @@ class LayerOverviewUtils {
writeFileSync(
`${LayerOverviewUtils.layerPath}${layer.id}.json`,
JSON.stringify(layer, null, " "),
"UTF8"
{ encoding: "utf8" }
)
}
@ -219,7 +219,7 @@ class LayerOverviewUtils {
continue
}
const contents = readFileSync(path, "UTF8")
const contents = readFileSync(path, { encoding: "utf8" })
if (contents.indexOf("data:image/png;") >= 0) {
console.warn("The SVG at " + path + " is a fake SVG: it contains PNG data!")
errCount++
@ -283,7 +283,7 @@ class LayerOverviewUtils {
const proto: LayoutConfigJson = JSON.parse(
readFileSync(
"./assets/themes/mapcomplete-changes/mapcomplete-changes.proto.json",
"UTF8"
{ encoding: "utf8" }
)
)
const protolayer = <LayerConfigJson>(

View file

@ -22,7 +22,7 @@ function generateLicenseInfos(paths: string[]): SmallLicense[] {
const licenses = []
for (const path of paths) {
try {
const parsed = JSON.parse(readFileSync(path, "UTF-8"))
const parsed = JSON.parse(readFileSync(path, { encoding: "utf8" }))
if (Array.isArray(parsed)) {
const l: SmallLicense[] = parsed
for (const smallLicens of l) {
@ -242,7 +242,7 @@ function createFullLicenseOverview(licensePaths: string[]) {
if (!existsSync(licensePath)) {
continue
}
const licenses = <SmallLicense[]>JSON.parse(readFileSync(licensePath, "UTF-8"))
const licenses = <SmallLicense[]>JSON.parse(readFileSync(licensePath, { encoding: "utf8" }))
for (const license of licenses) {
validateLicenseInfo(license)
const dir = licensePath.substring(0, licensePath.length - "license_info.json".length)

View file

@ -176,7 +176,7 @@ function generateTagInfoEntry(layout: LayoutConfig): any {
function generateProjectsOverview(files: string[]) {
try {
const tagInfoList = "../taginfo-projects/project_list.txt"
let projectList = readFileSync(tagInfoList, "UTF8")
let projectList = readFileSync(tagInfoList, { encoding: "utf8" })
.split("\n")
.filter((entry) => entry.indexOf("mapcomplete_") < 0)
.concat(

View file

@ -12,7 +12,7 @@ class TranslationPart {
const files = ScriptUtils.readDirRecSync(path, 1).filter((file) => file.endsWith(".json"))
const rootTranslation = new TranslationPart()
for (const file of files) {
const content = JSON.parse(readFileSync(file, "UTF8"))
const content = JSON.parse(readFileSync(file, { encoding: "utf8" }))
rootTranslation.addTranslation(file.substr(0, file.length - ".json".length), content)
}
return rootTranslation

View file

@ -9,7 +9,7 @@ import ScriptUtils from "./ScriptUtils"
function makeConvex(file) {
ScriptUtils.erasableLog("Handling", file)
const geoJson = JSON.parse(fs.readFileSync(file, "UTF8"))
const geoJson = JSON.parse(fs.readFileSync(file, { encoding: "utf8" }))
const convex = GeoOperations.convexHull(geoJson, { concavity: 2 })
if (convex.properties === undefined) {
convex.properties = {}

View file

@ -11,7 +11,7 @@ function main(args) {
const path = args[0]
const key = args[1]
const data = JSON.parse(fs.readFileSync(path, "UTF8"))
const data = JSON.parse(fs.readFileSync(path, { encoding: "utf8" }))
const perProperty = new Map<string, any[]>()
console.log("Partitioning", data.features.length, "features")

View file

@ -13,14 +13,14 @@ async function main(args: string[]) {
const alreadyLoaded = new Set<number>()
if (existsSync(output)) {
const lines = readFileSync(output, "UTF8").split("\n")
const lines = readFileSync(output, { encoding: "utf8" }).split("\n")
lines.shift()
lines.forEach((line) => {
const postalCode = Number(line.split(",")[0])
alreadyLoaded.add(postalCode)
})
} else {
writeFileSync(output, "postal_code,lon,lat\n", "UTF-8")
writeFileSync(output, "postal_code,lon,lat\n", { encoding: "utf8" })
}
for (const boundary of postcodes.features) {
@ -104,7 +104,7 @@ async function main(args: string[]) {
" are ",
JSON.stringify(depPoints)
)
appendFileSync(output, [postcode, ...depPoints[0]].join(", ") + "\n", "UTF-8")
appendFileSync(output, [postcode, ...depPoints[0]].join(", ") + "\n", { encoding: "utf8" })
}
}

View file

@ -3,7 +3,7 @@ import { writeFileSync } from "fs"
import ScriptUtils from "../ScriptUtils"
function handleFile(file: string, postalCode: number) {
const geojson = JSON.parse(fs.readFileSync(file, "UTF8"))
const geojson = JSON.parse(fs.readFileSync(file, { encoding: "utf8" }))
geojson.properties = {
type: "boundary",
boundary: "postal_code",
@ -14,7 +14,7 @@ function handleFile(file: string, postalCode: number) {
function getKnownPostalCodes(): number[] {
return fs
.readFileSync("./scripts/postal_code_tools/knownPostalCodes.csv", "UTF8")
.readFileSync("./scripts/postal_code_tools/knownPostalCodes.csv", { encoding: "utf8" })
.split("\n")
.map((line) => Number(line.split(",")[1]))
}

View file

@ -7609,7 +7609,7 @@ describe("GenerateCache", () => {
])
await ScriptUtils.sleep(250)
const birdhides = JSON.parse(
readFileSync(dir + "np-cache/natuurpunt_birdhide_12_2085_1368.geojson", "UTF8")
readFileSync(dir + "np-cache/natuurpunt_birdhide_12_2085_1368.geojson", { encoding: "utf8" })
)
expect(birdhides.features.length).deep.equal(5)
expect(

View file

@ -79,7 +79,7 @@
<div id="leafletDiv"></div>
<script src="./index.ts"></script>
<script type="module" src="./index.ts"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"></script>
<script>

View file

@ -1,18 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": [
"DOM",
"es5",
"scripthost",
"es2015.collection"
]
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
},
"exclude": [
"node_modules"
]
}
"exclude": ["node_modules"]
}

5
vite.config.js Normal file
View file

@ -0,0 +1,5 @@
/** @type {import('vite').UserConfig} */
export default {
// config options
optimizeDeps: ["util"],
}