From c701a47d17585b33f395453540bb9671eaedd65a Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Sun, 24 Jan 2021 21:53:46 +0100 Subject: [PATCH] Move colorsets into json file (#77) --- source/plugins/languages/colorsets.json | 4 ++++ source/plugins/languages/index.mjs | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 source/plugins/languages/colorsets.json diff --git a/source/plugins/languages/colorsets.json b/source/plugins/languages/colorsets.json new file mode 100644 index 00000000..c503377f --- /dev/null +++ b/source/plugins/languages/colorsets.json @@ -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"] +} \ No newline at end of file diff --git a/source/plugins/languages/index.mjs b/source/plugins/languages/index.mjs index b64159d5..e7561f65 100644 --- a/source/plugins/languages/index.mjs +++ b/source/plugins/languages/index.mjs @@ -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