import { readFileSync } from 'fs';
|
|
|
|
import matter from 'gray-matter';
|
|
import yaml from 'js-yaml';
|
|
import S from 'jsonschema-definer';
|
|
|
|
export const isDev = process.env['NODE_ENV'] === 'development';
|
|
|
|
export function readYAML(filepath: string) {
|
|
return matter(readFileSync(filepath, 'utf-8'), {
|
|
engines: {
|
|
yaml: {
|
|
parse: (s) =>
|
|
s
|
|
? (yaml.load(s, {
|
|
schema: yaml.JSON_SCHEMA,
|
|
}) as Record<string, any>)
|
|
: {},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
export const oItem = {
|
|
skip: S.boolean().optional(),
|
|
examples: S.list(
|
|
S.shape({
|
|
ja: S.string(),
|
|
en: S.string().optional(),
|
|
}).additionalProperties(true),
|
|
).optional(),
|
|
};
|