|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2025, Optimizely |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * Platform validator CLI |
| 21 | + * |
| 22 | + * Provides a unified interface for validating and fixing platform isolation issues. |
| 23 | + * |
| 24 | + * Usage: |
| 25 | + * node platform-validator.js --validate # Validate platform isolation (default) |
| 26 | + * node platform-validator.js --fix # Fix platform isolation issues |
| 27 | + */ |
| 28 | + |
| 29 | +/* eslint-disable @typescript-eslint/no-var-requires */ |
| 30 | +const { execSync } = require('child_process'); |
| 31 | + |
| 32 | +function main() { |
| 33 | + const args = process.argv.slice(2); |
| 34 | + |
| 35 | + const hasValidate = args.includes('--validate'); |
| 36 | + const hasFix = args.includes('--fix'); |
| 37 | + |
| 38 | + // Check if both options are provided |
| 39 | + if (hasValidate && hasFix) { |
| 40 | + console.error('❌ Error: Cannot specify both --validate and --fix options'); |
| 41 | + process.exit(1); |
| 42 | + } |
| 43 | + |
| 44 | + // Determine which script to run (default to validate) |
| 45 | + const shouldFix = hasFix; |
| 46 | + |
| 47 | + try { |
| 48 | + if (shouldFix) { |
| 49 | + console.log('🔧 Running platform isolation fix...\n'); |
| 50 | + execSync('node scripts/add-platform-exports.js', { stdio: 'inherit' }); |
| 51 | + } else { |
| 52 | + console.log('🔍 Running platform isolation validation...\n'); |
| 53 | + execSync('node scripts/validate-platform-isolation.js', { stdio: 'inherit' }); |
| 54 | + } |
| 55 | + } catch (error) { |
| 56 | + process.exit(error.status || 1); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +if (require.main === module) { |
| 61 | + main(); |
| 62 | +} |
| 63 | + |
| 64 | +module.exports = { main }; |
0 commit comments