extract-vscode-variables.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env node
  2. /**
  3. * VS Code theme extraction using Playwright
  4. * Extracts comprehensive CSS variables from running VS Code instance
  5. * Replaces the old theme generation script with complete variable extraction
  6. */
  7. import { execSync } from "child_process"
  8. import fs from "fs"
  9. import path from "path"
  10. import { fileURLToPath } from "url"
  11. const __filename = fileURLToPath(import.meta.url)
  12. const __dirname = path.dirname(__filename)
  13. const PLAYWRIGHT_E2E_DIR = path.resolve(__dirname, "..")
  14. const STORYBOOK_OUTPUT_DIR = path.resolve(__dirname, "../../storybook/generated-theme-styles")
  15. async function extractThemeVariables() {
  16. console.log("🎨 Extracting VS Code themes using Playwright...\n")
  17. try {
  18. // Run the Playwright extraction test
  19. console.log("🚀 Running Playwright CSS extraction...")
  20. const playwrightCommand = `cd "${PLAYWRIGHT_E2E_DIR}" && npx playwright test --config=scripts/theme-extraction.config.ts --reporter=line`
  21. execSync(playwrightCommand, { stdio: "inherit", cwd: PLAYWRIGHT_E2E_DIR })
  22. // Verify the files were created directly in the storybook directory
  23. const darkOutputPath = path.join(STORYBOOK_OUTPUT_DIR, "dark-modern.css")
  24. const lightOutputPath = path.join(STORYBOOK_OUTPUT_DIR, "light-modern.css")
  25. if (!fs.existsSync(darkOutputPath) || !fs.existsSync(lightOutputPath)) {
  26. throw new Error("Playwright extraction failed - CSS files not found in storybook directory")
  27. }
  28. console.log(`✅ Generated dark-modern.css`)
  29. console.log(`✅ Generated light-modern.css`)
  30. console.log(`\n🎉 Theme extraction complete! Files saved to ${STORYBOOK_OUTPUT_DIR}`)
  31. } catch (error) {
  32. console.error("❌ Theme extraction failed:", error.message)
  33. process.exit(1)
  34. }
  35. }
  36. // Run if called directly
  37. if (import.meta.url === `file://${process.argv[1]}`) {
  38. extractThemeVariables().catch((error) => {
  39. console.error("Fatal error:", error)
  40. process.exit(1)
  41. })
  42. }
  43. export { extractThemeVariables }