app-icon-badge-next 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +264 -0
- package/app.plugin.js +1 -0
- package/dist/app.plugin.js +268 -0
- package/dist/assets/banner-overlay-adaptive.png +0 -0
- package/dist/assets/banner-overlay.png +0 -0
- package/dist/assets/fonts/open-sans-128-black.fnt +297 -0
- package/dist/assets/fonts/open-sans-128-black.png +0 -0
- package/dist/assets/fonts/open-sans-128-white.fnt +297 -0
- package/dist/assets/fonts/open-sans-128-white.png +0 -0
- package/dist/assets/fonts/open-sans-64-black.fnt +297 -0
- package/dist/assets/fonts/open-sans-64-black.png +0 -0
- package/dist/assets/fonts/open-sans-64-white.fnt +297 -0
- package/dist/assets/fonts/open-sans-64-white.png +0 -0
- package/dist/assets/ribbon-overlay-adaptive.png +0 -0
- package/dist/assets/ribbon-overlay.png +0 -0
- package/dist/cli.js +292 -0
- package/dist/generate.js +298 -0
- package/dist/index.d.mts +53 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +252 -0
- package/dist/index.mjs +217 -0
- package/package.json +82 -0
- package/types.ts +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AdzeB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<h1 align="center">App Icon Badge Next</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
Production-ready app icon badging for modern Expo and React Native workflows.
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/AdzeB/app-icon-badge-next"><img src="https://img.shields.io/badge/repo-AdzeB%2Fapp--icon--badge--next-181717?style=flat-square&logo=github" alt="repo"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/app-icon-badge-next"><img src="https://img.shields.io/npm/v/app-icon-badge-next.svg?style=flat-square" alt="npm version"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/app-icon-badge-next"><img src="https://img.shields.io/npm/dm/app-icon-badge-next.svg?style=flat-square" alt="npm downloads"></a>
|
|
11
|
+
<a href="https://github.com/AdzeB/app-icon-badge-next/blob/main/LICENSE"><img src="https://img.shields.io/github/license/AdzeB/app-icon-badge-next?style=flat-square" alt="license"></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://github.com/AdzeB/app-icon-badge-next/stargazers"><img src="https://img.shields.io/github/stars/AdzeB/app-icon-badge-next?style=social" alt="stars"></a>
|
|
16
|
+
<a href="https://github.com/AdzeB/app-icon-badge-next/network/members"><img src="https://img.shields.io/github/forks/AdzeB/app-icon-badge-next?style=social" alt="forks"></a>
|
|
17
|
+
<a href="https://github.com/AdzeB/app-icon-badge-next/issues"><img src="https://img.shields.io/github/issues/AdzeB/app-icon-badge-next?style=social" alt="issues"></a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## About
|
|
23
|
+
|
|
24
|
+
`app-icon-badge-next` is the production-ready successor to [`app-icon-badge`](https://github.com/obytes/app-icon-badge), focused on reliability in CI/EAS, support for modern Expo icon models, and predictable results across current iOS and Android launcher behavior.
|
|
25
|
+
|
|
26
|
+
## Motivation
|
|
27
|
+
|
|
28
|
+
Mobile teams often install multiple builds of the same app (development, QA, staging, production). When icons look identical, QA and debugging slow down.
|
|
29
|
+
|
|
30
|
+
`app-icon-badge-next` overlays clear environment/version badges on icons so builds are easy to identify at a glance.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- Expo config plugin and library API support.
|
|
35
|
+
- Platform-aware badge configuration:
|
|
36
|
+
- shared `badges`
|
|
37
|
+
- `ios.badges`
|
|
38
|
+
- `android.badges`
|
|
39
|
+
- Android adaptive icon safe-zone support (`adaptiveSafeMode`, `android.safeZoneScale`).
|
|
40
|
+
- Badge text controls: `fontScale`, `padding`, `letterSpacing`, `opacity`.
|
|
41
|
+
- Deterministic cache support to skip unchanged generations.
|
|
42
|
+
- Debug and dry-run modes for safer CI usage.
|
|
43
|
+
- Expo 54+ icon model handling (root icon, Android icon + adaptive foreground, iOS string and object variants).
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# yarn
|
|
49
|
+
yarn add app-icon-badge-next
|
|
50
|
+
|
|
51
|
+
# npm
|
|
52
|
+
npm install app-icon-badge-next
|
|
53
|
+
|
|
54
|
+
# pnpm
|
|
55
|
+
pnpm add app-icon-badge-next
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### Expo Plugin
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// app.config.ts
|
|
64
|
+
import type { ConfigContext, ExpoConfig } from '@expo/config';
|
|
65
|
+
import type { AppIconBadgeConfig } from 'app-icon-badge-next/types';
|
|
66
|
+
|
|
67
|
+
const VERSION = '1.0.1';
|
|
68
|
+
const APP_ENV = 'QA';
|
|
69
|
+
|
|
70
|
+
const appIconBadgeConfig: AppIconBadgeConfig = {
|
|
71
|
+
enabled: true,
|
|
72
|
+
cache: true,
|
|
73
|
+
debug: false,
|
|
74
|
+
dryRun: false,
|
|
75
|
+
adaptiveSafeMode: true,
|
|
76
|
+
badges: [
|
|
77
|
+
{
|
|
78
|
+
text: APP_ENV,
|
|
79
|
+
type: 'banner',
|
|
80
|
+
color: 'white',
|
|
81
|
+
background: '#FF0000',
|
|
82
|
+
fontScale: 1,
|
|
83
|
+
padding: 0,
|
|
84
|
+
letterSpacing: 0,
|
|
85
|
+
opacity: 1,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
ios: {
|
|
89
|
+
badges: [
|
|
90
|
+
{ text: VERSION, type: 'ribbon', position: 'right' },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
android: {
|
|
94
|
+
safeZoneScale: 0.72,
|
|
95
|
+
badges: [
|
|
96
|
+
{ text: VERSION, type: 'ribbon', position: 'right' },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default ({ config }: ConfigContext): ExpoConfig => ({
|
|
102
|
+
...config,
|
|
103
|
+
name: 'my-app',
|
|
104
|
+
icon: './assets/icon.png',
|
|
105
|
+
android: {
|
|
106
|
+
icon: './assets/icon-android.png',
|
|
107
|
+
adaptiveIcon: {
|
|
108
|
+
foregroundImage: './assets/adaptive-icon.png',
|
|
109
|
+
backgroundColor: '#FFFFFF',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
plugins: [['app-icon-badge-next', appIconBadgeConfig]],
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Plugin option summary (defaults in parentheses):
|
|
117
|
+
|
|
118
|
+
- `enabled`: enable or disable generation (`true`).
|
|
119
|
+
- `badges`: shared badge layers for all platforms.
|
|
120
|
+
- `ios.badges`: iOS-only badge layers (falls back to `badges`).
|
|
121
|
+
- `android.badges`: Android-only badge layers (falls back to `badges`).
|
|
122
|
+
- `android.safeZoneScale`: safe-zone scale for adaptive foreground, 0.4-1 (`0.72`).
|
|
123
|
+
- `adaptiveSafeMode`: apply safe-zone transform for adaptive icons (`true`).
|
|
124
|
+
- `cache`: deterministic cache for unchanged inputs (`true`).
|
|
125
|
+
- `debug`: structured debug logs (`false`).
|
|
126
|
+
- `dryRun`: skip file writes (`false`).
|
|
127
|
+
|
|
128
|
+
The plugin rewrites configured icon paths to fixed outputs under `.expo/app-icon-badge` and generates the badged images at that moment (synchronously, before Expo's own icon handling reads them). A deterministic cache keyed on source bytes + badge config makes repeat evaluations no-ops, and the plugin is idempotent when Expo re-applies it to an already rewritten config.
|
|
129
|
+
|
|
130
|
+
Source: <https://github.com/AdzeB/app-icon-badge-next/blob/main/src/plugin/app.plugin.ts>
|
|
131
|
+
|
|
132
|
+
### As a Library
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { addBadge } from 'app-icon-badge-next';
|
|
136
|
+
import path from 'node:path';
|
|
137
|
+
|
|
138
|
+
const icon = path.resolve(__dirname, './assets/icon.png');
|
|
139
|
+
|
|
140
|
+
await addBadge({
|
|
141
|
+
icon,
|
|
142
|
+
dstPath: './assets/icon.environment.png',
|
|
143
|
+
badges: [
|
|
144
|
+
{
|
|
145
|
+
text: 'staging',
|
|
146
|
+
type: 'banner',
|
|
147
|
+
color: 'white',
|
|
148
|
+
background: '#FF0000',
|
|
149
|
+
fontScale: 1,
|
|
150
|
+
padding: 0,
|
|
151
|
+
letterSpacing: 0,
|
|
152
|
+
opacity: 1,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
text: '1.0.1',
|
|
156
|
+
type: 'ribbon',
|
|
157
|
+
position: 'right',
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
isAdaptiveIcon: false,
|
|
161
|
+
adaptiveSafeMode: true,
|
|
162
|
+
safeZoneScale: 0.72,
|
|
163
|
+
debug: false,
|
|
164
|
+
dryRun: false,
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
All options except `icon` and `badges` are optional. Defaults: `isAdaptiveIcon: false`, `adaptiveSafeMode: true`, `safeZoneScale: 0.72`, `debug: false`, `dryRun: false`. Omitting `dstPath` writes next to the source as `<name>.result.<ext>`.
|
|
169
|
+
|
|
170
|
+
## CLI
|
|
171
|
+
|
|
172
|
+
Run the CLI:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
npx app-icon-badge-next --help
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Command help:
|
|
179
|
+
|
|
180
|
+
```text
|
|
181
|
+
Usage: app-icon-badge-next [options] [command]
|
|
182
|
+
|
|
183
|
+
Generate app icons with badges
|
|
184
|
+
|
|
185
|
+
Options:
|
|
186
|
+
-V, --version output the version number
|
|
187
|
+
-h, --help display help for command
|
|
188
|
+
|
|
189
|
+
Commands:
|
|
190
|
+
add-badge [options] <iconPath>
|
|
191
|
+
help [command] display help for command
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`add-badge` options:
|
|
195
|
+
|
|
196
|
+
```text
|
|
197
|
+
Usage: app-icon-badge-next add-badge [options] <iconPath>
|
|
198
|
+
|
|
199
|
+
Options:
|
|
200
|
+
--text <text> badge text
|
|
201
|
+
--type <type> badge type: banner | ribbon
|
|
202
|
+
--position <position> banner: top | bottom, ribbon: left | right
|
|
203
|
+
--background <background> badge background as #rrggbb
|
|
204
|
+
--color <color> badge text color: white | black (default: "white")
|
|
205
|
+
--platform <platform> target platform: ios | android | all (default: "all")
|
|
206
|
+
--preview write result to preview path (default: false)
|
|
207
|
+
--safe-zone enable adaptive safe zone (default: false)
|
|
208
|
+
--scale <scale> safe zone scale (0.4-1) (default: "0.72")
|
|
209
|
+
--dry-run no file write (default: false)
|
|
210
|
+
--debug debug logs (default: false)
|
|
211
|
+
-h, --help display help for command
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Example:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npx app-icon-badge-next add-badge ./assets/icon.png \
|
|
218
|
+
--type banner \
|
|
219
|
+
--text QA \
|
|
220
|
+
--position top \
|
|
221
|
+
--background '#45f4ee' \
|
|
222
|
+
--color black \
|
|
223
|
+
--platform all \
|
|
224
|
+
--safe-zone \
|
|
225
|
+
--scale 0.72
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Contributing
|
|
229
|
+
|
|
230
|
+
Contributions are welcome! See the [contributing guide](./.github/CONTRIBUTING.md) for setup, workflow, and release details.
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
pnpm install # install dependencies
|
|
234
|
+
pnpm type-check # TypeScript type checking
|
|
235
|
+
pnpm build # build dist/
|
|
236
|
+
pnpm test # run tests (requires a prior build)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
- Found a bug or want a feature? [Open an issue](https://github.com/AdzeB/app-icon-badge-next/issues/new/choose).
|
|
240
|
+
- Security issue? Report it privately — see the [security policy](./.github/SECURITY.md).
|
|
241
|
+
- This project follows the [Contributor Covenant Code of Conduct](./.github/CODE_OF_CONDUCT.md).
|
|
242
|
+
|
|
243
|
+
Releases are automated with [Changesets](https://github.com/changesets/changesets); see [CHANGELOG.md](./CHANGELOG.md) for release notes.
|
|
244
|
+
|
|
245
|
+
## Special Thanks and License Attribution
|
|
246
|
+
|
|
247
|
+
Special thanks to the original project and maintainers:
|
|
248
|
+
|
|
249
|
+
- Original library: <https://github.com/obytes/app-icon-badge>
|
|
250
|
+
- Notable upstream fixes and context that influenced this successor:
|
|
251
|
+
- <https://github.com/obytes/app-icon-badge/pull/44>
|
|
252
|
+
- <https://github.com/obytes/app-icon-badge/pull/43>
|
|
253
|
+
- <https://github.com/obytes/app-icon-badge/issues/38>
|
|
254
|
+
- <https://github.com/obytes/app-icon-badge/issues/37>
|
|
255
|
+
|
|
256
|
+
License agreement and attribution:
|
|
257
|
+
|
|
258
|
+
- `app-icon-badge-next` is MIT licensed.
|
|
259
|
+
- The original `obytes/app-icon-badge` project is MIT licensed.
|
|
260
|
+
- This successor preserves attribution to the original work and follows MIT license terms for reuse and distribution.
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
MIT. See [LICENSE](./LICENSE).
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/app.plugin.js').default;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/plugin/app.plugin.ts
|
|
31
|
+
var app_plugin_exports = {};
|
|
32
|
+
__export(app_plugin_exports, {
|
|
33
|
+
default: () => app_plugin_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(app_plugin_exports);
|
|
36
|
+
var import_node_child_process = require("child_process");
|
|
37
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
38
|
+
var import_node_os = __toESM(require("os"));
|
|
39
|
+
var import_node_path3 = __toESM(require("path"));
|
|
40
|
+
var import_zod2 = require("zod");
|
|
41
|
+
|
|
42
|
+
// src/core/validation.ts
|
|
43
|
+
var import_zod = require("zod");
|
|
44
|
+
var hexColor = import_zod.z.string().regex(/^#[0-9a-fA-F]{6}$/);
|
|
45
|
+
var baseBadge = {
|
|
46
|
+
text: import_zod.z.string().min(1),
|
|
47
|
+
color: import_zod.z.enum(["white", "black"]).default("white"),
|
|
48
|
+
background: hexColor.optional(),
|
|
49
|
+
fontScale: import_zod.z.number().min(0.5).max(2).default(1),
|
|
50
|
+
letterSpacing: import_zod.z.number().min(0).max(10).default(0),
|
|
51
|
+
padding: import_zod.z.number().min(0).max(120).default(0),
|
|
52
|
+
opacity: import_zod.z.number().min(0).max(1).default(1)
|
|
53
|
+
};
|
|
54
|
+
var banner = import_zod.z.object({
|
|
55
|
+
type: import_zod.z.literal("banner"),
|
|
56
|
+
position: import_zod.z.enum(["top", "bottom"]).default("bottom"),
|
|
57
|
+
...baseBadge
|
|
58
|
+
});
|
|
59
|
+
var ribbon = import_zod.z.object({
|
|
60
|
+
type: import_zod.z.literal("ribbon"),
|
|
61
|
+
position: import_zod.z.enum(["left", "right"]).default("right"),
|
|
62
|
+
...baseBadge
|
|
63
|
+
});
|
|
64
|
+
var badgeSchema = import_zod.z.discriminatedUnion("type", [banner, ribbon]);
|
|
65
|
+
var addBadgeParamsSchema = import_zod.z.object({
|
|
66
|
+
icon: import_zod.z.string().min(1),
|
|
67
|
+
dstPath: import_zod.z.string().optional(),
|
|
68
|
+
badges: import_zod.z.array(badgeSchema).min(1),
|
|
69
|
+
isAdaptiveIcon: import_zod.z.boolean().default(false),
|
|
70
|
+
adaptiveSafeMode: import_zod.z.boolean().default(true),
|
|
71
|
+
safeZoneScale: import_zod.z.number().min(0.4).max(1).default(0.72),
|
|
72
|
+
debug: import_zod.z.boolean().default(false),
|
|
73
|
+
dryRun: import_zod.z.boolean().default(false)
|
|
74
|
+
});
|
|
75
|
+
var pluginOptionsSchema = import_zod.z.object({
|
|
76
|
+
enabled: import_zod.z.boolean().default(true),
|
|
77
|
+
badges: import_zod.z.array(badgeSchema).optional(),
|
|
78
|
+
ios: import_zod.z.object({ badges: import_zod.z.array(badgeSchema).optional() }).default({}),
|
|
79
|
+
android: import_zod.z.object({
|
|
80
|
+
badges: import_zod.z.array(badgeSchema).optional(),
|
|
81
|
+
safeZoneScale: import_zod.z.number().min(0.4).max(1).default(0.72)
|
|
82
|
+
}).default({}),
|
|
83
|
+
adaptiveSafeMode: import_zod.z.boolean().default(true),
|
|
84
|
+
cache: import_zod.z.boolean().default(true),
|
|
85
|
+
debug: import_zod.z.boolean().default(false),
|
|
86
|
+
dryRun: import_zod.z.boolean().default(false)
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// src/core/cache.ts
|
|
90
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
91
|
+
var import_node_path2 = __toESM(require("path"));
|
|
92
|
+
|
|
93
|
+
// src/core/utils.ts
|
|
94
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
95
|
+
var import_node_fs = __toESM(require("fs"));
|
|
96
|
+
var import_node_path = __toESM(require("path"));
|
|
97
|
+
function sha256(value) {
|
|
98
|
+
return import_node_crypto.default.createHash("sha256").update(value).digest("hex");
|
|
99
|
+
}
|
|
100
|
+
function resolveFile(projectRoot, maybeRelative) {
|
|
101
|
+
return import_node_path.default.isAbsolute(maybeRelative) ? maybeRelative : import_node_path.default.join(projectRoot, maybeRelative);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/core/cache.ts
|
|
105
|
+
var EMPTY = { version: "1", entries: {} };
|
|
106
|
+
function readCache(projectRoot) {
|
|
107
|
+
const cachePath = import_node_path2.default.join(projectRoot, ".expo", "app-icon-badge", "cache.json");
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(import_node_fs2.default.readFileSync(cachePath, "utf8"));
|
|
110
|
+
} catch {
|
|
111
|
+
return EMPTY;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function isCacheHit(manifest, destination, hash) {
|
|
115
|
+
return manifest.entries[destination] === hash;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/plugin/app.plugin.ts
|
|
119
|
+
var DST_DIR = ".expo/app-icon-badge";
|
|
120
|
+
var iosIconObjectSchema = import_zod2.z.object({
|
|
121
|
+
light: import_zod2.z.string().optional(),
|
|
122
|
+
dark: import_zod2.z.string().optional(),
|
|
123
|
+
tinted: import_zod2.z.string().optional()
|
|
124
|
+
}).catchall(import_zod2.z.unknown());
|
|
125
|
+
function iosIconObject(config) {
|
|
126
|
+
const icon = config.ios?.icon;
|
|
127
|
+
if (!icon || typeof icon !== "object") return void 0;
|
|
128
|
+
const parsed = iosIconObjectSchema.safeParse(icon);
|
|
129
|
+
return parsed.success ? parsed.data : void 0;
|
|
130
|
+
}
|
|
131
|
+
function setIosIcon(config, icon) {
|
|
132
|
+
const iosWithIcon = { ...config.ios, icon };
|
|
133
|
+
config.ios = iosWithIcon;
|
|
134
|
+
}
|
|
135
|
+
function debugLog(enabled, payload) {
|
|
136
|
+
if (!enabled) return;
|
|
137
|
+
process.stdout.write(`[app-icon-badge-next:plugin] ${JSON.stringify(payload)}
|
|
138
|
+
`);
|
|
139
|
+
}
|
|
140
|
+
function iconTargets(options) {
|
|
141
|
+
const shared = options.badges ?? [];
|
|
142
|
+
const ios = options.ios.badges ?? shared;
|
|
143
|
+
const android = options.android.badges ?? shared;
|
|
144
|
+
return [
|
|
145
|
+
{
|
|
146
|
+
destination: `${DST_DIR}/icon.png`,
|
|
147
|
+
badges: shared,
|
|
148
|
+
get: (c) => typeof c.icon === "string" ? c.icon : void 0,
|
|
149
|
+
set: (c, destination) => {
|
|
150
|
+
c.icon = destination;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
destination: `${DST_DIR}/android-icon.png`,
|
|
155
|
+
badges: android,
|
|
156
|
+
get: (c) => typeof c.android?.icon === "string" ? c.android.icon : void 0,
|
|
157
|
+
set: (c, destination) => {
|
|
158
|
+
c.android = { ...c.android, icon: destination };
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
destination: `${DST_DIR}/android-adaptive-foreground.png`,
|
|
163
|
+
badges: android,
|
|
164
|
+
adaptive: true,
|
|
165
|
+
get: (c) => typeof c.android?.adaptiveIcon?.foregroundImage === "string" ? c.android.adaptiveIcon.foregroundImage : void 0,
|
|
166
|
+
set: (c, destination) => {
|
|
167
|
+
c.android = {
|
|
168
|
+
...c.android,
|
|
169
|
+
adaptiveIcon: { ...c.android?.adaptiveIcon, foregroundImage: destination }
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
destination: `${DST_DIR}/ios-icon.png`,
|
|
175
|
+
badges: ios,
|
|
176
|
+
get: (c) => typeof c.ios?.icon === "string" ? c.ios.icon : void 0,
|
|
177
|
+
set: (c, destination) => {
|
|
178
|
+
setIosIcon(c, destination);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
...["light", "dark", "tinted"].map(
|
|
182
|
+
(variant) => ({
|
|
183
|
+
destination: `${DST_DIR}/ios-icon-${variant}.png`,
|
|
184
|
+
badges: ios,
|
|
185
|
+
get: (c) => iosIconObject(c)?.[variant],
|
|
186
|
+
set: (c, destination) => {
|
|
187
|
+
setIosIcon(c, { ...iosIconObject(c), [variant]: destination });
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
)
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
function runGeneration(payload) {
|
|
194
|
+
const payloadPath = import_node_path3.default.join(
|
|
195
|
+
import_node_os.default.tmpdir(),
|
|
196
|
+
`app-icon-badge-next-${process.pid}-${Date.now()}.json`
|
|
197
|
+
);
|
|
198
|
+
import_node_fs3.default.writeFileSync(payloadPath, JSON.stringify(payload));
|
|
199
|
+
try {
|
|
200
|
+
(0, import_node_child_process.execFileSync)(process.execPath, [require.resolve("./generate.js"), payloadPath], {
|
|
201
|
+
stdio: ["ignore", "inherit", "inherit"]
|
|
202
|
+
});
|
|
203
|
+
} finally {
|
|
204
|
+
import_node_fs3.default.rmSync(payloadPath, { force: true });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
var withIconBadge = (config, options = {}) => {
|
|
208
|
+
const parsed = pluginOptionsSchema.parse(options);
|
|
209
|
+
if (!parsed.enabled) return config;
|
|
210
|
+
const projectRoot = config._internal?.projectRoot ?? process.cwd();
|
|
211
|
+
const manifest = readCache(projectRoot);
|
|
212
|
+
const jobs = [];
|
|
213
|
+
for (const target of iconTargets(parsed)) {
|
|
214
|
+
if (target.badges.length === 0) continue;
|
|
215
|
+
const source = target.get(config);
|
|
216
|
+
if (!source) continue;
|
|
217
|
+
if (source.startsWith(DST_DIR)) continue;
|
|
218
|
+
const sourceAbsolute = resolveFile(projectRoot, source);
|
|
219
|
+
if (!import_node_fs3.default.existsSync(sourceAbsolute)) {
|
|
220
|
+
debugLog(parsed.debug, { event: "missing-source", source });
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
target.set(config, target.destination);
|
|
224
|
+
const cachePayload = {
|
|
225
|
+
badges: target.badges,
|
|
226
|
+
isAdaptiveIcon: target.adaptive ?? false,
|
|
227
|
+
adaptiveSafeMode: parsed.adaptiveSafeMode,
|
|
228
|
+
safeZoneScale: parsed.android.safeZoneScale,
|
|
229
|
+
source: sourceAbsolute
|
|
230
|
+
};
|
|
231
|
+
const hash = sha256(
|
|
232
|
+
Buffer.concat([import_node_fs3.default.readFileSync(sourceAbsolute), Buffer.from(JSON.stringify(cachePayload))])
|
|
233
|
+
);
|
|
234
|
+
const destinationAbsolute = import_node_path3.default.join(projectRoot, target.destination);
|
|
235
|
+
if (parsed.cache && isCacheHit(manifest, target.destination, hash) && import_node_fs3.default.existsSync(destinationAbsolute)) {
|
|
236
|
+
debugLog(parsed.debug, { event: "cache-hit", destination: target.destination });
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
jobs.push({
|
|
240
|
+
icon: sourceAbsolute,
|
|
241
|
+
dstPath: destinationAbsolute,
|
|
242
|
+
destination: target.destination,
|
|
243
|
+
hash,
|
|
244
|
+
badges: target.badges,
|
|
245
|
+
isAdaptiveIcon: target.adaptive ?? false
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
if (jobs.length > 0 && !parsed.dryRun) {
|
|
249
|
+
runGeneration({
|
|
250
|
+
projectRoot,
|
|
251
|
+
cache: parsed.cache,
|
|
252
|
+
debug: parsed.debug,
|
|
253
|
+
adaptiveSafeMode: parsed.adaptiveSafeMode,
|
|
254
|
+
safeZoneScale: parsed.android.safeZoneScale,
|
|
255
|
+
jobs
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
debugLog(parsed.debug, {
|
|
259
|
+
event: "config-updated",
|
|
260
|
+
generated: jobs.map((job) => job.destination),
|
|
261
|
+
adaptiveSafeMode: parsed.adaptiveSafeMode,
|
|
262
|
+
safeZoneScale: parsed.android.safeZoneScale,
|
|
263
|
+
cache: parsed.cache,
|
|
264
|
+
dryRun: parsed.dryRun
|
|
265
|
+
});
|
|
266
|
+
return config;
|
|
267
|
+
};
|
|
268
|
+
var app_plugin_default = withIconBadge;
|
|
Binary file
|
|
Binary file
|