var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try {
            step(generator.next(value));
        }
        catch (e) {
            reject(e);
        } }
        function rejected(value) { try {
            step(generator["throw"](value));
        }
        catch (e) {
            reject(e);
        } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
const fs = require('fs');
const fsPromises = require('fs').promises;
function toCamelCase(text) {
    return text.replace(/-\w/g, clearAndUpper);
}
function toPascalCase(text) {
    return text.replace(/(^\w|-\w)/g, clearAndUpper);
}
function clearAndUpper(text) {
    return text.replace(/-/, '').toUpperCase();
}
const buildIconLibrary = () => {
    let files = fs.readdirSync('./src/assets/icons');
    let flagFiles = fs.readdirSync('./src/assets/icons/flags');
    let importString = '';
    let objString = `export const Icons = {`;
    for (const fileName of files) {
        if (!fileName.includes('.svg')) {
            continue;
        }
        const fileNameNoExt = fileName.split('.')[0];
        const camelCaseFileName = toCamelCase(fileNameNoExt);
        const pascalCaseFileName = toPascalCase(fileNameNoExt);
        importString += `import ${pascalCaseFileName} from './${fileName}';\n`;
        objString += `\n  ${camelCaseFileName}: ${pascalCaseFileName},`;
    }
    for (const fileName of flagFiles) {
        if (!fileName.includes('.svg')) {
            continue;
        }
        const fileNameNoExt = fileName.split('.')[0];
        const camelCaseFileName = toCamelCase(fileNameNoExt);
        const pascalCaseFileName = toPascalCase(fileNameNoExt);
        importString += `import ${pascalCaseFileName} from './flags/${fileName}';\n`;
        objString += `\n  ${camelCaseFileName}: ${pascalCaseFileName},`;
    }
    const codeStr = `${importString}\n${objString}\n};\n`;
    fs.writeFile('./src/assets/icons/index.ts', codeStr, 'utf8', err => {
        if (err) {
            console.error(err);
        }
    });
};
const buildImages = () => __awaiter(void 0, void 0, void 0, function* () {
    const files = fs.readdirSync('./src/assets/images');
    let objString = 'export const Images = {\n';
    for (let i = 0; i < files.length; i++) {
        const fileName = files[i];
        if (!fileName.includes('png') && !fileName.includes('jpg') && !fileName.includes('jpeg')) {
            continue;
        }
        const content = yield fsPromises.readFile(`./src/assets/images/${fileName}`, { encoding: 'base64' });
        const fileNameSplit = fileName.split('.');
        const ext = fileNameSplit[1];
        const fileNameNoExt = fileNameSplit[0];
        const camelCaseFileName = toCamelCase(fileNameNoExt);
        const dataUrl = `data:image/${ext};base64,${content}`;
        objString += `  ${camelCaseFileName}:\n    '${dataUrl}',\n`;
    }
    fs.writeFile('./src/assets/images/index.ts', `${objString}};\n`, 'utf8', err => {
        if (err) {
            console.error(err);
        }
    });
});
const main = () => {
    buildIconLibrary();
    buildImages();
};
main();
//# sourceMappingURL=buildAssets.js.map
