Move colorsets into json file (#77)

This commit is contained in:
Simon Lecoq
2021-01-24 21:53:46 +01:00
committed by GitHub
parent 81b7414b2a
commit c701a47d17
2 changed files with 8 additions and 5 deletions

View File

@@ -0,0 +1,4 @@
{
"rainbow":["0:#ff0000", "1:#ffa500", "2:#ffff00", "3:#008000", "4:#0000ff", "5:#4b0082", "6:#ee82ee", "7:#162221"],
"complementary":["0:#ff0000", "1:#008000", "2:#ffa500", "3:#0000ff", "4:#ffff00", "5:#4b0082", "6:#162221", "7:#ee82ee"]
}

View File

@@ -1,5 +1,5 @@
//Setup
export default async function ({login, data, q}, {enabled = false} = {}) {
export default async function ({login, data, imports, q}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
@@ -12,10 +12,9 @@
//Skipped repositories
skipped = decodeURIComponent(skipped).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
//Custom colors
if (`${colors}` === "rainbow")
colors = ["0:#ff0000", "1:#ffa500", "2:#ffff00", "3:#008000", "4:#0000ff", "5:#4b0082", "6:#ee82ee", "7:#162221"]
if (`${colors}` === "complementary")
colors = ["0:#ff0000", "1:#008000", "2:#ffa500", "3:#0000ff", "4:#ffff00", "5:#4b0082", "6:#162221", "7:#ee82ee"]
const colorsets = JSON.parse(`${await imports.fs.readFile(`${imports.__module(import.meta.url)}/colorsets.json`)}`)
if (`${colors}` in colorsets)
colors = colorsets[`${colors}`]
colors = Object.fromEntries(decodeURIComponent(colors).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x).map(x => x.split(":").map(x => x.trim())))
console.debug(`metrics/compute/${login}/plugins > languages > custom colors ${JSON.stringify(colors)}`)
//Iterate through user's repositories and retrieve languages data