UNPKG

@curvenote/cli-plugin

Version:
31 lines (30 loc) 1.4 kB
import { u } from 'unist-builder'; export function validateStringOptions(vfile, fieldName, field, validValues) { const notString = typeof field !== 'string'; const invalidValues = validValues && typeof field === 'string' && !validValues.includes(field); if (notString) vfile.message(`Invalid ${fieldName} supplied.`); if (invalidValues) vfile.message(`Invalid ${fieldName} supplied must be one of (${validValues.join(' | ')}).`); } export function makePlaceholder(data, description) { var _a, _b; const optionList = data.options ? [ u('ul', (_b = (_a = Object.entries(data.options)) === null || _a === void 0 ? void 0 : _a.map(([key, value]) => u('listItem', [u('inlineCode', key), u('text', `: ${String(value)}`)]))) !== null && _b !== void 0 ? _b : []), ] : []; return [ u('admonition', { kind: 'important' }, [ u('admonitionTitle', [u('inlineCode', [u('text', data.name)])]), u('paragraph', [ u('text', 'This block will be replaced with '), u('strong', [u('text', description)]), u('text', ' when deployed to '), u('link', { url: 'https://curvenote.com' }, [u('text', 'Curvenote')]), u('text', '.'), ]), u('paragraph', [u('text', 'Options:'), ...optionList]), ]), ]; }