@reverso/scanner 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/output/index.d.ts +6 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +6 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/json-writer.d.ts +32 -0
- package/dist/output/json-writer.d.ts.map +1 -0
- package/dist/output/json-writer.js +169 -0
- package/dist/output/json-writer.js.map +1 -0
- package/dist/output/types-writer.d.ts +24 -0
- package/dist/output/types-writer.d.ts.map +1 -0
- package/dist/output/types-writer.js +209 -0
- package/dist/output/types-writer.js.map +1 -0
- package/dist/parser/ast-parser.d.ts +79 -0
- package/dist/parser/ast-parser.d.ts.map +1 -0
- package/dist/parser/ast-parser.js +201 -0
- package/dist/parser/ast-parser.js.map +1 -0
- package/dist/parser/attribute-extractor.d.ts +29 -0
- package/dist/parser/attribute-extractor.d.ts.map +1 -0
- package/dist/parser/attribute-extractor.js +204 -0
- package/dist/parser/attribute-extractor.js.map +1 -0
- package/dist/parser/index.d.ts +7 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +7 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/jsx-walker.d.ts +31 -0
- package/dist/parser/jsx-walker.d.ts.map +1 -0
- package/dist/parser/jsx-walker.js +103 -0
- package/dist/parser/jsx-walker.js.map +1 -0
- package/dist/scanner.d.ts +101 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +204 -0
- package/dist/scanner.js.map +1 -0
- package/dist/schema/generator.d.ts +22 -0
- package/dist/schema/generator.d.ts.map +1 -0
- package/dist/schema/generator.js +176 -0
- package/dist/schema/generator.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +6 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/normalizer.d.ts +45 -0
- package/dist/schema/normalizer.d.ts.map +1 -0
- package/dist/schema/normalizer.js +165 -0
- package/dist/schema/normalizer.js.map +1 -0
- package/dist/watch/index.d.ts +5 -0
- package/dist/watch/index.d.ts.map +1 -0
- package/dist/watch/index.js +5 -0
- package/dist/watch/index.js.map +1 -0
- package/dist/watch/watcher.d.ts +82 -0
- package/dist/watch/watcher.d.ts.map +1 -0
- package/dist/watch/watcher.js +141 -0
- package/dist/watch/watcher.js.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @reverso/scanner
|
|
2
|
+
|
|
3
|
+
AST parser for detecting `data-reverso` markers in React/Next.js code.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @reverso/scanner
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Scanner } from '@reverso/scanner';
|
|
15
|
+
|
|
16
|
+
const scanner = new Scanner({
|
|
17
|
+
rootDir: './src',
|
|
18
|
+
include: ['**/*.tsx'],
|
|
19
|
+
exclude: ['**/node_modules/**'],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Scan and generate schema
|
|
23
|
+
const schema = await scanner.scan();
|
|
24
|
+
|
|
25
|
+
// Watch for changes
|
|
26
|
+
scanner.watch((schema) => {
|
|
27
|
+
console.log('Schema updated:', schema.pages.length, 'pages');
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **AST Parsing**: Uses ts-morph for accurate JSX analysis
|
|
34
|
+
- **Marker Detection**: Finds all `data-reverso-*` attributes
|
|
35
|
+
- **Schema Generation**: Creates structured schema from markers
|
|
36
|
+
- **Watch Mode**: Real-time scanning with chokidar
|
|
37
|
+
- **Type Inference**: Detects field types from attributes
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
See [https://reverso.dev/docs/packages/scanner](https://reverso.dev/docs/packages/scanner)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reverso/scanner
|
|
3
|
+
*
|
|
4
|
+
* AST parser for detecting data-reverso markers in React/Next.js code.
|
|
5
|
+
* Uses ts-morph to parse TypeScript/JSX and extract field definitions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createScanner, scan } from '@reverso/scanner';
|
|
10
|
+
*
|
|
11
|
+
* // One-time scan
|
|
12
|
+
* const result = await scan({
|
|
13
|
+
* srcDir: './src',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* console.log(`Found ${result.schema.totalFields} fields`);
|
|
17
|
+
*
|
|
18
|
+
* // Watch mode
|
|
19
|
+
* const scanner = createScanner({
|
|
20
|
+
* srcDir: './src',
|
|
21
|
+
* outputDir: '.reverso',
|
|
22
|
+
* watch: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* scanner.on((event) => {
|
|
26
|
+
* if (event.type === 'complete') {
|
|
27
|
+
* console.log('Schema updated:', event.schema);
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* await scanner.startWatch();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const VERSION = "0.0.0";
|
|
35
|
+
export { Scanner, createScanner, scan, type ScannerOptions, type ScanEventType, type ScanEvent, type ScanEventHandler, } from './scanner.js';
|
|
36
|
+
export { AstParser, createParser, walkJsxElements, getUniquePaths, groupFieldsByPath, findDuplicatePaths, hasReversoMarker, extractAttributes, getElementTextContent, type AstParserOptions, type ParseResult, type JsxWalkerOptions, type ExtractedAttributes, } from './parser/index.js';
|
|
37
|
+
export { generateSchema, convertToFieldSchema, updateSchemaMeta, normalizeFieldPath, normalizeFields, sortSectionFields, sortPageSections, sortSchemaPages, ensureLabels, deduplicateFields, mergeFields, reorderSections, validateSchemaStructure, } from './schema/index.js';
|
|
38
|
+
export { writeJsonSchema, readJsonSchema, compareSchemas, formatSchemaDiff, generateTypeDefinitions, writeTypesFile, type JsonWriterOptions, type TypesWriterOptions, } from './output/index.js';
|
|
39
|
+
export { FileWatcher, createWatcher, type WatchEventType, type WatchEvent, type WatchEventHandler, type WatcherOptions, } from './watch/index.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,WAAW,EACX,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reverso/scanner
|
|
3
|
+
*
|
|
4
|
+
* AST parser for detecting data-reverso markers in React/Next.js code.
|
|
5
|
+
* Uses ts-morph to parse TypeScript/JSX and extract field definitions.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createScanner, scan } from '@reverso/scanner';
|
|
10
|
+
*
|
|
11
|
+
* // One-time scan
|
|
12
|
+
* const result = await scan({
|
|
13
|
+
* srcDir: './src',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* console.log(`Found ${result.schema.totalFields} fields`);
|
|
17
|
+
*
|
|
18
|
+
* // Watch mode
|
|
19
|
+
* const scanner = createScanner({
|
|
20
|
+
* srcDir: './src',
|
|
21
|
+
* outputDir: '.reverso',
|
|
22
|
+
* watch: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* scanner.on((event) => {
|
|
26
|
+
* if (event.type === 'complete') {
|
|
27
|
+
* console.log('Schema updated:', event.schema);
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* await scanner.startWatch();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const VERSION = '0.0.0';
|
|
35
|
+
// Main scanner exports
|
|
36
|
+
export { Scanner, createScanner, scan, } from './scanner.js';
|
|
37
|
+
// Parser exports
|
|
38
|
+
export { AstParser, createParser, walkJsxElements, getUniquePaths, groupFieldsByPath, findDuplicatePaths, hasReversoMarker, extractAttributes, getElementTextContent, } from './parser/index.js';
|
|
39
|
+
// Schema exports
|
|
40
|
+
export { generateSchema, convertToFieldSchema, updateSchemaMeta, normalizeFieldPath, normalizeFields, sortSectionFields, sortPageSections, sortSchemaPages, ensureLabels, deduplicateFields, mergeFields, reorderSections, validateSchemaStructure, } from './schema/index.js';
|
|
41
|
+
// Output exports
|
|
42
|
+
export { writeJsonSchema, readJsonSchema, compareSchemas, formatSchemaDiff, generateTypeDefinitions, writeTypesFile, } from './output/index.js';
|
|
43
|
+
// Watch exports
|
|
44
|
+
export { FileWatcher, createWatcher, } from './watch/index.js';
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,uBAAuB;AACvB,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,GAKL,MAAM,cAAc,CAAC;AAEtB,iBAAiB;AACjB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,GAKtB,MAAM,mBAAmB,CAAC;AAE3B,iBAAiB;AACjB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B,iBAAiB;AACjB,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,GAGf,MAAM,mBAAmB,CAAC;AAE3B,gBAAgB;AAChB,OAAO,EACL,WAAW,EACX,aAAa,GAKd,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output exports for @reverso/scanner
|
|
3
|
+
*/
|
|
4
|
+
export { writeJsonSchema, readJsonSchema, compareSchemas, formatSchemaDiff, type JsonWriterOptions, } from './json-writer.js';
|
|
5
|
+
export { generateTypeDefinitions, writeTypesFile, type TypesWriterOptions, } from './types-writer.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/output/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/output/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,uBAAuB,EACvB,cAAc,GAEf,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON schema output writer.
|
|
3
|
+
*/
|
|
4
|
+
import type { ProjectSchema, SchemaDiff } from '@reverso/core';
|
|
5
|
+
/**
|
|
6
|
+
* Options for writing JSON schema.
|
|
7
|
+
*/
|
|
8
|
+
export interface JsonWriterOptions {
|
|
9
|
+
/** Output directory */
|
|
10
|
+
outputDir: string;
|
|
11
|
+
/** Pretty print JSON (default: true) */
|
|
12
|
+
pretty?: boolean;
|
|
13
|
+
/** Indent size for pretty printing (default: 2) */
|
|
14
|
+
indent?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Write schema to a JSON file.
|
|
18
|
+
*/
|
|
19
|
+
export declare function writeJsonSchema(schema: ProjectSchema, options: JsonWriterOptions): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Read existing schema from JSON file.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readJsonSchema(options: JsonWriterOptions): Promise<ProjectSchema | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Compare two schemas and return the differences.
|
|
26
|
+
*/
|
|
27
|
+
export declare function compareSchemas(before: ProjectSchema | null, after: ProjectSchema): SchemaDiff;
|
|
28
|
+
/**
|
|
29
|
+
* Format schema diff as a human-readable string.
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatSchemaDiff(diff: SchemaDiff): string;
|
|
32
|
+
//# sourceMappingURL=json-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-writer.d.ts","sourceRoot":"","sources":["../../src/output/json-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAe,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG5E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAa9F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,KAAK,EAAE,aAAa,GAAG,UAAU,CA0E7F;AAqCD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CA6BzD"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON schema output writer.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { SCHEMA_FILE_NAME } from '@reverso/core';
|
|
8
|
+
/**
|
|
9
|
+
* Write schema to a JSON file.
|
|
10
|
+
*/
|
|
11
|
+
export async function writeJsonSchema(schema, options) {
|
|
12
|
+
const outputPath = join(options.outputDir, SCHEMA_FILE_NAME);
|
|
13
|
+
// Ensure output directory exists
|
|
14
|
+
if (!existsSync(options.outputDir)) {
|
|
15
|
+
await mkdir(options.outputDir, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
// Serialize to JSON
|
|
18
|
+
const pretty = options.pretty !== false;
|
|
19
|
+
const indent = options.indent ?? 2;
|
|
20
|
+
const content = pretty ? JSON.stringify(schema, null, indent) : JSON.stringify(schema);
|
|
21
|
+
// Write file
|
|
22
|
+
await writeFile(outputPath, content, 'utf-8');
|
|
23
|
+
return outputPath;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read existing schema from JSON file.
|
|
27
|
+
*/
|
|
28
|
+
export async function readJsonSchema(options) {
|
|
29
|
+
const outputPath = join(options.outputDir, SCHEMA_FILE_NAME);
|
|
30
|
+
if (!existsSync(outputPath)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
35
|
+
return JSON.parse(content);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Compare two schemas and return the differences.
|
|
43
|
+
*/
|
|
44
|
+
export function compareSchemas(before, after) {
|
|
45
|
+
if (!before) {
|
|
46
|
+
// Everything is new
|
|
47
|
+
const allFields = after.pages.flatMap((page) => page.sections.flatMap((section) => section.fields));
|
|
48
|
+
return {
|
|
49
|
+
added: allFields,
|
|
50
|
+
removed: [],
|
|
51
|
+
modified: [],
|
|
52
|
+
hasChanges: allFields.length > 0,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const beforeFields = new Map();
|
|
56
|
+
const afterFields = new Map();
|
|
57
|
+
// Collect all fields from before schema
|
|
58
|
+
for (const page of before.pages) {
|
|
59
|
+
for (const section of page.sections) {
|
|
60
|
+
for (const field of section.fields) {
|
|
61
|
+
beforeFields.set(field.path, field);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Collect all fields from after schema
|
|
66
|
+
for (const page of after.pages) {
|
|
67
|
+
for (const section of page.sections) {
|
|
68
|
+
for (const field of section.fields) {
|
|
69
|
+
afterFields.set(field.path, field);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Find added fields
|
|
74
|
+
const added = [];
|
|
75
|
+
for (const [path, field] of afterFields) {
|
|
76
|
+
if (!beforeFields.has(path)) {
|
|
77
|
+
added.push(field);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Find removed fields
|
|
81
|
+
const removed = [];
|
|
82
|
+
for (const [path, field] of beforeFields) {
|
|
83
|
+
if (!afterFields.has(path)) {
|
|
84
|
+
removed.push(field);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Find modified fields
|
|
88
|
+
const modified = [];
|
|
89
|
+
for (const [path, afterField] of afterFields) {
|
|
90
|
+
const beforeField = beforeFields.get(path);
|
|
91
|
+
if (beforeField) {
|
|
92
|
+
const changes = getFieldChanges(beforeField, afterField);
|
|
93
|
+
if (changes.length > 0) {
|
|
94
|
+
modified.push({
|
|
95
|
+
path,
|
|
96
|
+
before: beforeField,
|
|
97
|
+
after: afterField,
|
|
98
|
+
changes,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
added,
|
|
105
|
+
removed,
|
|
106
|
+
modified,
|
|
107
|
+
hasChanges: added.length > 0 || removed.length > 0 || modified.length > 0,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the list of changed properties between two fields.
|
|
112
|
+
*/
|
|
113
|
+
function getFieldChanges(before, after) {
|
|
114
|
+
const changes = [];
|
|
115
|
+
const keys = [
|
|
116
|
+
'type',
|
|
117
|
+
'label',
|
|
118
|
+
'placeholder',
|
|
119
|
+
'required',
|
|
120
|
+
'validation',
|
|
121
|
+
'options',
|
|
122
|
+
'condition',
|
|
123
|
+
'help',
|
|
124
|
+
'min',
|
|
125
|
+
'max',
|
|
126
|
+
'step',
|
|
127
|
+
'accept',
|
|
128
|
+
'multiple',
|
|
129
|
+
'rows',
|
|
130
|
+
'width',
|
|
131
|
+
'readonly',
|
|
132
|
+
'hidden',
|
|
133
|
+
];
|
|
134
|
+
for (const key of keys) {
|
|
135
|
+
if (before[key] !== after[key]) {
|
|
136
|
+
changes.push(key);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return changes;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Format schema diff as a human-readable string.
|
|
143
|
+
*/
|
|
144
|
+
export function formatSchemaDiff(diff) {
|
|
145
|
+
const lines = [];
|
|
146
|
+
if (diff.added.length > 0) {
|
|
147
|
+
lines.push(`Added (${diff.added.length}):`);
|
|
148
|
+
for (const field of diff.added) {
|
|
149
|
+
lines.push(` + ${field.path} (${field.type})`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (diff.removed.length > 0) {
|
|
153
|
+
lines.push(`Removed (${diff.removed.length}):`);
|
|
154
|
+
for (const field of diff.removed) {
|
|
155
|
+
lines.push(` - ${field.path} (${field.type})`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (diff.modified.length > 0) {
|
|
159
|
+
lines.push(`Modified (${diff.modified.length}):`);
|
|
160
|
+
for (const mod of diff.modified) {
|
|
161
|
+
lines.push(` ~ ${mod.path}: ${mod.changes.join(', ')}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!diff.hasChanges) {
|
|
165
|
+
lines.push('No changes detected.');
|
|
166
|
+
}
|
|
167
|
+
return lines.join('\n');
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=json-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-writer.js","sourceRoot":"","sources":["../../src/output/json-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAcjD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAqB,EACrB,OAA0B;IAE1B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAE7D,iCAAiC;IACjC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACnC,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,oBAAoB;IACpB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC;IACxC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;IACnC,MA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AI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types output writer.
|
|
3
|
+
*/
|
|
4
|
+
import { type ProjectSchema } from '@reverso/core';
|
|
5
|
+
/**
|
|
6
|
+
* Options for writing TypeScript types.
|
|
7
|
+
*/
|
|
8
|
+
export interface TypesWriterOptions {
|
|
9
|
+
/** Output directory */
|
|
10
|
+
outputDir: string;
|
|
11
|
+
/** Include JSDoc comments (default: true) */
|
|
12
|
+
includeComments?: boolean;
|
|
13
|
+
/** Export format: 'named' | 'default' (default: 'named') */
|
|
14
|
+
exportFormat?: 'named' | 'default';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate TypeScript type definitions from a schema.
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateTypeDefinitions(schema: ProjectSchema, options?: TypesWriterOptions): string;
|
|
20
|
+
/**
|
|
21
|
+
* Write TypeScript types to a file.
|
|
22
|
+
*/
|
|
23
|
+
export declare function writeTypesFile(schema: ProjectSchema, options: TypesWriterOptions): Promise<string>;
|
|
24
|
+
//# sourceMappingURL=types-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-writer.d.ts","sourceRoot":"","sources":["../../src/output/types-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAIL,KAAK,aAAa,EAKnB,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACpC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,kBAAsC,GAC9C,MAAM,CAwCR;AAiLD;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAejB"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types output writer.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { TYPES_FILE_NAME, camelCase, pascalCase, } from '@reverso/core';
|
|
8
|
+
/**
|
|
9
|
+
* Generate TypeScript type definitions from a schema.
|
|
10
|
+
*/
|
|
11
|
+
export function generateTypeDefinitions(schema, options = { outputDir: '' }) {
|
|
12
|
+
const lines = [];
|
|
13
|
+
const includeComments = options.includeComments !== false;
|
|
14
|
+
// Header
|
|
15
|
+
lines.push('/**');
|
|
16
|
+
lines.push(' * Auto-generated types from Reverso CMS schema.');
|
|
17
|
+
lines.push(' * Do not edit this file manually.');
|
|
18
|
+
lines.push(` * Generated at: ${schema.generatedAt}`);
|
|
19
|
+
lines.push(' */');
|
|
20
|
+
lines.push('');
|
|
21
|
+
// Import base types
|
|
22
|
+
lines.push('import type {');
|
|
23
|
+
lines.push(' ImageValue,');
|
|
24
|
+
lines.push(' FileValue,');
|
|
25
|
+
lines.push(' GalleryValue,');
|
|
26
|
+
lines.push(' VideoValue,');
|
|
27
|
+
lines.push(' AudioValue,');
|
|
28
|
+
lines.push(' OEmbedValue,');
|
|
29
|
+
lines.push(' LinkValue,');
|
|
30
|
+
lines.push(' MapValue,');
|
|
31
|
+
lines.push(' BlocksValue,');
|
|
32
|
+
lines.push(' RelationValue,');
|
|
33
|
+
lines.push(' TaxonomyValue,');
|
|
34
|
+
lines.push(' UserValue,');
|
|
35
|
+
lines.push(' CodeValue,');
|
|
36
|
+
lines.push("} from '@reverso/core';");
|
|
37
|
+
lines.push('');
|
|
38
|
+
// Generate types for each page
|
|
39
|
+
for (const page of schema.pages) {
|
|
40
|
+
lines.push(...generatePageTypes(page, includeComments));
|
|
41
|
+
lines.push('');
|
|
42
|
+
}
|
|
43
|
+
// Generate root content type
|
|
44
|
+
lines.push(generateRootType(schema, includeComments));
|
|
45
|
+
return lines.join('\n');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generate types for a single page.
|
|
49
|
+
*/
|
|
50
|
+
function generatePageTypes(page, includeComments) {
|
|
51
|
+
const lines = [];
|
|
52
|
+
const pageTypeName = `${pascalCase(page.slug)}Content`;
|
|
53
|
+
if (includeComments) {
|
|
54
|
+
lines.push(`/** Content for the ${page.name} page */`);
|
|
55
|
+
}
|
|
56
|
+
lines.push(`export interface ${pageTypeName} {`);
|
|
57
|
+
for (const section of page.sections) {
|
|
58
|
+
const sectionTypeName = pascalCase(page.slug) + pascalCase(section.slug);
|
|
59
|
+
if (includeComments && section.isRepeater) {
|
|
60
|
+
lines.push(` /** ${section.name} (repeater) */`);
|
|
61
|
+
}
|
|
62
|
+
else if (includeComments) {
|
|
63
|
+
lines.push(` /** ${section.name} */`);
|
|
64
|
+
}
|
|
65
|
+
if (section.isRepeater) {
|
|
66
|
+
lines.push(` ${camelCase(section.slug)}: ${sectionTypeName}Item[];`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
lines.push(` ${camelCase(section.slug)}: ${sectionTypeName};`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
lines.push('}');
|
|
73
|
+
lines.push('');
|
|
74
|
+
// Generate section types
|
|
75
|
+
for (const section of page.sections) {
|
|
76
|
+
lines.push(...generateSectionTypes(page, section, includeComments));
|
|
77
|
+
}
|
|
78
|
+
return lines;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Generate types for a single section.
|
|
82
|
+
*/
|
|
83
|
+
function generateSectionTypes(page, section, includeComments) {
|
|
84
|
+
const lines = [];
|
|
85
|
+
const sectionTypeName = pascalCase(page.slug) + pascalCase(section.slug);
|
|
86
|
+
const typeName = section.isRepeater ? `${sectionTypeName}Item` : sectionTypeName;
|
|
87
|
+
if (includeComments) {
|
|
88
|
+
lines.push(`/** ${section.name} ${section.isRepeater ? 'item' : 'section'} */`);
|
|
89
|
+
}
|
|
90
|
+
lines.push(`export interface ${typeName} {`);
|
|
91
|
+
// Get fields for this section (filter out repeater placeholder)
|
|
92
|
+
const fields = section.fields.filter((f) => {
|
|
93
|
+
const parts = f.path.split('.');
|
|
94
|
+
return !parts.includes('$') || parts[parts.length - 1] !== '$';
|
|
95
|
+
});
|
|
96
|
+
for (const field of fields) {
|
|
97
|
+
const fieldName = getFieldName(field);
|
|
98
|
+
const fieldType = getTypeScriptType(field);
|
|
99
|
+
const isOptional = !field.required;
|
|
100
|
+
if (includeComments && field.label) {
|
|
101
|
+
lines.push(` /** ${field.label} */`);
|
|
102
|
+
}
|
|
103
|
+
lines.push(` ${camelCase(fieldName)}${isOptional ? '?' : ''}: ${fieldType};`);
|
|
104
|
+
}
|
|
105
|
+
lines.push('}');
|
|
106
|
+
lines.push('');
|
|
107
|
+
return lines;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the field name from a field schema.
|
|
111
|
+
*/
|
|
112
|
+
function getFieldName(field) {
|
|
113
|
+
const parts = field.path.split('.');
|
|
114
|
+
// Skip the repeater placeholder if present
|
|
115
|
+
const filtered = parts.filter((p) => p !== '$');
|
|
116
|
+
// Return the last part
|
|
117
|
+
return filtered[filtered.length - 1] ?? 'unknown';
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Map Reverso field types to TypeScript types.
|
|
121
|
+
*/
|
|
122
|
+
function getTypeScriptType(field) {
|
|
123
|
+
const typeMap = {
|
|
124
|
+
// Text inputs
|
|
125
|
+
text: 'string',
|
|
126
|
+
textarea: 'string',
|
|
127
|
+
number: 'number',
|
|
128
|
+
range: 'number',
|
|
129
|
+
email: 'string',
|
|
130
|
+
url: 'string',
|
|
131
|
+
phone: 'string',
|
|
132
|
+
// Rich content
|
|
133
|
+
wysiwyg: 'string',
|
|
134
|
+
markdown: 'string',
|
|
135
|
+
code: 'CodeValue',
|
|
136
|
+
blocks: 'BlocksValue',
|
|
137
|
+
// Selection
|
|
138
|
+
select: 'string',
|
|
139
|
+
multiselect: 'string[]',
|
|
140
|
+
checkbox: 'boolean',
|
|
141
|
+
checkboxgroup: 'string[]',
|
|
142
|
+
radio: 'string',
|
|
143
|
+
boolean: 'boolean',
|
|
144
|
+
// Media
|
|
145
|
+
image: 'ImageValue',
|
|
146
|
+
file: 'FileValue',
|
|
147
|
+
gallery: 'GalleryValue',
|
|
148
|
+
video: 'VideoValue',
|
|
149
|
+
audio: 'AudioValue',
|
|
150
|
+
oembed: 'OEmbedValue',
|
|
151
|
+
// Date/Time
|
|
152
|
+
date: 'string',
|
|
153
|
+
datetime: 'string',
|
|
154
|
+
time: 'string',
|
|
155
|
+
// Relationships
|
|
156
|
+
relation: field.multiple ? 'RelationValue[]' : 'RelationValue',
|
|
157
|
+
taxonomy: field.multiple ? 'TaxonomyValue[]' : 'TaxonomyValue',
|
|
158
|
+
link: 'LinkValue',
|
|
159
|
+
pagelink: 'string',
|
|
160
|
+
user: 'UserValue',
|
|
161
|
+
// Advanced
|
|
162
|
+
color: 'string',
|
|
163
|
+
map: 'MapValue',
|
|
164
|
+
repeater: 'unknown[]', // Will be replaced with actual type
|
|
165
|
+
group: 'Record<string, unknown>',
|
|
166
|
+
flexible: 'unknown[]',
|
|
167
|
+
// UI helpers (no data)
|
|
168
|
+
message: 'never',
|
|
169
|
+
tab: 'never',
|
|
170
|
+
accordion: 'never',
|
|
171
|
+
buttongroup: 'string',
|
|
172
|
+
};
|
|
173
|
+
return typeMap[field.type] ?? 'unknown';
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Generate the root content type that combines all pages.
|
|
177
|
+
*/
|
|
178
|
+
function generateRootType(schema, includeComments) {
|
|
179
|
+
const lines = [];
|
|
180
|
+
if (includeComments) {
|
|
181
|
+
lines.push('/** All content types */');
|
|
182
|
+
}
|
|
183
|
+
lines.push('export interface ReversoContent {');
|
|
184
|
+
for (const page of schema.pages) {
|
|
185
|
+
const pageTypeName = `${pascalCase(page.slug)}Content`;
|
|
186
|
+
if (includeComments) {
|
|
187
|
+
lines.push(` /** ${page.name} */`);
|
|
188
|
+
}
|
|
189
|
+
lines.push(` ${camelCase(page.slug)}: ${pageTypeName};`);
|
|
190
|
+
}
|
|
191
|
+
lines.push('}');
|
|
192
|
+
return lines.join('\n');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Write TypeScript types to a file.
|
|
196
|
+
*/
|
|
197
|
+
export async function writeTypesFile(schema, options) {
|
|
198
|
+
const outputPath = join(options.outputDir, TYPES_FILE_NAME);
|
|
199
|
+
// Ensure output directory exists
|
|
200
|
+
if (!existsSync(options.outputDir)) {
|
|
201
|
+
await mkdir(options.outputDir, { recursive: true });
|
|
202
|
+
}
|
|
203
|
+
// Generate type definitions
|
|
204
|
+
const content = generateTypeDefinitions(schema, options);
|
|
205
|
+
// Write file
|
|
206
|
+
await writeFile(outputPath, content, 'utf-8');
|
|
207
|
+
return outputPath;
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=types-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-writer.js","sourceRoot":"","sources":["../../src/output/types-writer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAML,eAAe,EACf,SAAS,EACT,UAAU,GACX,MAAM,eAAe,CAAC;AAcvB;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAqB,EACrB,UAA8B,EAAE,SAAS,EAAE,EAAE,EAAE;IAE/C,MAAM,KAAK,GAA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