(extensions: ParsedExtension[], dryRun: boolean = true)
| 141 | } |
| 142 | |
| 143 | async function importToConvex(extensions: ParsedExtension[], dryRun: boolean = true) { |
| 144 | if (dryRun) { |
| 145 | console.log("\n=== DRY RUN MODE ===") |
| 146 | console.log("No data will be imported. Remove --dry-run flag to actually import.\n") |
| 147 | } |
| 148 | |
| 149 | const convexUrl = process.env.NEXT_PUBLIC_CONVEX_URL |
| 150 | if (!convexUrl && !dryRun) { |
| 151 | throw new Error("NEXT_PUBLIC_CONVEX_URL environment variable is required") |
| 152 | } |
| 153 | |
| 154 | const client = convexUrl ? new ConvexHttpClient(convexUrl) : null |
| 155 | |
| 156 | console.log(`\nFound ${extensions.length} extensions to import:\n`) |
| 157 | |
| 158 | const byCategory: Record<string, ParsedExtension[]> = {} |
| 159 | for (const ext of extensions) { |
| 160 | if (!byCategory[ext.category]) byCategory[ext.category] = [] |
| 161 | byCategory[ext.category].push(ext) |
| 162 | } |
| 163 | |
| 164 | for (const [category, exts] of Object.entries(byCategory)) { |
| 165 | console.log(`\n${category.toUpperCase()} (${exts.length}):`) |
| 166 | for (const ext of exts) { |
| 167 | const productId = generateProductId(ext.name) |
| 168 | const type = CATEGORY_TO_TYPE[category] || "plugin" |
| 169 | |
| 170 | console.log(` - ${ext.name}`) |
| 171 | console.log(` productId: ${productId}`) |
| 172 | console.log(` type: ${type}`) |
| 173 | console.log(` url: ${ext.url}`) |
| 174 | console.log(` description: ${ext.description.slice(0, 80)}...`) |
| 175 | |
| 176 | if (!dryRun && client) { |
| 177 | try { |
| 178 | // Check if already exists |
| 179 | const existing = await client.query(api.extensions.getByProductId, { productId }) |
| 180 | if (existing) { |
| 181 | console.log(` ⏭️ Already exists, skipping`) |
| 182 | continue |
| 183 | } |
| 184 | |
| 185 | // Note: We can't directly call submit mutation without auth |
| 186 | // This would need to be done via admin API or internal mutation |
| 187 | console.log(` ⚠️ Would need admin API to import`) |
| 188 | } catch (error) { |
| 189 | console.log(` ❌ Error: ${error}`) |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return extensions |
| 196 | } |
| 197 | |
| 198 | async function main() { |
| 199 | const args = process.argv.slice(2) |
no test coverage detected