Files
light_preset_manager/frontend/scripts/copy.js
T

39 lines
1.4 KiB
JavaScript

// =============================================================================
// COPY SCRIPT
// =============================================================================
// Copies the built JS file to all required locations:
// 1. custom_components/.../frontend/ → For HACS distribution
// 2. ha-dev-config/www/ → For local development testing
const fs = require('fs');
const path = require('path');
// Source: where esbuild outputs the compiled file
const SOURCE = path.resolve(__dirname, '../dist/light-preset-manager.js');
// Targets: where we need to copy the file
const TARGETS = [
// Production location (HACS will use this)
path.resolve(__dirname, '../../custom_components/light_preset_manager/frontend/light-preset-manager.js'),
// Development location (served at /local/ by HA)
path.resolve(__dirname, '../../ha-dev-config/www/light-preset-manager.js'),
];
// Ensure each target directory exists, then copy
for (const target of TARGETS) {
const dir = path.dirname(target);
// Create directory if it doesn't exist
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
console.log(`📁 Created directory: ${dir}`);
}
// Copy the file
try {
fs.copyFileSync(SOURCE, target);
console.log(`✅ Copied to: ${path.relative(process.cwd(), target)}`);
} catch (err) {
console.error(`❌ Failed: ${err.message}`);
}
}