#!/usr/bin/env node
/**
* Quick Fix Script for TypeScript Errors
* Fixes common issues in cross-platform integration files
*/
import { writeFileSync, readFileSync } from 'fs';
import { join } from 'path';
class QuickFixer {
private projectRoot: string;
constructor() {
this.projectRoot = process.cwd();
}
/**
* Fix external-apis.ts TypeScript errors
*/
fixExternalAPIs(): void {
console.log('π§ Fixing external-apis.ts...');
const filePath = join(this.projectRoot, 'src/integrations/external-apis.ts');
let content = readFileSync(filePath, 'utf-8');
// Fix unknown data types with proper typing
content = content.replace(
/const data = await response\.json\(\);/g,
'const data = await response.json() as any;'
);
// Fix missing properties in optimization results
content = content.replace(
/return \{\s*original: string,\s*optimized: .+?,\s*savings:/g,
`return {
original: string,
optimized: optimized,
suggestions: [],
removed: [],
savings:`
);
// Add proper error handling
content = content.replace(
/throw new Error\(data\.error\?\./g,
'throw new Error((data as any)?.error?.'
);
writeFileSync(filePath, content);
console.log(' β
external-apis.ts fixed');
}
/**
* Fix build-tools.ts import issues
*/
fixBuildTools(): void {
console.log('π§ Fixing build-tools.ts...');
const filePath = join(this.projectRoot, 'src/integrations/build-tools.ts');
let content = readFileSync(filePath, 'utf-8');
// Fix import path
content = content.replace(
/from '\.\/framework-adapter\.js'/g,
"from '../adapters/framework-adapter.js'"
);
// Fix type parameters
content = content.replace(
/\.map\(f => /g,
'.map((f: any) => '
);
writeFileSync(filePath, content);
console.log(' β
build-tools.ts fixed');
}
/**
* Fix gemini-helper.ts initialization
*/
fixGeminiHelper(): void {
console.log('π§ Fixing gemini-helper.ts...');
const filePath = join(this.projectRoot, 'src/utils/gemini-helper.ts');
let content = readFileSync(filePath, 'utf-8');
// Fix definite assignment
content = content.replace(
/private genAI: GoogleGenerativeAI;/g,
'private genAI!: GoogleGenerativeAI; // Definite assignment'
);
writeFileSync(filePath, content);
console.log(' β
gemini-helper.ts fixed');
}
/**
* Create simplified test file
*/
createSimpleTest(): void {
console.log('π§ͺ Creating simple test file...');
const testContent = `// Simple test to verify core functionality
import { AdapterFactory } from '../src/adapters/framework-adapter.js';
console.log('Testing framework adapters...');
try {
const reactAdapter = AdapterFactory.getAdapter('react');
console.log('React adapter:', reactAdapter ? 'β
' : 'β');
const vueAdapter = AdapterFactory.getAdapter('vue');
console.log('Vue adapter:', vueAdapter ? 'β
' : 'β');
const supportedFrameworks = AdapterFactory.getSupportedFrameworks();
console.log('Supported frameworks:', supportedFrameworks);
console.log('\\nπ Basic adapter test completed!');
} catch (error) {
console.error('β Test failed:', error.message);
}`;
const testPath = join(this.projectRoot, 'test-simple.mjs');
writeFileSync(testPath, testContent);
console.log(' β
Simple test created at test-simple.mjs');
}
/**
* Create minimal working example
*/
createMinimalExample(): void {
console.log('π Creating minimal working example...');
const exampleContent = `#!/usr/bin/env node
/**
* Minimal Working Example - Cross-Platform Tailwind MCP
* Demonstrates basic framework conversion functionality
*/
// Mock GeminiHelper for testing without API key
class MockGeminiHelper {
async generateContent(prompt) {
console.log('π€ Mock AI generating content for:', prompt.substring(0, 50) + '...');
if (prompt.includes('React')) {
return \`import React from 'react';
export const Button = ({ children, className, ...props }) => {
return (
<button
className={\`bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 \${className || ''}\`}
{...props}
>
{children}
</button>
);
};\`;
}
if (prompt.includes('Vue')) {
return \`<template>
<button
:class="buttonClasses"
@click="$emit('click')"
>
<slot />
</button>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
className: String
})
const buttonClasses = computed(() => [
'bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600',
props.className
].filter(Boolean).join(' '))
</script>\`;
}
return 'Generated component content...';
}
}
// Minimal framework conversion example
class MinimalFrameworkConverter {
constructor() {
this.gemini = new MockGeminiHelper();
}
async convertToReact(htmlComponent) {
console.log('π Converting to React...');
const prompt = \`Convert this HTML to React: \${htmlComponent}\`;
return await this.gemini.generateContent(prompt);
}
async convertToVue(htmlComponent) {
console.log('π Converting to Vue...');
const prompt = \`Convert this HTML to Vue: \${htmlComponent}\`;
return await this.gemini.generateContent(prompt);
}
}
// Demo usage
async function runDemo() {
console.log('π Cross-Platform Tailwind MCP Demo\\n');
const converter = new MinimalFrameworkConverter();
const htmlComponent = \`
<button class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 transition-colors">
Click me
</button>
\`;
console.log('π Original HTML:');
console.log(htmlComponent);
console.log('\\n' + '='.repeat(50) + '\\n');
// Convert to React
const reactComponent = await converter.convertToReact(htmlComponent);
console.log('βοΈ React Component:');
console.log(reactComponent);
console.log('\\n' + '='.repeat(50) + '\\n');
// Convert to Vue
const vueComponent = await converter.convertToVue(htmlComponent);
console.log('π Vue Component:');
console.log(vueComponent);
console.log('\\n' + '='.repeat(50) + '\\n');
console.log('β
Demo completed successfully!');
console.log('π‘ This shows how the cross-platform system works');
console.log('π― Ready for integration with real Gemini API');
}
// Run demo
runDemo().catch(console.error);`;
const examplePath = join(this.projectRoot, 'examples/minimal-demo.mjs');
writeFileSync(examplePath, exampleContent);
console.log(' β
Minimal example created at examples/minimal-demo.mjs');
}
/**
* Run all fixes
*/
runAllFixes(): void {
console.log('π οΈ Running Quick Fixes for MCP Tailwind Gemini\\n');
try {
this.fixExternalAPIs();
this.fixBuildTools();
this.fixGeminiHelper();
this.createSimpleTest();
this.createMinimalExample();
console.log('\\nβ
All fixes completed successfully!');
console.log('\\nπ Next Steps:');
console.log('1. Run: npm run build');
console.log('2. Test: node test-simple.mjs');
console.log('3. Demo: node examples/minimal-demo.mjs');
console.log('4. Deploy: Use with Claude Desktop');
} catch (error) {
console.error('β Fix failed:', error.message);
}
}
}
// Run fixes if this file is executed directly
if (import.meta.url === \`file://\${process.argv[1]}\`) {
const fixer = new QuickFixer();
fixer.runAllFixes();
}
export { QuickFixer };