* Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
*/
import fs from 'fs';
const dist = './dist/index.html';
const html = fs.readFileSync(dist, 'utf-8');
let result = '<!doctype html>';
const htmlArrs = html.match(/<\/?[a-zA-Z]+(?:[^>]*)?(?:>|$)/g) || [];
htmlArrs.forEach(string => {
string = string.replace(/\s?nomodule\s?/g, ' ');
string = string.replace(/\s?crossorigin\s?/g, ' ');
string = string.replace(/data-src/g, 'src');
string = string.replace(/\s?type="module"/g, '');
string = string.replace(/System.import\(([\s\S]{0,50})getAttribute\(([\s\S]{0,50})\)\)/g, '');
result += string;
});
result = result.replace('<title></title>', '<title>Scalar</title>');
fs.writeFileSync(dist, result, 'utf-8');
console.log('build end');