Copyright panel: port to svelte, generate licenses detects 'mostly white' icons now, fix #2041
This commit is contained in:
parent
f2d2240896
commit
2aa77b7b47
9 changed files with 331 additions and 245 deletions
|
@ -123,7 +123,7 @@ export default class ScriptUtils {
|
|||
return ScriptUtils.DownloadJSON(url)
|
||||
}
|
||||
|
||||
public static async ReadSvg(path: string): Promise<any> {
|
||||
public static async ReadSvg(path: string): Promise<SVGElement> {
|
||||
if (!existsSync(path)) {
|
||||
throw "File not found: " + path
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ import SmallLicense from "../src/Models/smallLicense"
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import Script from "./Script"
|
||||
import { Utils } from "../src/Utils"
|
||||
|
||||
const prompt = require("prompt-sync")()
|
||||
|
||||
export class GenerateLicenseInfo extends Script {
|
||||
private static readonly needsLicenseRef = new Set(
|
||||
ScriptUtils.readDirRecSync("./LICENSES")
|
||||
|
@ -23,7 +25,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
authors: ["Pieter Vander Vennet"],
|
||||
path: undefined,
|
||||
license: "CC0",
|
||||
sources: [],
|
||||
sources: []
|
||||
})
|
||||
knownLicenses.set("streetcomplete", {
|
||||
authors: ["Tobias Zwick (westnordost)"],
|
||||
|
@ -31,8 +33,8 @@ export class GenerateLicenseInfo extends Script {
|
|||
license: "CC0",
|
||||
sources: [
|
||||
"https://github.com/streetcomplete/StreetComplete/tree/master/res/graphics",
|
||||
"https://f-droid.org/packages/de.westnordost.streetcomplete/",
|
||||
],
|
||||
"https://f-droid.org/packages/de.westnordost.streetcomplete/"
|
||||
]
|
||||
})
|
||||
|
||||
knownLicenses.set("temaki", {
|
||||
|
@ -41,34 +43,34 @@ export class GenerateLicenseInfo extends Script {
|
|||
license: "CC0",
|
||||
sources: [
|
||||
"https://github.com/ideditor/temaki",
|
||||
"https://ideditor.github.io/temaki/docs/",
|
||||
],
|
||||
"https://ideditor.github.io/temaki/docs/"
|
||||
]
|
||||
})
|
||||
|
||||
knownLicenses.set("maki", {
|
||||
authors: ["Maki"],
|
||||
path: undefined,
|
||||
license: "CC0",
|
||||
sources: ["https://labs.mapbox.com/maki-icons/"],
|
||||
sources: ["https://labs.mapbox.com/maki-icons/"]
|
||||
})
|
||||
|
||||
knownLicenses.set("t", {
|
||||
authors: [],
|
||||
path: undefined,
|
||||
license: "CC0; trivial",
|
||||
sources: [],
|
||||
sources: []
|
||||
})
|
||||
knownLicenses.set("na", {
|
||||
authors: [],
|
||||
path: undefined,
|
||||
license: "CC0",
|
||||
sources: [],
|
||||
sources: []
|
||||
})
|
||||
knownLicenses.set("carto", {
|
||||
authors: ["OSM-Carto"],
|
||||
path: undefined,
|
||||
license: "CC0",
|
||||
sources: [""],
|
||||
sources: [""]
|
||||
})
|
||||
knownLicenses.set("tv", {
|
||||
authors: ["Toerisme Vlaanderen"],
|
||||
|
@ -76,20 +78,20 @@ export class GenerateLicenseInfo extends Script {
|
|||
license: "CC0",
|
||||
sources: [
|
||||
"https://toerismevlaanderen.be/pinjepunt",
|
||||
"https://mapcomplete.org/toerisme_vlaanderenn",
|
||||
],
|
||||
"https://mapcomplete.org/toerisme_vlaanderenn"
|
||||
]
|
||||
})
|
||||
knownLicenses.set("tvf", {
|
||||
authors: ["Jo De Baerdemaeker "],
|
||||
path: undefined,
|
||||
license: "All rights reserved",
|
||||
sources: ["https://www.studiotype.be/fonts/flandersart"],
|
||||
sources: ["https://www.studiotype.be/fonts/flandersart"]
|
||||
})
|
||||
knownLicenses.set("twemoji", {
|
||||
authors: ["Twemoji"],
|
||||
path: undefined,
|
||||
license: "CC-BY 4.0",
|
||||
sources: ["https://github.com/twitter/twemoji"],
|
||||
sources: ["https://github.com/twitter/twemoji"]
|
||||
})
|
||||
return knownLicenses
|
||||
}
|
||||
|
@ -135,6 +137,50 @@ export class GenerateLicenseInfo extends Script {
|
|||
return licenses
|
||||
}
|
||||
|
||||
async mostlyWhite(allIcons: string[]) {
|
||||
const whitePaths = new Set<string>()
|
||||
for (const icon of allIcons) {
|
||||
if (!icon.endsWith(".svg")) {
|
||||
continue
|
||||
}
|
||||
|
||||
const svg = await ScriptUtils.ReadSvg(icon)
|
||||
|
||||
const colours = new Set<string>()
|
||||
Utils.WalkObject(svg, leaf => {
|
||||
const style = leaf["style"].split(";")
|
||||
for (const styleElement of style) {
|
||||
const [key, value] = styleElement.split(":").map(x => x.trim())
|
||||
if (value === "none") {
|
||||
continue
|
||||
}
|
||||
if (key === "fill" || key === "stroke") {
|
||||
colours.add(value)
|
||||
}
|
||||
return colours
|
||||
}
|
||||
}, leaf => typeof leaf["style"] === "string" )
|
||||
if(colours.size === 0){
|
||||
continue
|
||||
}
|
||||
const whiteColours = Array.from(colours).map(c => {
|
||||
const rgb = Utils.color(c)
|
||||
if(!rgb){
|
||||
console.log("Could not parse ", c)
|
||||
return false
|
||||
}
|
||||
const {r,g,b} = rgb
|
||||
return (r > 245 && g > 245 && b > 245)
|
||||
})
|
||||
const hasDark = whiteColours.some(isWhite => !isWhite)
|
||||
if(!hasDark){
|
||||
whitePaths.add(icon)
|
||||
}
|
||||
|
||||
}
|
||||
return whitePaths
|
||||
}
|
||||
|
||||
missingLicenseInfos(licenseInfos: SmallLicense[], allIcons: string[]) {
|
||||
const missing = []
|
||||
|
||||
|
@ -182,7 +228,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
authors: author.split(";"),
|
||||
path: path,
|
||||
license: prompt("What is the license for artwork " + path + "? > "),
|
||||
sources: prompt("Where was this artwork found? > ").split(";"),
|
||||
sources: prompt("Where was this artwork found? > ").split(";")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,7 +261,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
"ISC-LICENSE": "ISC",
|
||||
"LOGO-BY-THE-GOVERNMENT": "LOGO",
|
||||
PD: "PUBLIC-DOMAIN",
|
||||
"LOGO-(ALL-RIGHTS-RESERVED)": "LOGO",
|
||||
"LOGO-(ALL-RIGHTS-RESERVED)": "LOGO"
|
||||
/* ALL-RIGHTS-RESERVED:
|
||||
PD:
|
||||
PUBLIC-DOMAIN:
|
||||
|
@ -246,7 +292,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
path: license.path,
|
||||
license: license.license,
|
||||
authors: license.authors,
|
||||
sources: license.sources,
|
||||
sources: license.sources
|
||||
}
|
||||
|
||||
cloned.license = Utils.Dedup(
|
||||
|
@ -289,7 +335,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
}
|
||||
|
||||
queryMissingLicenses(missingLicenses: string[]) {
|
||||
process.on("SIGINT", function () {
|
||||
process.on("SIGINT", function() {
|
||||
console.log("Aborting... Bye!")
|
||||
process.exit()
|
||||
})
|
||||
|
@ -311,7 +357,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
* Creates the humongous license_info in the generated assets, containing all licenses with a path relative to the root
|
||||
* @param licensePaths
|
||||
*/
|
||||
createFullLicenseOverview(licensePaths: string[]) {
|
||||
createFullLicenseOverview(licensePaths: string[], mostlyWhite: string[]) {
|
||||
const allLicenses: SmallLicense[] = []
|
||||
for (const licensePath of licensePaths) {
|
||||
if (!existsSync(licensePath)) {
|
||||
|
@ -327,6 +373,9 @@ export class GenerateLicenseInfo extends Script {
|
|||
licensePath.length - "license_info.json".length
|
||||
)
|
||||
license.path = dir + license.path
|
||||
if(mostlyWhite.some(l => license.path === l)){
|
||||
license["mostly_white"] = true
|
||||
}
|
||||
allLicenses.push(license)
|
||||
}
|
||||
}
|
||||
|
@ -354,6 +403,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
(pth) => pth.match(/(.svg|.png|.jpg|.ttf|.otf|.woff|.jpeg)$/i) != null
|
||||
)
|
||||
const missingLicenses = this.missingLicenseInfos(licenseInfos, artwork)
|
||||
const mostlyWhite: Set<string> = await this.mostlyWhite(artwork)
|
||||
if (args.indexOf("--prompt") >= 0 || args.indexOf("--query") >= 0) {
|
||||
this.queryMissingLicenses(missingLicenses)
|
||||
return this.main([])
|
||||
|
@ -371,7 +421,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
if (licenseInfo.sources.length + licenseInfo.authors.length == 0 && !isTrivial) {
|
||||
invalidLicenses.push(
|
||||
"Invalid license: No sources nor authors given in the license for " +
|
||||
JSON.stringify(licenseInfo)
|
||||
JSON.stringify(licenseInfo)
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
@ -394,10 +444,10 @@ export class GenerateLicenseInfo extends Script {
|
|||
const spdxContent = [
|
||||
"SPDX-FileCopyrightText: " + licenseInfo.authors.join("; "),
|
||||
"SPDX-License-Identifier: " +
|
||||
licenseInfo.license
|
||||
.split(" AND ")
|
||||
.map((s) => this.addLicenseRef(s))
|
||||
.join(" AND "),
|
||||
licenseInfo.license
|
||||
.split(" AND ")
|
||||
.map((s) => this.addLicenseRef(s))
|
||||
.join(" AND ")
|
||||
]
|
||||
writeFileSync(spdxPath, spdxContent.join("\n"))
|
||||
}
|
||||
|
@ -412,7 +462,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
}
|
||||
|
||||
this.cleanLicenseInfo(licensePaths, licenseInfos)
|
||||
this.createFullLicenseOverview(licensePaths)
|
||||
this.createFullLicenseOverview(licensePaths, Array.from(mostlyWhite))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -422,7 +472,6 @@ export class GenerateLicenseInfo extends Script {
|
|||
*/
|
||||
private addLicenseRef(s: string): string {
|
||||
if (GenerateLicenseInfo.needsLicenseRef.has(s)) {
|
||||
console.log("Mapping ", s, Array.from(GenerateLicenseInfo.needsLicenseRef))
|
||||
return "LicenseRef-" + s
|
||||
}
|
||||
return s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue