1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-26 01:00:27 +02:00
simple-icons/scripts/utils.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-06-06 14:40:35 +02:00
/**
* @file Internal utilities.
*
* Here resides all the functionality that does not qualifies to reside
* in the SDK because is not publicly exposed.
*/
import fs from 'node:fs/promises';
2024-03-24 19:38:18 +02:00
import path from 'node:path';
import {getDirnameFromImportMeta, getIconDataPath} from '../sdk.mjs';
const __dirname = getDirnameFromImportMeta(import.meta.url);
2024-06-06 14:40:35 +02:00
/**
* @typedef {import("../sdk.js").IconData} IconData
*/
/**
* Get JSON schema data.
2024-06-06 14:40:35 +02:00
* @param {string} rootDirectory Path to the root directory of the project.
* @returns {Promise<any>} JSON schema data.
*/
export const getJsonSchemaData = async (
2024-03-24 19:38:18 +02:00
rootDirectory = path.resolve(__dirname, '..'),
) => {
2024-03-24 19:38:18 +02:00
const jsonSchemaPath = path.resolve(rootDirectory, '.jsonschema.json');
const jsonSchemaString = await fs.readFile(jsonSchemaPath, 'utf8');
return JSON.parse(jsonSchemaString);
};
/**
* Write icons data to _data/simple-icons.json.
2024-06-06 14:40:35 +02:00
* @param {{icons: IconData[]}} iconsData Icons data object.
* @param {string} rootDirectory Path to the root directory of the project.
*/
2023-04-19 15:23:13 +02:00
export const writeIconsData = async (
iconsData,
2024-03-24 19:38:18 +02:00
rootDirectory = path.resolve(__dirname, '..'),
2023-04-19 15:23:13 +02:00
) => {
await fs.writeFile(
2024-03-24 19:38:18 +02:00
getIconDataPath(rootDirectory),
`${JSON.stringify(iconsData, null, 4)}\n`,
'utf8',
);
};