|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * This AI-generated script copies workspace plugin dist folders to the dist/plugins directory |
| 5 | + * to ensure they're available for dynamic imports in production. |
| 6 | + */ |
| 7 | +import { execSync } from 'child_process'; |
| 8 | +import fs from 'fs'; |
| 9 | +import path from 'path'; |
| 10 | +import { fileURLToPath } from 'url'; |
| 11 | + |
| 12 | +const __filename = fileURLToPath(import.meta.url); |
| 13 | +const __dirname = path.dirname(__filename); |
| 14 | + |
| 15 | +// Get the package.json to find workspace dependencies |
| 16 | +const packageJsonPath = path.resolve(__dirname, '../package.json'); |
| 17 | +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 18 | + |
| 19 | +// Create the plugins directory if it doesn't exist |
| 20 | +const pluginsDir = path.resolve(__dirname, '../dist/plugins'); |
| 21 | +if (!fs.existsSync(pluginsDir)) { |
| 22 | + fs.mkdirSync(pluginsDir, { recursive: true }); |
| 23 | +} |
| 24 | + |
| 25 | +// Find all workspace plugins |
| 26 | +const pluginPrefix = 'unraid-api-plugin-'; |
| 27 | +const workspacePlugins = Object.keys(packageJson.peerDependencies || {}).filter((pkgName) => |
| 28 | + pkgName.startsWith(pluginPrefix) |
| 29 | +); |
| 30 | + |
| 31 | +// Copy each plugin's dist folder to the plugins directory |
| 32 | +for (const pkgName of workspacePlugins) { |
| 33 | + const pluginPath = path.resolve(__dirname, `../../packages/${pkgName}`); |
| 34 | + const pluginDistPath = path.resolve(pluginPath, 'dist'); |
| 35 | + const targetPath = path.resolve(pluginsDir, pkgName); |
| 36 | + |
| 37 | + console.log(`Building ${pkgName}...`); |
| 38 | + try { |
| 39 | + execSync('pnpm build', { |
| 40 | + cwd: pluginPath, |
| 41 | + stdio: 'inherit', |
| 42 | + }); |
| 43 | + console.log(`Successfully built ${pkgName}`); |
| 44 | + } catch (error) { |
| 45 | + console.error(`Failed to build ${pkgName}:`, error.message); |
| 46 | + process.exit(1); |
| 47 | + } |
| 48 | + |
| 49 | + if (!fs.existsSync(pluginDistPath)) { |
| 50 | + console.warn(`Plugin ${pkgName} dist folder not found at ${pluginDistPath}`); |
| 51 | + process.exit(1); |
| 52 | + } |
| 53 | + console.log(`Copying ${pkgName} dist folder to ${targetPath}`); |
| 54 | + fs.mkdirSync(targetPath, { recursive: true }); |
| 55 | + fs.cpSync(pluginDistPath, targetPath, { recursive: true }); |
| 56 | + console.log(`Successfully copied ${pkgName} dist folder`); |
| 57 | +} |
| 58 | + |
| 59 | +console.log('Plugin dist folders copied successfully'); |
0 commit comments