diff --git a/build.js b/build.js index 758fe82..f8bab3f 100644 --- a/build.js +++ b/build.js @@ -18,6 +18,15 @@ const removeDirs = (base, filterFn) => { } }; +const deleteFiles = (basePath, filenames) => { + filenames.forEach(filename => { + const filePath = path.join(basePath, filename); + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); + } + }); +}; + try { console.log(' Building Moonfin for webOS...\n'); @@ -43,6 +52,50 @@ try { const localeDir = path.join('dist', 'node_modules', 'ilib', 'locale'); removeDirs(localeDir, (name) => !name.startsWith('en')); + // Root-level files: phone, currency, unit, address, astronomy data + console.log('\n Removing unused ilib data files...'); + const nonEngLocalefiles = ([ + 'currency.json', + 'numplan.json', + 'emergency.json', + 'unitfmt.json', + 'phoneloc.json', + 'phonefmt.json', + 'iddarea.json', + 'idd.json', + 'mnc.json', + 'address.json', + 'addressres.json', + 'astro.json', + 'pseudomap.json', + 'collation.json', + 'countries.json', + 'nativecountries.json', + 'ctrynames.json', + 'ctryreverse.json', + 'name.json', + 'lang2charset.json', + 'ccc.json' + ]); + deleteFiles(path.join('dist', 'node_modules', 'ilib', 'locale'), nonEngLocalefiles); + + // Remove Deseret script locale (historic/obsolete) + fs.rmSync(path.join('dist', 'node_modules', 'ilib', 'locale', 'en', 'Dsrt'), {recursive: true, force: true}); + + // Strip bulky files from en/ regional subdirs (keep only sysres, dateformats, list, localeinfo, plurals) + console.log('\n Removing non-essential files from en/ regional locale dirs...'); + deleteFiles(path.join('dist', 'node_modules', 'ilib', 'locale', 'en'), nonEngLocalefiles); + + // Remove unused font weights to reduce size + console.log('\n Removing unused font weights...'); + const fontFiles = ([ + 'MuseoSans-Thin.ttf', + 'MuseoSans-BlackItalic.ttf', + 'MuseoSans-BoldItalic.ttf', + 'MuseoSans-MediumItalic.ttf' + ]); + deleteFiles(path.join('dist', 'node_modules', '@enact', 'sandstone', 'fonts', 'MuseoSans'), fontFiles); + // Package into IPK console.log('\n Creating IPK package...'); fs.mkdirSync('build', {recursive: true});