|
1 | 1 | const esbuild = require('esbuild'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
2 | 4 |
|
3 | 5 | // Build configurations for different module formats |
4 | 6 | const builds = [ |
@@ -47,13 +49,73 @@ const builds = [ |
47 | 49 | }, |
48 | 50 | ]; |
49 | 51 |
|
| 52 | +// TypeScript declaration content |
| 53 | +const typeDeclaration = `// Type definitions for @matdata/yasgui-graph-plugin |
| 54 | +// Project: https://github.com/Matdata-eu/yasgui-graph-plugin |
| 55 | +
|
| 56 | +declare module '@matdata/yasgui-graph-plugin' { |
| 57 | + import type { default as Yasr } from '@zazuko/yasgui/build/ts/yasr'; |
| 58 | +
|
| 59 | + /** |
| 60 | + * YASGUI plugin for visualizing SPARQL CONSTRUCT and DESCRIBE query results as interactive graphs |
| 61 | + */ |
| 62 | + export default class GraphPlugin { |
| 63 | + /** |
| 64 | + * Creates a new GraphPlugin instance |
| 65 | + * @param yasr - The YASR instance |
| 66 | + */ |
| 67 | + constructor(yasr: typeof Yasr); |
| 68 | +
|
| 69 | + /** |
| 70 | + * Plugin priority (higher = shown first in tabs) |
| 71 | + */ |
| 72 | + static get priority(): number; |
| 73 | +
|
| 74 | + /** |
| 75 | + * Plugin label for tab display |
| 76 | + */ |
| 77 | + static get label(): string; |
| 78 | +
|
| 79 | + /** |
| 80 | + * Check if plugin can handle the current results |
| 81 | + * @returns True if results are from CONSTRUCT or DESCRIBE query |
| 82 | + */ |
| 83 | + canHandleResults(): boolean; |
| 84 | +
|
| 85 | + /** |
| 86 | + * Render the graph visualization |
| 87 | + */ |
| 88 | + draw(): void; |
| 89 | +
|
| 90 | + /** |
| 91 | + * Download the current visualization as PNG |
| 92 | + */ |
| 93 | + download(): void; |
| 94 | +
|
| 95 | + /** |
| 96 | + * Get vis-network configuration options |
| 97 | + * @returns Network options for vis-network |
| 98 | + */ |
| 99 | + getNetworkOptions(): any; |
| 100 | + } |
| 101 | +} |
| 102 | +`; |
| 103 | + |
50 | 104 | // Build all formats |
51 | 105 | Promise.all(builds.map(config => esbuild.build(config))) |
52 | 106 | .then(() => { |
| 107 | + // Create TypeScript declaration file |
| 108 | + const distDir = path.join(__dirname, 'dist'); |
| 109 | + if (!fs.existsSync(distDir)) { |
| 110 | + fs.mkdirSync(distDir, { recursive: true }); |
| 111 | + } |
| 112 | + fs.writeFileSync(path.join(distDir, 'index.d.ts'), typeDeclaration); |
| 113 | + |
53 | 114 | console.log('✅ Build complete:'); |
54 | 115 | console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)'); |
55 | 116 | console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)'); |
56 | 117 | console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)'); |
| 118 | + console.log(' - dist/index.d.ts (TypeScript declarations)'); |
57 | 119 | }) |
58 | 120 | .catch((err) => { |
59 | 121 | console.error('❌ Build failed:', err); |
|
0 commit comments