Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
128 lines
4.4 KiB
JavaScript
128 lines
4.4 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
const glob = require('glob');
|
||
|
||
// Vue 3 migration patterns
|
||
const migrationPatterns = [
|
||
// Replace iView with ViewUIPlus
|
||
{ from: /import\s+{\s*([^}]+)\s*}\s+from\s+['"]iview['"]/g, to: "import { $1 } from 'view-ui-plus'" },
|
||
{ from: /import\s+iView\s+from\s+['"]iview['"]/g, to: "import ViewUIPlus from 'view-ui-plus'" },
|
||
{ from: /this\.\$Message/g, to: "this.$Message" },
|
||
{ from: /this\.\$Modal/g, to: "this.$Modal" },
|
||
{ from: /this\.\$Notice/g, to: "this.$Notice" },
|
||
{ from: /this\.\$Spin/g, to: "this.$Spin" },
|
||
|
||
// Replace component names
|
||
{ from: /<i-/g, to: "<" },
|
||
{ from: /<\/i-/g, to: "</" },
|
||
|
||
// Vue 3 event bus
|
||
{ from: /this\.\$eventBus\.\$emit/g, to: "this.$eventBus.emit" },
|
||
{ from: /this\.\$eventBus\.\$on/g, to: "this.$eventBus.on" },
|
||
{ from: /this\.\$eventBus\.\$off/g, to: "this.$eventBus.off" },
|
||
|
||
// Vue 3 slots
|
||
{ from: /slot="([^"]+)"/g, to: 'v-slot:$1' },
|
||
{ from: /slot-scope="([^"]+)"/g, to: 'v-slot="$1"' },
|
||
|
||
// Vue 3 filters (need to be converted to methods or computed)
|
||
{ from: /\|\s*(\w+)/g, to: (match, filterName) => {
|
||
console.log(`Warning: Filter "${filterName}" needs to be converted to a method or computed property`);
|
||
return match;
|
||
}},
|
||
|
||
// Vue 3 v-model changes
|
||
{ from: /v-model="([^"]+)"\s+:value="([^"]+)"/g, to: 'v-model="$1"' },
|
||
|
||
// Vue 3 lifecycle hooks
|
||
{ from: /beforeDestroy\s*\(/g, to: "beforeUnmount(" },
|
||
{ from: /destroyed\s*\(/g, to: "unmounted(" },
|
||
|
||
// Vue Router changes
|
||
{ from: /this\.\$router\.currentRoute\b/g, to: "this.$router.currentRoute.value" },
|
||
{ from: /router\.currentRoute\b/g, to: "router.currentRoute.value" },
|
||
];
|
||
|
||
// Function to update a single file
|
||
function updateFile(filePath) {
|
||
console.log(`Updating: ${filePath}`);
|
||
|
||
let content = fs.readFileSync(filePath, 'utf8');
|
||
let hasChanges = false;
|
||
|
||
// Apply migration patterns
|
||
migrationPatterns.forEach(pattern => {
|
||
if (typeof pattern.to === 'string') {
|
||
const newContent = content.replace(pattern.from, pattern.to);
|
||
if (newContent !== content) {
|
||
hasChanges = true;
|
||
content = newContent;
|
||
}
|
||
} else if (typeof pattern.to === 'function') {
|
||
content = content.replace(pattern.from, pattern.to);
|
||
}
|
||
});
|
||
|
||
// Add getCurrentInstance import if using this.$root
|
||
if (content.includes('this.$root') && !content.includes('getCurrentInstance')) {
|
||
content = content.replace(
|
||
/import\s+{([^}]+)}\s+from\s+['"]vue['"]/,
|
||
"import { $1, getCurrentInstance } from 'vue'"
|
||
);
|
||
if (!content.includes("import { getCurrentInstance } from 'vue'")) {
|
||
content = "import { getCurrentInstance } from 'vue'\n" + content;
|
||
}
|
||
hasChanges = true;
|
||
}
|
||
|
||
// Update global properties access
|
||
if (content.includes('this.$') && !content.includes('globalProperties')) {
|
||
// Add setup() if not exists
|
||
if (!content.includes('setup()')) {
|
||
const exportDefaultMatch = content.match(/export\s+default\s*{/);
|
||
if (exportDefaultMatch) {
|
||
const insertIndex = exportDefaultMatch.index + exportDefaultMatch[0].length;
|
||
content = content.slice(0, insertIndex) +
|
||
"\n setup() {\n const instance = getCurrentInstance()\n const globalProperties = instance?.appContext.config.globalProperties\n \n return {\n globalProperties\n }\n }," +
|
||
content.slice(insertIndex);
|
||
hasChanges = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (hasChanges) {
|
||
fs.writeFileSync(filePath, content);
|
||
console.log(`✓ Updated: ${filePath}`);
|
||
} else {
|
||
console.log(`- No changes needed: ${filePath}`);
|
||
}
|
||
}
|
||
|
||
// Main function
|
||
function main() {
|
||
const viewPath = path.join(__dirname, 'src/view');
|
||
const componentPath = path.join(__dirname, 'src/components');
|
||
|
||
// Find all .vue files
|
||
const vueFiles = [
|
||
...glob.sync(path.join(viewPath, '**/*.vue')),
|
||
...glob.sync(path.join(componentPath, '**/*.vue'))
|
||
];
|
||
|
||
console.log(`Found ${vueFiles.length} Vue files to update\n`);
|
||
|
||
// Update each file
|
||
vueFiles.forEach(updateFile);
|
||
|
||
console.log('\n✅ Migration script completed!');
|
||
console.log('\n⚠️ Please review the following:');
|
||
console.log('1. Filters need to be manually converted to methods or computed properties');
|
||
console.log('2. Complex v-model usage may need manual adjustment');
|
||
console.log('3. Test all components after migration');
|
||
console.log('4. Run npm install to install new dependencies');
|
||
}
|
||
|
||
// Run the script
|
||
main(); |