You've already forked simple-icons
mirror of
https://github.com/simple-icons/simple-icons.git
synced 2025-11-23 21:34:49 +02:00
convert scripts to esm (#6946)
* convert scripts to esm * fix tests * fix tests * fix lints * syncFs to fsSync * named export for fs Co-authored-by: LitoMore <LitoMore@users.noreply.github.com> * fsSync to { promises as fs } * convert update-svgs-count to esm * rename data to icons * fix build script * switch svglintrc file to mjs * use node: protocol * pluralize getIcons Co-authored-by: LitoMore <LitoMore@users.noreply.github.com>
This commit is contained in:
@@ -5,16 +5,8 @@
|
||||
* linters (e.g. jsonlint/svglint).
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const fakeDiff = require('fake-diff');
|
||||
|
||||
const UTF8 = 'utf8';
|
||||
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const dataFile = path.resolve(rootDir, '_data', 'simple-icons.json');
|
||||
const data = require(dataFile);
|
||||
import fakeDiff from 'fake-diff';
|
||||
import { getIconsDataString } from '../utils.js';
|
||||
|
||||
/**
|
||||
* Contains our tests so they can be isolated from each other.
|
||||
@@ -22,7 +14,7 @@ const data = require(dataFile);
|
||||
*/
|
||||
const TESTS = {
|
||||
/* Tests whether our icons are in alphabetical order */
|
||||
alphabetical: () => {
|
||||
alphabetical: (data) => {
|
||||
const collector = (invalidEntries, icon, index, array) => {
|
||||
if (index > 0) {
|
||||
const prev = array[index - 1];
|
||||
@@ -54,22 +46,30 @@ const TESTS = {
|
||||
},
|
||||
|
||||
/* Check the formatting of the data file */
|
||||
prettified: () => {
|
||||
const dataString = fs.readFileSync(dataFile, UTF8).replace(/\r\n/g, '\n');
|
||||
prettified: async (data, dataString) => {
|
||||
const normalizedDataString = dataString.replace(/\r\n/g, '\n');
|
||||
const dataPretty = `${JSON.stringify(data, null, ' ')}\n`;
|
||||
if (dataString !== dataPretty) {
|
||||
const dataDiff = fakeDiff(dataString, dataPretty);
|
||||
|
||||
if (normalizedDataString !== dataPretty) {
|
||||
const dataDiff = fakeDiff(normalizedDataString, dataPretty);
|
||||
return `Data file is formatted incorrectly:\n\n${dataDiff}`;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// execute all tests and log all errors
|
||||
const errors = Object.keys(TESTS)
|
||||
.map((k) => TESTS[k]())
|
||||
.filter(Boolean);
|
||||
(async () => {
|
||||
const dataString = await getIconsDataString();
|
||||
const data = JSON.parse(dataString);
|
||||
|
||||
if (errors.length > 0) {
|
||||
errors.forEach((error) => console.error(`\u001b[31m${error}\u001b[0m`));
|
||||
process.exit(1);
|
||||
}
|
||||
const errors = (
|
||||
await Promise.all(
|
||||
Object.keys(TESTS).map((test) => TESTS[test](data, dataString)),
|
||||
)
|
||||
).filter(Boolean);
|
||||
|
||||
if (errors.length > 0) {
|
||||
errors.forEach((error) => console.error(`\u001b[31m${error}\u001b[0m`));
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user