UNPKG

@bacons/apple-targets

Version:
45 lines (44 loc) 2.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withIosSymbolset = exports.isSFSymbolContent = void 0; const config_plugins_1 = require("expo/config-plugins"); const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); /** * Check if SVG content is an SF Symbol template by looking for the * characteristic `<g id="Symbols">` group that all SF Symbol templates contain. */ function isSFSymbolContent(content) { // SF Symbol templates always have a <g id="Symbols"> group containing // weight/size variant groups like "Regular-S", "Regular-M", "Regular-L". return /\bid="Symbols"/.test(content) && /\bid="Regular-S"/.test(content); } exports.isSFSymbolContent = isSFSymbolContent; const withIosSymbolset = (config, { cwd, name, svgContent, svgFilename }) => { return (0, config_plugins_1.withDangerousMod)(config, [ "ios", async (config) => { const projectRoot = config.modRequest.projectRoot; const symbolsetDir = node_path_1.default.join(projectRoot, cwd, `Assets.xcassets/${name}.symbolset`); await node_fs_1.default.promises.mkdir(symbolsetDir, { recursive: true }); await node_fs_1.default.promises.writeFile(node_path_1.default.join(symbolsetDir, svgFilename), svgContent); await node_fs_1.default.promises.writeFile(node_path_1.default.join(symbolsetDir, "Contents.json"), JSON.stringify({ info: { author: "expo", version: 1, }, symbols: [ { filename: svgFilename, idiom: "universal", }, ], }, null, 2)); return config; }, ]); }; exports.withIosSymbolset = withIosSymbolset;