@react-native-vector-icons/common
Version:
Customizable Icons for React Native with support for image source and full styling.
52 lines (48 loc) • 2.57 kB
JavaScript
;
var _nodeFs = _interopRequireDefault(require("node:fs"));
var path = _interopRequireWildcard(require("node:path"));
var _picocolors = _interopRequireDefault(require("picocolors"));
var plist = _interopRequireWildcard(require("plist"));
var _common = require("./common.js");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const getFontName = fontPath => path.basename(fontPath);
const packageJsonFilename = process.argv[2];
if (!packageJsonFilename) {
throw new Error('Need the path to the root package.json as the first argument');
}
const infoPlistFilename = process.argv[3];
if (!infoPlistFilename) {
throw new Error('Need the path to the Info.plist as the second argument');
}
const fonts = (0, _common.getFontPaths)(packageJsonFilename);
console.log(`Found ${fonts.length} fonts`);
const infoPlistContent = _nodeFs.default.readFileSync(infoPlistFilename, 'utf8');
const infoPlist = plist.parse(infoPlistContent);
const plistFonts = new Set(infoPlist.UIAppFonts || []);
const providedFonts = new Set(fonts.map(getFontName));
let hasChanges = false;
// Check for missing fonts and add them
providedFonts.forEach(font => {
if (!plistFonts.has(font)) {
plistFonts.add(font);
console.log(_picocolors.default.green(`Added ${font}`));
hasChanges = true;
} else {
console.log(`Existing ${font}`);
}
});
// Check for extra fonts in Info.plist
plistFonts.forEach(font => {
if (!providedFonts.has(font)) {
console.log(_picocolors.default.yellow(`Extra ${font} (Please remove manually if not needed)`));
}
});
// Update Info.plist if there were changes
if (hasChanges) {
infoPlist.UIAppFonts = Array.from(plistFonts);
const updatedInfoPlistContent = plist.build(infoPlist).replace(/^ {2}/gm, '').replace(/ {2}/gm, '\t');
_nodeFs.default.writeFileSync(infoPlistFilename, updatedInfoPlistContent, 'utf8');
}
//# sourceMappingURL=updatePlist.js.map