build-plugin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env node
  2. import fs from 'fs';
  3. import path from 'path';
  4. import process from 'process';
  5. import { fileURLToPath } from 'url';
  6. /**
  7. * Build script for the dashboard plugin
  8. * Copies package.json from plugin source to dist/plugin output directory
  9. */
  10. const __filename = fileURLToPath(import.meta.url);
  11. const __dirname = path.dirname(__filename);
  12. const sourcePackageJson = path.join(__dirname, '../plugin/package.json');
  13. const sourceHtmlFile = path.join(__dirname, '../plugin/default-page.html');
  14. const outputDir = path.join(__dirname, '../dist/plugin');
  15. const outputPackageJson = path.join(outputDir, 'package.json');
  16. const outputHtmlFile = path.join(outputDir, 'default-page.html');
  17. try {
  18. // Ensure output directory exists
  19. if (!fs.existsSync(outputDir)) {
  20. fs.mkdirSync(outputDir, { recursive: true });
  21. console.log(`Created output directory: ${outputDir}`);
  22. }
  23. // Copy package.json
  24. if (fs.existsSync(sourcePackageJson)) {
  25. fs.copyFileSync(sourcePackageJson, outputPackageJson);
  26. console.log(`Copied package.json from ${sourcePackageJson} to ${outputPackageJson}`);
  27. } else {
  28. console.error(`Source package.json not found at: ${sourcePackageJson}`);
  29. process.exit(1);
  30. }
  31. // Copy default-page.html
  32. if (fs.existsSync(sourceHtmlFile)) {
  33. fs.copyFileSync(sourceHtmlFile, outputHtmlFile);
  34. console.log(`Copied default-page.html from ${sourceHtmlFile} to ${outputHtmlFile}`);
  35. } else {
  36. console.error(`Source default-page.html not found at: ${sourceHtmlFile}`);
  37. process.exit(1);
  38. }
  39. console.log('Plugin build completed successfully');
  40. } catch (error) {
  41. console.error('Plugin build failed:', error.message);
  42. process.exit(1);
  43. }