power-flux-card/build.js

79 lines
2.3 KiB
JavaScript
Raw Normal View History

2026-02-07 12:12:01 +01:00
const fs = require('fs');
const path = require('path');
const SRC_DIR = 'src';
const DIST_DIR = 'dist';
const OUTPUT_FILE = path.join(DIST_DIR, 'power-flux-card.js');
// Ensure dist dir exists
2026-02-17 23:01:12 +01:00
if (!fs.existsSync(DIST_DIR)) {
2026-02-07 12:12:01 +01:00
fs.mkdirSync(DIST_DIR);
}
// Process Languages
console.log('Processing languages...');
const langFiles = fs.readdirSync(SRC_DIR).filter(file => file.startsWith('lang-') && file.endsWith('.js'));
let langsScript = '';
2026-02-07 12:51:57 +01:00
// We will construct the translation objects
let langDefinitions = '';
let mergeScript = `
const editorTranslations = {};
const cardTranslations = {};
`;
2026-02-07 12:12:01 +01:00
langFiles.forEach(file => {
const langCode = file.replace('lang-', '').replace('.js', '');
2026-02-17 23:01:12 +01:00
2026-02-07 12:12:01 +01:00
let content = fs.readFileSync(path.join(SRC_DIR, file), 'utf8');
2026-02-07 12:51:57 +01:00
// Remove export default
2026-02-07 12:12:01 +01:00
content = content.replace('export default', '').trim();
if (content.endsWith(';')) {
content = content.slice(0, -1);
}
2026-02-17 23:01:12 +01:00
2026-02-07 12:51:57 +01:00
// Assign to a variable
langDefinitions += `const lang_${langCode} = ${content};\n`;
2026-02-17 23:01:12 +01:00
2026-02-07 12:51:57 +01:00
// Add to merge logic
mergeScript += `editorTranslations['${langCode}'] = lang_${langCode}.editor;\n`;
mergeScript += `cardTranslations['${langCode}'] = lang_${langCode}.card;\n`;
2026-02-07 12:12:01 +01:00
});
2026-02-07 12:51:57 +01:00
langsScript = langDefinitions + mergeScript;
const imagesScript = '';
2026-02-07 12:12:01 +01:00
// Process Editor
console.log('Processing editor...');
let editorContent = fs.readFileSync(path.join(SRC_DIR, 'power-flux-card-editor.js'), 'utf8');
2026-02-07 12:51:57 +01:00
// Remove imports/exports if any
editorContent = editorContent.replace(/import .* from .*/g, '').replace(/export .*/g, '');
2026-02-17 23:22:08 +01:00
// Remove editorTranslations/cardTranslations declarations (already created by build merge script)
editorContent = editorContent.replace(/const editorTranslations\s*=\s*\{[^}]*\};/gs, '');
editorContent = editorContent.replace(/const cardTranslations\s*=\s*\{[^}]*\};/gs, '');
2026-02-07 12:12:01 +01:00
// Process Main Card
console.log('Processing main card...');
let mainContent = fs.readFileSync(path.join(SRC_DIR, 'power-flux-card.js'), 'utf8');
// Remove imports
mainContent = mainContent.replace(/import .* from .*/g, '');
// 5. Combine everything
console.log('Writing output...');
const finalContent = `
/**
* Power Flux Card (Bundled)
* Generated by build.js
*/
${langsScript}
${imagesScript}
${editorContent}
${mainContent}
`;
fs.writeFileSync(OUTPUT_FILE, finalContent);
console.log(`Build complete: ${OUTPUT_FILE}`);