Common: Tests: init colors test

This commit is contained in:
Viktor Fomin 2024-08-21 17:40:40 +03:00
parent 1d93dc44f0
commit 47ab91a674
7 changed files with 243 additions and 0 deletions

1
common/Tests/colors-test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.html

View File

@ -0,0 +1,10 @@
{
"name": "colors-test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"start": "node src/index.js"
}
}

View File

@ -0,0 +1,39 @@
// (c) Copyright Ascensio System SIA 2010-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
export const excludeFiles = ["../../../packages/shared/utils/encoder.ts"];
export const excludeDirs = [
"../../../packages/client/node_modules",
"../../../packages/shared/node_modules",
"../../../packages/login/node_modules",
"../../../packages/doceditor/node_modules",
"../../../packages/management/node_modules",
"../../../packages/doceditor/.next",
"../../../packages/login/.next",
"../../../packages/login/dist",
"../../../packages/shared/themes",
];

View File

@ -0,0 +1,42 @@
// (c) Copyright Ascensio System SIA 2010-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import fs from "fs";
import { searchDirectoryForHexColors } from "./utils.js";
import { excludeDirs, excludeFiles } from "./exclude.js";
import { generateReport } from "./report.js";
const directoryPath = "../../../packages";
const reportName = `colors_report_${new Date().toJSON()}.html`;
const hexColorsFound = searchDirectoryForHexColors(
directoryPath,
excludeFiles,
excludeDirs
);
const htmlReport = generateReport(hexColorsFound);
fs.writeFileSync(reportName, htmlReport, "utf-8");

View File

@ -0,0 +1,67 @@
// (c) Copyright Ascensio System SIA 2010-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
export function generateReport(hexColorsFound) {
let htmlReport = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Colors report</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
h1 { color: #333; }
h3 { margin-top: 8px; }
ul { list-style-type: none; padding: 0; }
li { margin-bottom: 4px; }
.color-box { display: inline-block; width: 16px; height: 16px; margin-right: 8px; vertical-align: middle; }
</style>
</head>
<body>
<h1>Colors Report</h1>
<p>Found colors in the following files:</p>
`;
Object.keys(hexColorsFound).forEach((file) => {
htmlReport += `<h3>File: ${file}</h3><ul>`;
hexColorsFound[file].forEach((color) => {
htmlReport += `
<li>
<div class="color-box" style="background-color: ${color};"></div>
${color}
</li>`;
});
htmlReport += "</ul>";
});
htmlReport += `
<p>Total files with colors: ${Object.keys(hexColorsFound).length}</p>
</body>
</html>`;
return htmlReport;
}

View File

@ -0,0 +1,72 @@
// (c) Copyright Ascensio System SIA 2010-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import path from "path";
import fs from "fs";
const hexColorPattern = /#(?:[0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})\b/g;
export function findHexColorsInFile(filePath) {
const content = fs.readFileSync(filePath, "utf-8");
const matches = content.match(hexColorPattern);
return matches || [];
}
export function searchDirectoryForHexColors(
directory,
excludeFiles = [],
excludeDirs = []
) {
let hexColors = {};
function walkDirectory(currentPath) {
const items = fs.readdirSync(currentPath);
items.forEach((item) => {
const fullPath = path.join(currentPath, item);
const isDirectory = fs.statSync(fullPath).isDirectory();
if (isDirectory) {
if (!excludeDirs.includes(fullPath)) {
walkDirectory(fullPath);
}
} else {
if (
!excludeFiles.includes(fullPath) &&
/\.(js|ts|jsx|tsx)$/.test(item)
) {
const matches = findHexColorsInFile(fullPath);
if (matches.length > 0) {
hexColors[fullPath] = matches;
}
}
}
});
}
walkDirectory(directory);
return hexColors;
}

View File

@ -0,0 +1,12 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 8
cacheKey: 10
"colors-test@workspace:.":
version: 0.0.0-use.local
resolution: "colors-test@workspace:."
languageName: unknown
linkType: soft