2021-12-25 17:22:56 +03:00
|
|
|
import path from 'node:path';
|
2022-09-25 04:04:58 +03:00
|
|
|
import fs from 'node:fs/promises';
|
2023-04-19 16:23:13 +03:00
|
|
|
import { getDirnameFromImportMeta, getIconDataPath } from '../sdk.mjs';
|
2022-09-28 05:11:27 +03:00
|
|
|
|
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get JSON schema data.
|
2023-08-08 07:38:52 +03:00
|
|
|
* @param {String} rootDir Path to the root directory of the project.
|
2022-09-28 05:11:27 +03:00
|
|
|
*/
|
|
|
|
export const getJsonSchemaData = async (
|
|
|
|
rootDir = path.resolve(__dirname, '..'),
|
|
|
|
) => {
|
|
|
|
const jsonSchemaPath = path.resolve(rootDir, '.jsonschema.json');
|
|
|
|
const jsonSchemaString = await fs.readFile(jsonSchemaPath, 'utf8');
|
|
|
|
return JSON.parse(jsonSchemaString);
|
|
|
|
};
|
|
|
|
|
2022-09-25 04:04:58 +03:00
|
|
|
/**
|
|
|
|
* Write icons data to _data/simple-icons.json.
|
|
|
|
* @param {Object} iconsData Icons data object.
|
2023-08-08 07:38:52 +03:00
|
|
|
* @param {String} rootDir Path to the root directory of the project.
|
2022-09-25 04:04:58 +03:00
|
|
|
*/
|
2023-04-19 16:23:13 +03:00
|
|
|
export const writeIconsData = async (
|
|
|
|
iconsData,
|
|
|
|
rootDir = path.resolve(__dirname, '..'),
|
|
|
|
) => {
|
2023-08-08 07:38:52 +03:00
|
|
|
await fs.writeFile(
|
2022-09-25 04:04:58 +03:00
|
|
|
getIconDataPath(rootDir),
|
|
|
|
`${JSON.stringify(iconsData, null, 4)}\n`,
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
};
|