| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #!/usr/bin/env node
- const fs = require('fs');
- const path = require('path');
- const { CORE_FIELDS, REQUIRED_FIELDS, MANUAL_ONLY_FIELDS, PGY_ALIAS, INDEXES, buildDdl, buildQueryMap } = require('../mcp/src/features/tihao-sourcing/media-library-schema');
- function main() {
- const args = parseArgs(process.argv.slice(2));
- const outputDir = path.resolve(args.output || path.join(__dirname, '..', 'docs'));
- fs.mkdirSync(outputDir, { recursive: true });
- const files = {
- schema: path.join(outputDir, 'media-library-field-schema.json'),
- ddl: path.join(outputDir, 'media-library-collection-ddl.txt'),
- queryMap: path.join(outputDir, 'media-library-query-map.md')
- };
- fs.writeFileSync(files.schema, JSON.stringify({
- collection: 'media_library',
- generatedAt: new Date().toISOString(),
- coreFields: CORE_FIELDS,
- requiredFields: REQUIRED_FIELDS,
- manualOnlyFields: MANUAL_ONLY_FIELDS,
- pgyAlias: PGY_ALIAS,
- indexes: INDEXES
- }, null, 2), 'utf8');
- fs.writeFileSync(files.ddl, buildDdl(), 'utf8');
- fs.writeFileSync(files.queryMap, buildQueryMap(), 'utf8');
- console.log(JSON.stringify({
- outputDir,
- fieldCount: Object.keys(CORE_FIELDS).length,
- requiredCount: REQUIRED_FIELDS.length,
- manualOnlyCount: MANUAL_ONLY_FIELDS.length,
- pgyAliasCount: Object.keys(PGY_ALIAS).length,
- indexCount: INDEXES.length,
- files
- }, null, 2));
- }
- function parseArgs(argv) {
- const args = {};
- for (let index = 0; index < argv.length; index += 1) {
- const raw = argv[index];
- if (!raw.startsWith('--')) continue;
- const key = raw.slice(2).replace(/-([a-z])/g, (_, char) => char.toUpperCase());
- const next = argv[index + 1];
- if (!next || next.startsWith('--')) args[key] = true;
- else {
- args[key] = next;
- index += 1;
- }
- }
- return args;
- }
- if (require.main === module) {
- try {
- main();
- } catch (error) {
- console.error(error && error.stack ? error.stack : String(error));
- process.exit(1);
- }
- }
- module.exports = { main };
|