diff --git a/.eslintignore b/.eslintignore index 2be570a9..a843dc44 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1 @@ test/fixtures -public/js diff --git a/.eslintrc b/.eslintrc index cc12cba5..98cba183 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,5 +3,11 @@ "parserOptions": { "sourceType": "module", "requireConfigFile": false + }, + "rules": { + "func-style": "off", + "no-invalid-this": "off", + "no-inner-declarations": "off", + "no-case-declarations": "off" } } diff --git a/esbuild.config.js b/esbuild.config.js index 0a16f542..3a3ecd20 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -17,8 +17,8 @@ const kNodeModulesDir = path.join(__dirname, "node_modules"); await esbuild.build({ entryPoints: [ - path.join(kPublicDir, "js", "master.js"), - path.join(kPublicDir, "css", "style.css"), + path.join(kPublicDir, "main.js"), + path.join(kPublicDir, "main.css"), path.join(kNodeModulesDir, "highlight.js", "styles", "github.css"), ...getBuildConfiguration().entryPoints ], @@ -38,17 +38,10 @@ await esbuild.build({ outdir: kOutDir }); +const imagesFiles = await fs.readdir(kImagesDir); + await Promise.all([ - ...[ - "github-mark.png", - "github-black.png", - "npm-icon.svg", - "node.png", - "snyk.png", - "sonatype.png", - "avatar-default.png", - "scorecard.png", - "ext-link.svg" - ].map((name) => fs.copyFile(path.join(kImagesDir, name), path.join(kOutDir, name))), + ...imagesFiles + .map((name) => fs.copyFile(path.join(kImagesDir, name), path.join(kOutDir, name))), fs.copyFile(path.join(kPublicDir, "favicon.ico"), path.join(kOutDir, "favicon.ico")) ]); diff --git a/public/js/scorecard.js b/public/common/scorecard.js similarity index 100% rename from public/js/scorecard.js rename to public/common/scorecard.js diff --git a/public/js/utils.js b/public/common/utils.js similarity index 59% rename from public/js/utils.js rename to public/common/utils.js index 96636be9..6e345ff4 100644 --- a/public/js/utils.js +++ b/public/common/utils.js @@ -1,6 +1,10 @@ +/* eslint-disable no-invalid-this */ // Import static import avatarURL from "../img/avatar-default.png"; +// Import Internal Dependencies +import { createExpandableSpan } from "../components/expandable/expandable"; + window.activeLegendElement = null; function getVCSRepositoryPath(url) { @@ -15,7 +19,8 @@ function getVCSRepositoryPath(url) { 1, repo.pathname.includes(".git") ? -4 : repo.pathname.length ); - } catch { + } + catch { return null; } } @@ -29,7 +34,8 @@ function getVCSRepositoryPlatform(url) { const repo = new URL(url); return repo.host; - } catch { + } + catch { return null; } } @@ -113,14 +119,6 @@ export function createLink(href, text = null) { return createDOMElement("a", { text, attributes }); } -export function createTooltip(text, description) { - const spanElement = createDOMElement("span", { text: description }); - - return createDOMElement("div", { - classList: ["tooltip"], text, childs: [spanElement] - }); -} - export function parseRepositoryUrl(repository = {}, defaultValue = null) { if (typeof repository !== "object" || !("url" in repository)) { return defaultValue; @@ -160,6 +158,7 @@ export function createAvatarImageElement(email = null) { imageElement.src = `${avatarURL}`; }; } + return imageElement; } @@ -179,48 +178,6 @@ export function createAvatar(name, desc) { return divEl; } -export function createFileBox(options = {}) { - const { title, fileName, childs = [], titleHref = "#", fileHref = null, severity = null } = options; - - const defaultHrefProperties = { target: "_blank", rel: "noopener noreferrer" }; - const fileDomElement = fileHref === null ? - createDOMElement("p", { text: fileName }) : - createDOMElement("a", { text: fileName, attributes: { href: fileHref, ...defaultHrefProperties } }); - - const boxHeader = createDOMElement("div", { - classList: ["box-header"], - childs: [ - ...(severity === null ? [] : [ - createDOMElement("span", { classList: [severity], text: severity.charAt(0).toUpperCase() }) - ]), - titleHref === null ? - createDOMElement("p", { text: title, className: "box-title" }) : - createDOMElement("a", { - text: title, - className: "box-title", - attributes: { - href: titleHref, ...defaultHrefProperties - } - }), - createDOMElement("p", { - className: "box-file", - childs: [ - createDOMElement("i", { classList: ["icon-docs"] }), - fileDomElement - ] - }) - ] - }); - - return createDOMElement("div", { - classList: ["box-file-info"], - childs: [ - boxHeader, - ...childs.filter((element) => element !== null) - ] - }); -} - export function createLiField(title, value, options = {}) { const { isLink = false } = options; @@ -240,42 +197,6 @@ export function createLiField(title, value, options = {}) { return liElement; } -export function createExpandableSpan(hideItemsLength, onclick = () => void 0) { - const span = createDOMElement("span", { - classList: ["expandable"], - attributes: { "data-value": "closed" }, - childs: [ - createDOMElement("i", { className: "icon-plus-squared-alt" }), - createDOMElement("p", { text: "show more" }) - ] - }); - span.addEventListener("click", function itemListClickAction() { - const isClosed = this.getAttribute("data-value") === "closed"; - { - const innerI = this.querySelector("i"); - innerI.classList.remove(isClosed ? "icon-plus-squared-alt" : "icon-minus-squared-alt"); - innerI.classList.add(isClosed ? "icon-minus-squared-alt" : "icon-plus-squared-alt"); - } - this.querySelector("p").textContent = isClosed ? "show less" : "show more"; - this.setAttribute("data-value", isClosed ? "opened" : "closed"); - - for (let id = 0; id < this.parentNode.childNodes.length; id++) { - const node = this.parentNode.childNodes[id]; - if (node !== this) { - if (isClosed) { - node.classList.remove("hidden"); - } - else if (id >= hideItemsLength) { - node.classList.add("hidden"); - } - } - } - onclick(this); - }); - - return span; -} - export function createItemsList(node, items = [], options = {}) { const { onclick = null, hideItems = false, hideItemsLength = 5 } = options; @@ -313,24 +234,24 @@ export function createItemsList(node, items = [], options = {}) { } export function copyToClipboard(str) { - const el = document.createElement('textarea'); // Create a