mirror of
https://github.com/yamadashy/repomix.git
synced 2026-05-30 11:18:53 +02:00
53ddb5ac36
intent(test-coverage): normalizeObjectNode is the load-bearing workaround for @valibot/to-json-schema's output gaps (missing additionalProperties:false, noisy empty required arrays). A bug in its tree walk would silently break the published repomix.config.json IntelliSense schema. Extract to its own module and pin the behavior: adding/respecting additionalProperties, stripping empty required, recursing through properties / anyOf / oneOf / items, handling null and primitives
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { toJsonSchema } from '@valibot/to-json-schema';
|
|
import { repomixConfigFileSchema } from '../../../src/config/configSchema.js';
|
|
import { normalizeObjectNode } from './normalizeJsonSchema.js';
|
|
|
|
const getPackageVersion = async (): Promise<string> => {
|
|
const packageJsonPath = path.resolve('./package.json');
|
|
const packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8');
|
|
const packageJson = JSON.parse(packageJsonContent);
|
|
return packageJson.version;
|
|
};
|
|
|
|
const generateSchema = async () => {
|
|
const version = await getPackageVersion();
|
|
const versionParts = version.split('.');
|
|
const majorMinorVersion = `${versionParts[0]}.${versionParts[1]}.${versionParts[2]}`;
|
|
|
|
const jsonSchema = toJsonSchema(repomixConfigFileSchema, {
|
|
target: 'draft-07',
|
|
});
|
|
normalizeObjectNode(jsonSchema);
|
|
|
|
const schemaWithMeta = {
|
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
...jsonSchema,
|
|
title: 'Repomix Configuration',
|
|
description: 'Schema for repomix.config.json configuration file',
|
|
};
|
|
|
|
const baseOutputDir = path.resolve('./website/client/src/public/schemas');
|
|
await fs.mkdir(baseOutputDir, { recursive: true });
|
|
|
|
const versionedOutputDir = path.resolve(baseOutputDir, majorMinorVersion);
|
|
await fs.mkdir(versionedOutputDir, { recursive: true });
|
|
|
|
const versionedOutputPath = path.resolve(versionedOutputDir, 'schema.json');
|
|
await fs.writeFile(versionedOutputPath, JSON.stringify(schemaWithMeta, null, 2), 'utf-8');
|
|
|
|
const latestOutputDir = path.resolve(baseOutputDir, 'latest');
|
|
await fs.mkdir(latestOutputDir, { recursive: true });
|
|
const latestOutputPath = path.resolve(latestOutputDir, 'schema.json');
|
|
await fs.writeFile(latestOutputPath, JSON.stringify(schemaWithMeta, null, 2), 'utf-8');
|
|
|
|
console.log(`Schema generated at ${versionedOutputPath}`);
|
|
console.log(`Schema also generated at ${latestOutputPath}`);
|
|
};
|
|
|
|
generateSchema().catch(console.error);
|