mirror of
https://github.com/simple-icons/simple-icons.git
synced 2024-11-16 00:59:07 +02:00
Fix SPDX license usages in add-icon-data
script
This commit is contained in:
parent
361e22120b
commit
afd6568725
@ -21,7 +21,7 @@ import {
|
||||
titleToSlug,
|
||||
urlRegex,
|
||||
} from '../sdk.mjs';
|
||||
import {getJsonSchemaData, writeIconsData} from './utils.js';
|
||||
import {getJsonSchemaData, getSpdxLicenseIds, writeIconsData} from './utils.js';
|
||||
|
||||
/** @type {{icons: import('../sdk.js').IconData[]}} */
|
||||
const iconsData = JSON.parse(await getIconsDataString());
|
||||
@ -34,11 +34,8 @@ const aliasTypes = ['aka', 'old'].map((key) => ({
|
||||
value: key,
|
||||
}));
|
||||
|
||||
/** @type {{name: string, value: string}[]} */
|
||||
const licenseTypes =
|
||||
jsonSchema.definitions.brand.properties.license.oneOf[0].properties.type.enum.map(
|
||||
(/** @type {string} */ license) => ({name: license, value: license}),
|
||||
);
|
||||
const spdxLicenseIds = await getSpdxLicenseIds();
|
||||
const licenseTypes = spdxLicenseIds.map((id) => ({name: id, value: id}));
|
||||
|
||||
/**
|
||||
* Whether an input is a valid URL.
|
||||
|
@ -10,17 +10,16 @@
|
||||
* @typedef {IconData[]} IconsData
|
||||
*/
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import fakeDiff from 'fake-diff';
|
||||
import {
|
||||
collator,
|
||||
getDirnameFromImportMeta,
|
||||
getIconsDataString,
|
||||
normalizeNewlines,
|
||||
titleToSlug,
|
||||
} from '../../sdk.mjs';
|
||||
import {getSpdxLicenseIds} from '../utils.js';
|
||||
|
||||
/**
|
||||
* Contains our tests so they can be isolated from each other.
|
||||
@ -208,19 +207,7 @@ const TESTS = {
|
||||
|
||||
/* Check if all licenses are valid SPDX identifiers */
|
||||
async checkLicense(data) {
|
||||
const spdxLicenseIds = new Set(
|
||||
JSON.parse(
|
||||
await fs.readFile(
|
||||
path.join(
|
||||
getDirnameFromImportMeta(import.meta.url),
|
||||
'..',
|
||||
'..',
|
||||
'node_modules/spdx-license-ids/index.json',
|
||||
),
|
||||
'utf8',
|
||||
),
|
||||
),
|
||||
);
|
||||
const spdxLicenseIds = new Set(await getSpdxLicenseIds());
|
||||
const badLicenses = [];
|
||||
for (const {title, slug, license} of data.icons) {
|
||||
if (
|
||||
|
@ -45,3 +45,21 @@ export const writeIconsData = async (
|
||||
'utf8',
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get SPDX license IDs from `spdx-license-ids` package.
|
||||
* @param {string} rootDirectory Path to the root directory of the project.
|
||||
* @returns {Promise<string[]>} Set of SPDX license IDs.
|
||||
*/
|
||||
export const getSpdxLicenseIds = async (
|
||||
rootDirectory = path.resolve(__dirname, '..'),
|
||||
) => {
|
||||
const getSpdxLicenseJson = path.resolve(
|
||||
rootDirectory,
|
||||
'node_modules',
|
||||
'spdx-license-ids',
|
||||
'index.json',
|
||||
);
|
||||
const getSpdxLicenseString = await fs.readFile(getSpdxLicenseJson, 'utf8');
|
||||
return JSON.parse(getSpdxLicenseString);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user