pinecone-cli
Version:
Lovely VSCode theme builder
69 lines (63 loc) • 2.02 kB
JavaScript
import path from 'node:path';
import slugify from '@sindresorhus/slugify';
import { log, readToJson } from '../utilities.js';
export const lint = ({ options, variants }) => {
const firstVariant = Object.keys(variants)[0];
if (typeof firstVariant === 'undefined') {
throw new TypeError('No themes found');
}
const selectedVariant = variants[firstVariant];
const slug = slugify(selectedVariant?.name ?? '', { lowercase: true });
const theme = readToJson(path.join(options.output, `${slug}-color-theme.json`));
const checkThemeValues = (source) => {
for (const key in source) {
if (key) {
const currentValue = source[key];
if (typeof currentValue === 'object') {
checkThemeValues(currentValue);
return;
}
if (typeof currentValue === 'undefined') {
log.warn(`
Color is undefined.
{
"${key}": "undefined"
}
`);
return;
}
if (typeof currentValue === 'string') {
if (currentValue.includes('[object Object]')) {
log.warn(`
Color has invalid value:
{
"${key}": "${currentValue}"
}
`);
return;
}
if (currentValue.includes(options.prefix)) {
log.warn(`
Color was not formatted:
{
"${key}": "${currentValue}"
}
`);
return;
}
if (currentValue.includes('#ff0000')) {
log.warn(`
Color has default value:
{
"${key}": "${currentValue}"
}
This usually occurs when a color is not formatted.
`);
return;
}
}
}
}
};
checkThemeValues(theme);
};