2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-04 18:23:17 +00:00

fix(iconify-icon): add iconify-icon to tags list for TypeScript

This commit is contained in:
Vjacheslav Trushkin 2023-01-26 21:13:01 +02:00
parent efb0e57ad3
commit a3732f627a

View File

@ -71,12 +71,57 @@ Object.keys(compile).forEach((key) => {
}
});
/**
* Update types before exit
*/
function updateTypes() {
const filename = 'dist/iconify-icon.d.ts';
const search = 'HTMLElementTagNameMap';
const search2 = 'interface IconifyIconHTMLElement extends';
const code = `
/**
* Add custom element to global elements list
*/
declare global {
interface HTMLElementTagNameMap {
'iconify-icon': IconifyIconHTMLElement;
}
}
`;
let data;
try {
data = fs.readFileSync(filename, 'utf8');
} catch {
// Missing
if (compile.api) {
throw new Error('Cannot clean up types file');
}
return;
}
// Check if code already exists
if (data.indexOf(search) !== -1) {
return;
}
// Check if required type exists
if (data.indexOf(search2) === -1) {
throw new Error('Cannot find required interface');
}
// Add code
fs.writeFileSync(filename, data + code, 'utf8');
console.log('Updated', filename);
}
/**
* Run next command
*/
const next = () => {
const item = commands.shift();
if (item === void 0) {
updateTypes();
process.exit(0);
}