mirror of
https://github.com/simple-icons/simple-icons.git
synced 2024-12-16 01:10:30 +02:00
34 lines
1003 B
JavaScript
34 lines
1003 B
JavaScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import {getDirnameFromImportMeta, getIconDataPath} from '../sdk.mjs';
|
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
|
|
|
/**
|
|
* Get JSON schema data.
|
|
* @param {String} rootDirectory Path to the root directory of the project.
|
|
*/
|
|
export const getJsonSchemaData = async (
|
|
rootDirectory = path.resolve(__dirname, '..'),
|
|
) => {
|
|
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.
|
|
* @param {Object} iconsData Icons data object.
|
|
* @param {String} rootDirectory Path to the root directory of the project.
|
|
*/
|
|
export const writeIconsData = async (
|
|
iconsData,
|
|
rootDirectory = path.resolve(__dirname, '..'),
|
|
) => {
|
|
await fs.writeFile(
|
|
getIconDataPath(rootDirectory),
|
|
`${JSON.stringify(iconsData, null, 4)}\n`,
|
|
'utf8',
|
|
);
|
|
};
|