Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

withWidgetLogoAsset.cjs

68 lines2.6 KB

1"use strict";
2​
3// Ships the branded T3 mark to the Live Activity / widget extension.
4//
5// expo-widgets generates ExpoWidgetsTarget without a Resources build phase and
6// has no asset support, so this plugin (a) writes an SVG template image set into
7// the generated widget asset catalog and (b) wires that catalog into the widget
8// target with an actool build phase.
9//
10// ORDERING: must be listed BEFORE "expo-widgets" in the plugins array. Expo
11// chains same-type mods so the last-registered runs FIRST; registering this
12// plugin earlier makes its mods run AFTER expo-widgets' mods. That matters
13// twice: expo-widgets' dangerous mod rmSync's ios/ExpoWidgetsTarget/ (deleting
14// any catalog written before it), and its xcodeproj mod is what creates the
15// widget target. Listed after expo-widgets, both steps silently no-op on a
16// fresh prebuild — which is how prod build 8 shipped without the logo.
17​
18const path = require("path");
19const fs = require("fs");
20const { withDangerousMod, withXcodeProject } = require("expo/config-plugins");
21const { addWidgetAssetCatalog } = require("./lib/addWidgetAssetCatalog.cjs");
22​
23const TARGET_NAME = "ExpoWidgetsTarget";
24const CATALOG_NAME = "Assets.xcassets";
25const IMAGE_SET = "T3Mark.imageset";
26const SVG_NAME = "T3Mark.svg";
27​
28const CATALOG_CONTENTS = JSON.stringify({ info: { author: "expo", version: 1 } }, null, 2) + "\n";
29const IMAGE_SET_CONTENTS =
30 JSON.stringify(
31 {
32 images: [{ idiom: "universal", filename: SVG_NAME }],
33 info: { author: "expo", version: 1 },
34 properties: {
35 "preserves-vector-representation": true,
36 "template-rendering-intent": "template",
37 },
38 },
39 null,
40 2,
41 ) + "\n";
42​
43function withAssetFiles(config) {
44 return withDangerousMod(config, [
45 "ios",
46 (cfg) => {
47 const source = path.join(cfg.modRequest.projectRoot, "assets", "widget", SVG_NAME);
48 const catalogDir = path.join(cfg.modRequest.platformProjectRoot, TARGET_NAME, CATALOG_NAME);
49 const imageSetDir = path.join(catalogDir, IMAGE_SET);
50 fs.mkdirSync(imageSetDir, { recursive: true });
51 fs.writeFileSync(path.join(catalogDir, "Contents.json"), CATALOG_CONTENTS);
52 fs.writeFileSync(path.join(imageSetDir, "Contents.json"), IMAGE_SET_CONTENTS);
53 fs.copyFileSync(source, path.join(imageSetDir, SVG_NAME));
54 return cfg;
55 },
56 ]);
58​
59function withAssetWiring(config) {
60 return withXcodeProject(config, (cfg) => {
61 addWidgetAssetCatalog(cfg.modResults, { targetName: TARGET_NAME });
62 return cfg;
63 });
65​
66module.exports = function withWidgetLogoAsset(config) {
67 return withAssetWiring(withAssetFiles(config));
68};