@youlai/rn-tools 0.0.0-stage → 0.1.3

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/index.mjs ADDED
@@ -0,0 +1,989 @@
1
+ import a from "node:path";
2
+ import $ from "node:fs";
3
+ import ae from "picocolors";
4
+ import { pathToFileURL as se } from "node:url";
5
+ import M from "sharp";
6
+ function B(e) {
7
+ return $.readFileSync(e, "utf8");
8
+ }
9
+ function S(e) {
10
+ return $.existsSync(e) ? B(e) : null;
11
+ }
12
+ function x(e, n, r) {
13
+ r || ($.mkdirSync(a.dirname(e), { recursive: !0 }), $.writeFileSync(e, n));
14
+ }
15
+ function _(e, n) {
16
+ let r = e, o = !1;
17
+ for (const [i, t] of n) {
18
+ const s = r.replace(i, t);
19
+ s !== r && (r = s, o = !0);
20
+ }
21
+ return { content: r, changed: o };
22
+ }
23
+ function q(e) {
24
+ if (!$.existsSync(e))
25
+ return [];
26
+ const n = [], r = (o) => {
27
+ for (const i of $.readdirSync(o, { withFileTypes: !0 })) {
28
+ const t = a.join(o, i.name);
29
+ i.isDirectory() ? r(t) : n.push(t);
30
+ }
31
+ };
32
+ return r(e), n;
33
+ }
34
+ function de(e, n, r) {
35
+ if (!$.existsSync(e) || e === n)
36
+ return [];
37
+ const o = q(e), i = [];
38
+ for (const t of o) {
39
+ const s = a.relative(e, t), d = a.join(n, s);
40
+ if ($.existsSync(d))
41
+ throw new Error(`Destination path already exists: ${d}`);
42
+ r || ($.mkdirSync(a.dirname(d), { recursive: !0 }), $.renameSync(t, d)), i.push({
43
+ from: t,
44
+ to: d
45
+ });
46
+ }
47
+ return r || ce(e), i;
48
+ }
49
+ function ce(e) {
50
+ let n = e;
51
+ for (; n !== a.dirname(n); ) {
52
+ if (!$.existsSync(n)) {
53
+ n = a.dirname(n);
54
+ continue;
55
+ }
56
+ if ($.readdirSync(n).length > 0)
57
+ break;
58
+ $.rmdirSync(n), n = a.dirname(n);
59
+ }
60
+ }
61
+ function ee(e, n) {
62
+ return $.existsSync(e) ? (n || $.rmSync(e, { recursive: !0, force: !0 }), !0) : !1;
63
+ }
64
+ function P(e) {
65
+ return W(e, "Info.plist", (n, r) => a.relative(n, r).split(a.sep).length === 2 && a.basename(r) === "Info.plist");
66
+ }
67
+ function W(e, n, r) {
68
+ const o = a.join(e, "ios"), t = q(o).find((s) => r(o, s));
69
+ if (!t)
70
+ throw new Error(`Could not find an iOS ${n} file under ${o}`);
71
+ return t;
72
+ }
73
+ const K = {
74
+ debug: 0,
75
+ info: 1,
76
+ warn: 2,
77
+ error: 3,
78
+ silent: 4
79
+ }, le = {
80
+ debug: "DEBUG",
81
+ info: "INFO ",
82
+ warn: "WARN ",
83
+ error: "ERROR"
84
+ };
85
+ function ue(e) {
86
+ return e.level ? e.level : e.quiet ? "warn" : e.verbose || process.env.RN_TOOLS_DEBUG === "1" ? "debug" : "info";
87
+ }
88
+ function fe(e, n, r) {
89
+ return e === "debug" ? r.gray(n) : e === "info" ? r.cyan(n) : e === "warn" ? r.yellow(n) : r.red(n);
90
+ }
91
+ function me() {
92
+ const e = /* @__PURE__ */ new Date();
93
+ return [
94
+ e.getHours().toString().padStart(2, "0"),
95
+ e.getMinutes().toString().padStart(2, "0"),
96
+ e.getSeconds().toString().padStart(2, "0")
97
+ ].join(":");
98
+ }
99
+ function pe(e, n, r, o) {
100
+ const i = [], t = r.prefix ?? "rn-tools";
101
+ return (r.timestamps ?? !0) && i.push(o.gray(me())), i.push(o.bold(t)), r.scope && i.push(o.magenta(r.scope)), r.dryRun && i.push(o.bgYellow(o.black(" DRY-RUN "))), i.push(fe(e, le[e], o)), i.push(n), i.join(" ");
102
+ }
103
+ function U(e, n, r, o, i) {
104
+ if (K[e] < K[o])
105
+ return;
106
+ const t = pe(e, n, r, i);
107
+ if (e === "error") {
108
+ console.error(t);
109
+ return;
110
+ }
111
+ if (e === "warn") {
112
+ console.warn(t);
113
+ return;
114
+ }
115
+ console.log(t);
116
+ }
117
+ function ge(e = {}) {
118
+ const n = ue(e), r = ae.createColors(e.color ?? !0);
119
+ return {
120
+ info(o) {
121
+ U("info", o, e, n, r);
122
+ },
123
+ warn(o) {
124
+ U("warn", o, e, n, r);
125
+ },
126
+ error(o) {
127
+ U("error", o, e, n, r);
128
+ },
129
+ debug(o) {
130
+ U("debug", o, e, n, r);
131
+ }
132
+ };
133
+ }
134
+ function O(e, n = {}) {
135
+ return e ?? ge(n);
136
+ }
137
+ const he = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)+$/, ne = ["java", "kotlin"];
138
+ function Z(e) {
139
+ if (!he.test(e))
140
+ throw new Error(
141
+ `Invalid bundle id: ${e}. Use dot-separated Java package style names, for example com.example.app`
142
+ );
143
+ }
144
+ async function ye(e) {
145
+ var C, k, E, F;
146
+ const n = a.resolve(e.rootDir ?? process.cwd()), r = e.dryRun ?? !1, o = e.verbose ?? !1, i = O(e.logger, {
147
+ dryRun: r,
148
+ color: e.color,
149
+ quiet: e.quiet,
150
+ scope: "bundle-id",
151
+ verbose: o
152
+ }), t = e.androidPackage ?? e.bundleId, s = e.iosBundleId ?? e.bundleId;
153
+ Z(t), Z(s);
154
+ const d = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), y = [], l = Ne(n);
155
+ o && ((C = i.debug) == null || C.call(i, `rootDir=${n}`), (k = i.debug) == null || k.call(i, `androidPackage=${t}`), (E = i.debug) == null || E.call(i, `iosBundleId=${s}`));
156
+ const b = S(l.gradle);
157
+ if (!b)
158
+ throw new Error(`Android build file not found: ${l.gradle}`);
159
+ const w = $e(l.gradle) ?? t, p = _(b, [
160
+ [/namespace\s+"[^"]+"/, `namespace "${t}"`],
161
+ [/applicationId\s+"[^"]+"/, `applicationId "${t}"`]
162
+ ]);
163
+ p.changed ? (x(l.gradle, p.content, r), d.add(l.gradle)) : u.add(`No namespace/applicationId changes were needed in ${l.gradle}`);
164
+ const f = b.match(/^\s*applicationId\b(.*)$/m);
165
+ f && !/^\s+"[^"]+"\s*$/.test(f[1]) && !f[1].includes(`"${t}"`) && u.add(
166
+ `applicationId in ${l.gradle} is not a string literal; update it manually`
167
+ );
168
+ const v = S(l.manifest);
169
+ if (v) {
170
+ const D = _(v, [
171
+ [/package="[^"]+"/, `package="${t}"`],
172
+ [/package\s*=\s*"[^"]+"/, `package="${t}"`]
173
+ ]);
174
+ D.changed && (x(l.manifest, D.content, r), d.add(l.manifest));
175
+ }
176
+ const g = ve(n), N = S(g);
177
+ if (!N)
178
+ throw new Error(`iOS project file not found: ${g}`);
179
+ const h = Ie(N, s);
180
+ h.changed ? (x(g, h.content, r), d.add(g)) : h.matches === 0 ? u.add(`No PRODUCT_BUNDLE_IDENTIFIER setting found in ${g}`) : u.add(`No PRODUCT_BUNDLE_IDENTIFIER changes were needed in ${g}`);
181
+ const m = P(n), c = S(m);
182
+ if (c) {
183
+ const D = c.match(
184
+ /<key>CFBundleIdentifier<\/key>\s*<string>([^<]+)<\/string>/
185
+ );
186
+ if (D && re(D[1]))
187
+ (F = i.debug) == null || F.call(i, `Kept build setting reference ${D[1]} in ${m}`);
188
+ else {
189
+ const R = _(c, [
190
+ [
191
+ /<key>CFBundleIdentifier<\/key>\s*<string>[^<]+<\/string>/,
192
+ `<key>CFBundleIdentifier</key>
193
+ <string>${s}</string>`
194
+ ]
195
+ ]);
196
+ R.changed && (x(m, R.content, r), d.add(m));
197
+ }
198
+ }
199
+ for (const D of ne) {
200
+ const R = a.join(
201
+ n,
202
+ "android/app/src/main",
203
+ D,
204
+ ...w.split(".")
205
+ ), j = a.join(
206
+ n,
207
+ "android/app/src/main",
208
+ D,
209
+ ...t.split(".")
210
+ ), oe = de(R, j, r);
211
+ for (const te of oe)
212
+ y.push(te);
213
+ }
214
+ const I = y.length > 0 ? y.map((D) => r ? D.from : D.to) : De(n, w);
215
+ for (const D of I) {
216
+ const R = S(D);
217
+ if (!R)
218
+ continue;
219
+ const j = _(R, [
220
+ [
221
+ new RegExp(`^package\\s+${be(w)}$`, "m"),
222
+ `package ${t}`
223
+ ]
224
+ ]);
225
+ j.changed && (x(D, j.content, r), d.add(D));
226
+ }
227
+ const A = {
228
+ changedFiles: Array.from(d).sort(),
229
+ movedFiles: y,
230
+ warnings: Array.from(u).sort(),
231
+ dryRun: r
232
+ };
233
+ return r ? i.info(`Dry-run completed with ${A.changedFiles.length} pending change(s)`) : i.info(`Updated ${A.changedFiles.length} file(s)`), A;
234
+ }
235
+ function Ie(e, n) {
236
+ let r = 0;
237
+ const o = e.replace(
238
+ /PRODUCT_BUNDLE_IDENTIFIER = ("[^"\n]*"|[^;\n]+);/g,
239
+ (i, t) => (r += 1, `PRODUCT_BUNDLE_IDENTIFIER = ${t.startsWith('"') ? `"${n}"` : n};`)
240
+ );
241
+ return { content: o, changed: o !== e, matches: r };
242
+ }
243
+ function re(e) {
244
+ return /\$[({][A-Za-z0-9_:]+[)}]/.test(e);
245
+ }
246
+ function $e(e) {
247
+ const n = S(e);
248
+ if (!n)
249
+ return null;
250
+ const r = n.match(/namespace\s+"([^"]+)"/);
251
+ return (r == null ? void 0 : r[1]) ?? null;
252
+ }
253
+ function Ne(e) {
254
+ return {
255
+ gradle: a.join(e, "android/app/build.gradle"),
256
+ manifest: a.join(e, "android/app/src/main/AndroidManifest.xml"),
257
+ javaRoot: a.join(e, "android/app/src/main/java"),
258
+ kotlinRoot: a.join(e, "android/app/src/main/kotlin")
259
+ };
260
+ }
261
+ function ve(e) {
262
+ return W(e, "project.pbxproj", (n, r) => a.relative(n, r).split(a.sep).length === 2 && r.endsWith(".xcodeproj/project.pbxproj"));
263
+ }
264
+ function De(e, n) {
265
+ const r = ne.map(
266
+ (i) => a.join(e, "android/app/src/main", i, ...n.split("."))
267
+ ), o = [];
268
+ for (const i of r)
269
+ o.push(...q(i));
270
+ return o;
271
+ }
272
+ function be(e) {
273
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
274
+ }
275
+ const we = [
276
+ "android/.gradle",
277
+ "android/app/build",
278
+ "ios/build",
279
+ ".metro",
280
+ ".expo"
281
+ ];
282
+ async function Ae(e) {
283
+ var u;
284
+ const n = a.resolve(e.rootDir ?? process.cwd()), r = e.dryRun ?? !1, o = e.verbose ?? !1, i = O(e.logger, {
285
+ dryRun: r,
286
+ color: e.color,
287
+ quiet: e.quiet,
288
+ scope: "clean",
289
+ verbose: o
290
+ });
291
+ o && ((u = i.debug) == null || u.call(i, `rootDir=${n}`));
292
+ const t = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
293
+ for (const y of we) {
294
+ const l = a.join(n, y);
295
+ ee(l, r) && (o && i.info(`${r ? "[dry-run] " : ""}clean target: ${l}`), t.add(l));
296
+ }
297
+ const d = {
298
+ changedFiles: Array.from(t).sort(),
299
+ movedFiles: [],
300
+ warnings: Array.from(s).sort(),
301
+ dryRun: r
302
+ };
303
+ return r ? i.info(`Dry-run completed with ${d.changedFiles.length} target(s)`) : i.info(`Cleaned ${d.changedFiles.length} target(s)`), d;
304
+ }
305
+ function Se(e) {
306
+ if (!e || !e.trim())
307
+ throw new Error("Display name cannot be empty");
308
+ }
309
+ async function xe(e) {
310
+ var v, g;
311
+ const n = a.resolve(e.rootDir ?? process.cwd()), r = e.dryRun ?? !1, o = e.verbose ?? !1, i = O(e.logger, {
312
+ dryRun: r,
313
+ color: e.color,
314
+ quiet: e.quiet,
315
+ scope: "display-name",
316
+ verbose: o
317
+ }), t = e.displayName.trim();
318
+ Se(t), o && ((v = i.debug) == null || v.call(i, `rootDir=${n}`), (g = i.debug) == null || g.call(i, `displayName=${t}`));
319
+ const s = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), u = a.join(n, "app.json"), y = S(u);
320
+ if (y)
321
+ try {
322
+ const h = {
323
+ ...JSON.parse(y),
324
+ displayName: t
325
+ }, m = `${JSON.stringify(h, null, 2)}
326
+ `;
327
+ m !== y && (x(u, m, r), s.add(u));
328
+ } catch {
329
+ d.add(`Skipped invalid JSON file: ${u}`);
330
+ }
331
+ const l = P(n), b = S(l);
332
+ if (b) {
333
+ const N = [
334
+ [
335
+ /<key>CFBundleDisplayName<\/key>\s*<string>[^<]*<\/string>/,
336
+ `<key>CFBundleDisplayName</key>
337
+ <string>${t}</string>`
338
+ ]
339
+ ], h = b.match(
340
+ /<key>CFBundleName<\/key>\s*<string>([^<]*)<\/string>/
341
+ );
342
+ (!h || !re(h[1])) && N.push([
343
+ /<key>CFBundleName<\/key>\s*<string>[^<]*<\/string>/,
344
+ `<key>CFBundleName</key>
345
+ <string>${t}</string>`
346
+ ]);
347
+ const m = _(b, N);
348
+ m.changed ? (x(l, m.content, r), s.add(l)) : d.add(`No iOS display-name changes were needed in ${l}`);
349
+ }
350
+ const w = a.join(n, "android/app/src/main/res/values/strings.xml"), p = S(w);
351
+ if (p) {
352
+ const N = _(p, [
353
+ [/<string name="app_name">[^<]*<\/string>/, `<string name="app_name">${t}</string>`]
354
+ ]);
355
+ N.changed ? (x(w, N.content, r), s.add(w)) : d.add(`No Android app_name changes were needed in ${w}`);
356
+ }
357
+ const f = {
358
+ changedFiles: Array.from(s).sort(),
359
+ movedFiles: [],
360
+ warnings: Array.from(d).sort(),
361
+ dryRun: r
362
+ };
363
+ return r ? i.info(`Dry-run completed with ${f.changedFiles.length} pending change(s)`) : i.info(`Updated ${f.changedFiles.length} file(s)`), f;
364
+ }
365
+ async function Re(e) {
366
+ var g, N, h, m;
367
+ const n = a.resolve(e.rootDir ?? process.cwd()), r = e.verbose ?? !1, o = O(e.logger, {
368
+ color: e.color,
369
+ quiet: e.quiet,
370
+ scope: "doctor",
371
+ verbose: r
372
+ });
373
+ r && ((g = o.debug) == null || g.call(o, `rootDir=${n}`));
374
+ const i = /* @__PURE__ */ new Set(), t = [], s = {}, d = a.join(n, "app.json"), u = S(d);
375
+ if (!u)
376
+ i.add(`Missing app.json: ${d}`);
377
+ else
378
+ try {
379
+ const c = JSON.parse(u);
380
+ s.appName = c.name, s.displayName = c.displayName, c.name || i.add(`Missing "name" in app.json: ${d}`), c.displayName || i.add(`Missing "displayName" in app.json: ${d}`);
381
+ } catch {
382
+ i.add(`Invalid JSON: ${d}`);
383
+ }
384
+ const y = a.join(n, "android/app/build.gradle"), l = S(y);
385
+ if (!l)
386
+ i.add(`Missing Android build file: ${y}`);
387
+ else {
388
+ const c = (N = l.match(/namespace\s+"([^"]+)"/)) == null ? void 0 : N[1], I = (h = l.match(/applicationId\s+"([^"]+)"/)) == null ? void 0 : h[1];
389
+ s.androidNamespace = c, s.androidApplicationId = I, c || i.add(`Missing namespace in ${y}`), I || i.add(`Missing applicationId in ${y}`), c && I && c !== I && i.add(`Android namespace and applicationId differ: ${c} vs ${I}`);
390
+ }
391
+ const b = a.join(n, "android/app/src/main/res/values/strings.xml"), w = S(b);
392
+ if (!w)
393
+ i.add(`Missing Android strings: ${b}`);
394
+ else {
395
+ const c = (m = w.match(/<string name="app_name">([^<]+)<\/string>/)) == null ? void 0 : m[1];
396
+ s.androidAppName = c, c || i.add(`Missing app_name in ${b}`);
397
+ }
398
+ const p = P(n), f = S(p);
399
+ f ? (s.iosBundleId = J(f, "CFBundleIdentifier"), s.iosDisplayName = J(f, "CFBundleDisplayName"), s.iosName = J(f, "CFBundleName"), /<key>CFBundleIdentifier<\/key>/.test(f) || i.add(`Missing CFBundleIdentifier in ${p}`), /<key>CFBundleDisplayName<\/key>/.test(f) || i.add(`Missing CFBundleDisplayName in ${p}`)) : i.add(`Missing iOS Info.plist: ${p}`), q(a.join(n, "android/app/src/main")).filter(
400
+ (c) => /\.(kt|java)$/.test(c)
401
+ ).length === 0 && i.add("No Android source files found under android/app/src/main"), Ce(s, i), s.appName && s.displayName && s.appName !== s.displayName && i.add(
402
+ `app.json "name" and "displayName" differ: ${s.appName} vs ${s.displayName}`
403
+ );
404
+ for (const c of i)
405
+ o.warn(c);
406
+ return i.size === 0 ? o.info("Doctor check passed") : o.info(`Doctor found ${i.size} issue(s)`), {
407
+ changedFiles: t,
408
+ movedFiles: [],
409
+ warnings: Array.from(i).sort(),
410
+ dryRun: !0
411
+ };
412
+ }
413
+ function J(e, n) {
414
+ var r;
415
+ return (r = e.match(new RegExp(`<key>${n}<\\/key>\\s*<string>([^<]*)<\\/string>`))) == null ? void 0 : r[1];
416
+ }
417
+ function T(e) {
418
+ return typeof e == "string" && !e.startsWith("$(") && !e.startsWith("${");
419
+ }
420
+ function Ce(e, n) {
421
+ e.androidNamespace && e.androidApplicationId && e.androidNamespace !== e.androidApplicationId && n.add(
422
+ `Android namespace and applicationId differ: ${e.androidNamespace} vs ${e.androidApplicationId}`
423
+ ), T(e.iosDisplayName) && T(e.iosName) && e.iosDisplayName !== e.iosName && n.add(
424
+ `iOS CFBundleDisplayName and CFBundleName differ: ${e.iosDisplayName} vs ${e.iosName}`
425
+ );
426
+ const r = e.displayName;
427
+ T(r) && (T(e.androidAppName) && e.androidAppName !== r && n.add(
428
+ `Android app_name does not match app.json displayName: ${e.androidAppName} vs ${r}`
429
+ ), T(e.iosDisplayName) && e.iosDisplayName !== r && n.add(
430
+ `iOS CFBundleDisplayName does not match app.json displayName: ${e.iosDisplayName} vs ${r}`
431
+ ));
432
+ }
433
+ const ke = "assets/icon.png", Fe = "android/app/src/main/res", Ee = "AppIcon.appiconset", je = "ic_launcher", _e = "ic_launcher_round", Oe = !0, Te = "#FFFFFF", Be = 0.72, Pe = "#FFFFFF", ie = [
434
+ { dir: "mipmap-mdpi", size: 48 },
435
+ { dir: "mipmap-hdpi", size: 72 },
436
+ { dir: "mipmap-xhdpi", size: 96 },
437
+ { dir: "mipmap-xxhdpi", size: 144 },
438
+ { dir: "mipmap-xxxhdpi", size: 192 }
439
+ ], Ue = [
440
+ { dir: "drawable-mdpi", size: 108 },
441
+ { dir: "drawable-hdpi", size: 162 },
442
+ { dir: "drawable-xhdpi", size: 216 },
443
+ { dir: "drawable-xxhdpi", size: 324 },
444
+ { dir: "drawable-xxxhdpi", size: 432 }
445
+ ], X = [
446
+ { idiom: "iphone", size: "20x20", scale: "2x", filename: "icon-20x20-2x-iphone.png" },
447
+ { idiom: "iphone", size: "20x20", scale: "3x", filename: "icon-20x20-3x-iphone.png" },
448
+ { idiom: "ipad", size: "20x20", scale: "1x", filename: "icon-20x20-1x-ipad.png" },
449
+ { idiom: "ipad", size: "20x20", scale: "2x", filename: "icon-20x20-2x-ipad.png" },
450
+ { idiom: "iphone", size: "29x29", scale: "2x", filename: "icon-29x29-2x-iphone.png" },
451
+ { idiom: "iphone", size: "29x29", scale: "3x", filename: "icon-29x29-3x-iphone.png" },
452
+ { idiom: "ipad", size: "29x29", scale: "1x", filename: "icon-29x29-1x-ipad.png" },
453
+ { idiom: "ipad", size: "29x29", scale: "2x", filename: "icon-29x29-2x-ipad.png" },
454
+ { idiom: "iphone", size: "40x40", scale: "2x", filename: "icon-40x40-2x-iphone.png" },
455
+ { idiom: "iphone", size: "40x40", scale: "3x", filename: "icon-40x40-3x-iphone.png" },
456
+ { idiom: "ipad", size: "40x40", scale: "1x", filename: "icon-40x40-1x-ipad.png" },
457
+ { idiom: "ipad", size: "40x40", scale: "2x", filename: "icon-40x40-2x-ipad.png" },
458
+ { idiom: "iphone", size: "60x60", scale: "2x", filename: "icon-60x60-2x-iphone.png" },
459
+ { idiom: "iphone", size: "60x60", scale: "3x", filename: "icon-60x60-3x-iphone.png" },
460
+ { idiom: "ipad", size: "76x76", scale: "1x", filename: "icon-76x76-1x-ipad.png" },
461
+ { idiom: "ipad", size: "76x76", scale: "2x", filename: "icon-76x76-2x-ipad.png" },
462
+ { idiom: "ipad", size: "83.5x83.5", scale: "2x", filename: "icon-83_5x83_5-2x-ipad.png" },
463
+ { idiom: "ios-marketing", size: "1024x1024", scale: "1x", filename: "icon-1024x1024.png" }
464
+ ];
465
+ async function ze(e) {
466
+ var C, k, E, F, D, R;
467
+ const n = await Qe(e.configPath, e.rootDir), r = Le(n, e), o = a.resolve(r.rootDir ?? process.cwd()), i = e.dryRun ?? !1, t = e.verbose ?? !1, s = O(e.logger, {
468
+ dryRun: i,
469
+ color: e.color,
470
+ quiet: e.quiet,
471
+ scope: "icon",
472
+ verbose: t
473
+ }), d = V(
474
+ o,
475
+ r.sourceImage ?? ke
476
+ ), u = V(
477
+ o,
478
+ r.androidDestinationDir ?? Fe
479
+ ), y = V(
480
+ o,
481
+ r.iosAssetsDir ?? sn(o)
482
+ ), l = a.join(
483
+ y,
484
+ r.iosIconSetName ?? Ee
485
+ ), b = r.androidIconName ?? je, w = r.androidRoundIconName ?? _e, p = r.androidAdaptiveIcon ?? Oe, f = r.androidAdaptiveIconBackgroundColor ?? Te, v = r.androidAdaptiveIconForegroundScale ?? Be, g = r.iosIconBackgroundColor ?? Pe;
486
+ t && ((C = s.debug) == null || C.call(s, `rootDir=${o}`), (k = s.debug) == null || k.call(s, `sourceImage=${d}`), (E = s.debug) == null || E.call(s, `androidDestinationDir=${u}`), (F = s.debug) == null || F.call(s, `androidAdaptiveIcon=${p}`), (D = s.debug) == null || D.call(s, `iosAssetsDir=${y}`), (R = s.debug) == null || R.call(s, `iosIconSetDir=${l}`)), Ve(d, "Icon source image"), We(v), Ke(d, u, l);
487
+ const N = await Xe(d);
488
+ Ge(N, d);
489
+ const h = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Set(), c = await Me({
490
+ sourceImage: d,
491
+ destinationDir: u,
492
+ iconName: b,
493
+ roundIconName: w,
494
+ adaptiveIcon: p,
495
+ adaptiveIconBackgroundColor: f,
496
+ adaptiveIconForegroundScale: v,
497
+ dryRun: i
498
+ }), I = await qe({
499
+ sourceImage: d,
500
+ iconSetDir: l,
501
+ backgroundColor: g,
502
+ dryRun: i
503
+ });
504
+ (await M(d).stats()).isOpaque || m.add(
505
+ `Icon source has transparent pixels; iOS icons were filled with ${g}`
506
+ );
507
+ for (const j of [...c, ...I])
508
+ h.add(j);
509
+ c.length === 0 && m.add(`No Android icon files were generated from ${d}`), I.length === 0 && m.add(`No iOS icon files were generated from ${d}`);
510
+ const A = {
511
+ changedFiles: Array.from(h).sort(),
512
+ movedFiles: [],
513
+ warnings: Array.from(m).sort(),
514
+ dryRun: i
515
+ };
516
+ return i ? s.info(`Dry-run completed with ${A.changedFiles.length} pending icon file(s)`) : s.info(`Generated ${A.changedFiles.length} icon file(s)`), A;
517
+ }
518
+ function Le(e, n) {
519
+ return {
520
+ ...e,
521
+ ...n
522
+ };
523
+ }
524
+ async function Me(e) {
525
+ const n = [];
526
+ for (const { dir: r, size: o } of ie) {
527
+ const i = a.join(e.destinationDir, r), t = a.join(i, `${e.iconName}.png`), s = a.join(i, `${e.roundIconName}.png`);
528
+ e.dryRun || ($.mkdirSync(i, { recursive: !0 }), await G(e.sourceImage, t, o), await G(e.sourceImage, s, o)), n.push(t, s);
529
+ }
530
+ if (e.adaptiveIcon) {
531
+ const r = `${e.iconName}_foreground`, o = `${e.iconName}_background`;
532
+ for (const { dir: d, size: u } of Ue) {
533
+ const y = a.join(e.destinationDir, d), l = a.join(y, `${r}.png`);
534
+ e.dryRun || ($.mkdirSync(y, { recursive: !0 }), await Ye(
535
+ e.sourceImage,
536
+ l,
537
+ u,
538
+ e.adaptiveIconForegroundScale
539
+ )), n.push(l);
540
+ }
541
+ const i = a.join(e.destinationDir, "values", `${o}.xml`), t = a.join(
542
+ e.destinationDir,
543
+ "mipmap-anydpi-v26",
544
+ `${e.iconName}.xml`
545
+ ), s = a.join(
546
+ e.destinationDir,
547
+ "mipmap-anydpi-v26",
548
+ `${e.roundIconName}.xml`
549
+ );
550
+ e.dryRun || (x(
551
+ i,
552
+ He(o, e.adaptiveIconBackgroundColor),
553
+ !1
554
+ ), x(t, Y(o, r), !1), x(
555
+ s,
556
+ Y(o, r),
557
+ !1
558
+ )), n.push(i, t, s);
559
+ }
560
+ return n;
561
+ }
562
+ async function qe(e) {
563
+ const n = [], r = X.map((t) => ({
564
+ idiom: t.idiom,
565
+ size: t.size,
566
+ scale: t.scale,
567
+ filename: t.filename
568
+ }));
569
+ e.dryRun || (ee(e.iconSetDir, !1), $.mkdirSync(e.iconSetDir, { recursive: !0 }));
570
+ for (const t of X) {
571
+ const s = a.join(e.iconSetDir, t.filename), d = Je(t.size, t.scale);
572
+ e.dryRun || await G(e.sourceImage, s, d, e.backgroundColor), n.push(s);
573
+ }
574
+ const o = a.join(e.iconSetDir, "Contents.json"), i = JSON.stringify(
575
+ {
576
+ images: r,
577
+ info: {
578
+ version: 1,
579
+ author: "xcode"
580
+ }
581
+ },
582
+ null,
583
+ 2
584
+ );
585
+ return e.dryRun || x(o, `${i}
586
+ `, !1), n.push(o), n;
587
+ }
588
+ function Je(e, n) {
589
+ const r = Number.parseFloat(e.split("x")[0] ?? "0"), o = Number.parseFloat(n.replace("x", ""));
590
+ return Math.round(r * o);
591
+ }
592
+ function Ve(e, n) {
593
+ if (!$.existsSync(e))
594
+ throw new Error(`${n} not found: ${e}`);
595
+ }
596
+ function Ge(e, n) {
597
+ if (!e.width || !e.height)
598
+ throw new Error(`Unable to read image dimensions for ${n}`);
599
+ if (e.width !== e.height)
600
+ throw new Error(
601
+ `Icon source image must be square, but got ${e.width}x${e.height}: ${n}`
602
+ );
603
+ }
604
+ function We(e) {
605
+ if (!Number.isFinite(e) || e <= 0 || e > 1)
606
+ throw new Error(
607
+ `Android adaptive icon foreground scale must be a number between 0 and 1, but got ${e}`
608
+ );
609
+ }
610
+ function Ke(e, n, r) {
611
+ const o = ie.map(
612
+ ({ dir: t }) => a.join(n, t)
613
+ ), i = [r, ...o].filter(
614
+ (t) => Ze(e, t)
615
+ );
616
+ if (i.length > 0)
617
+ throw new Error(
618
+ `Icon source image must be outside generated icon directories: ${i.join(", ")}
619
+ Use a source file such as assets/icon.png instead: ${e}`
620
+ );
621
+ }
622
+ function Ze(e, n) {
623
+ const r = a.relative(n, e);
624
+ return r === "" || !r.startsWith("..") && !a.isAbsolute(r);
625
+ }
626
+ function V(e, n) {
627
+ return a.isAbsolute(n) ? n : a.join(e, n);
628
+ }
629
+ async function Xe(e) {
630
+ return M(e).metadata();
631
+ }
632
+ async function G(e, n, r, o) {
633
+ $.mkdirSync(a.dirname(n), { recursive: !0 });
634
+ const i = M(e).resize(r, r, { fit: "fill" });
635
+ o && i.flatten({ background: o }).removeAlpha(), await i.png().toFile(n);
636
+ }
637
+ async function Ye(e, n, r, o) {
638
+ const i = Math.max(1, Math.round(r * o));
639
+ $.mkdirSync(a.dirname(n), { recursive: !0 }), await M(e).resize(i, i, { fit: "contain" }).extend({
640
+ top: Math.floor((r - i) / 2),
641
+ bottom: Math.ceil((r - i) / 2),
642
+ left: Math.floor((r - i) / 2),
643
+ right: Math.ceil((r - i) / 2),
644
+ background: { r: 0, g: 0, b: 0, alpha: 0 }
645
+ }).png().toFile(n);
646
+ }
647
+ function He(e, n) {
648
+ return [
649
+ '<?xml version="1.0" encoding="utf-8"?>',
650
+ "<resources>",
651
+ ` <color name="${e}">${n}</color>`,
652
+ "</resources>",
653
+ ""
654
+ ].join(`
655
+ `);
656
+ }
657
+ function Y(e, n) {
658
+ return [
659
+ '<?xml version="1.0" encoding="utf-8"?>',
660
+ '<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">',
661
+ ` <background android:drawable="@color/${e}" />`,
662
+ ` <foreground android:drawable="@drawable/${n}" />`,
663
+ "</adaptive-icon>",
664
+ ""
665
+ ].join(`
666
+ `);
667
+ }
668
+ async function Qe(e, n) {
669
+ if (!e) {
670
+ const i = rn(n);
671
+ return i ? H(i) : {};
672
+ }
673
+ nn(e);
674
+ const r = en(e, n), o = r.find((i) => $.existsSync(i));
675
+ if (!o)
676
+ throw new Error(`Icon config file not found: ${r[0] ?? a.resolve(e)}`);
677
+ return H(o);
678
+ }
679
+ function en(e, n) {
680
+ if (a.isAbsolute(e))
681
+ return [e];
682
+ const r = a.resolve(process.cwd(), e), o = n ? a.resolve(n, e) : null, i = [r];
683
+ return o && o !== r && i.push(o), i;
684
+ }
685
+ function nn(e) {
686
+ const n = a.basename(e);
687
+ if (n === "rn-tools.config" || n.startsWith("rn-tools.config."))
688
+ throw new Error(
689
+ `Legacy visible config filenames are not supported: ${e}. Use .rn-toolsrc, .rn-toolsrc.json, .rn-toolsrc.js, .rn-toolsrc.cjs, or .rn-toolsrc.mjs instead.`
690
+ );
691
+ }
692
+ function rn(e) {
693
+ const n = [e ? a.resolve(e) : null, process.cwd()].filter(
694
+ (o) => !!o
695
+ ), r = [
696
+ ".rn-toolsrc",
697
+ ".rn-toolsrc.json",
698
+ ".rn-toolsrc.js",
699
+ ".rn-toolsrc.cjs",
700
+ ".rn-toolsrc.mjs"
701
+ ];
702
+ for (const o of n)
703
+ for (const i of r) {
704
+ const t = a.join(o, i);
705
+ if ($.existsSync(t))
706
+ return t;
707
+ }
708
+ return null;
709
+ }
710
+ async function H(e) {
711
+ const n = a.extname(e).toLowerCase();
712
+ if (n === ".json" || n === "") {
713
+ const o = S(e);
714
+ if (!o)
715
+ throw new Error(`Icon config file not found: ${e}`);
716
+ let i;
717
+ try {
718
+ i = JSON.parse(o);
719
+ } catch {
720
+ throw new Error(`Icon config file is not valid JSON: ${e}`);
721
+ }
722
+ return Q(i, e);
723
+ }
724
+ const r = await import(se(e).href);
725
+ return Q(r, e);
726
+ }
727
+ function Q(e, n) {
728
+ if (!e || typeof e != "object")
729
+ throw new Error(`Icon config file must contain an object: ${n}`);
730
+ const r = on(e);
731
+ if (!r)
732
+ throw new Error(`Icon config section must be an object: ${n}`);
733
+ return an(r, a.dirname(n));
734
+ }
735
+ function on(e) {
736
+ if (!z(e))
737
+ return null;
738
+ const n = z(e.default) ? e.default : e;
739
+ return tn(n) ? z(n.icon) ? n.icon : null : z(n) ? n : null;
740
+ }
741
+ function tn(e) {
742
+ return Object.prototype.hasOwnProperty.call(e, "icon");
743
+ }
744
+ function z(e) {
745
+ return !!e && typeof e == "object" && !Array.isArray(e);
746
+ }
747
+ function an(e, n) {
748
+ const r = {};
749
+ return e.rootDir && (r.rootDir = L(n, e.rootDir)), e.sourceImage && (r.sourceImage = L(n, e.sourceImage)), e.androidDestinationDir && (r.androidDestinationDir = L(n, e.androidDestinationDir)), typeof e.androidAdaptiveIcon == "boolean" && (r.androidAdaptiveIcon = e.androidAdaptiveIcon), e.androidAdaptiveIconBackgroundColor && (r.androidAdaptiveIconBackgroundColor = e.androidAdaptiveIconBackgroundColor), typeof e.androidAdaptiveIconForegroundScale == "number" && (r.androidAdaptiveIconForegroundScale = e.androidAdaptiveIconForegroundScale), e.iosAssetsDir && (r.iosAssetsDir = L(n, e.iosAssetsDir)), e.iosIconSetName && (r.iosIconSetName = e.iosIconSetName), e.iosIconBackgroundColor && (r.iosIconBackgroundColor = e.iosIconBackgroundColor), e.androidIconName && (r.androidIconName = e.androidIconName), e.androidRoundIconName && (r.androidRoundIconName = e.androidRoundIconName), r;
750
+ }
751
+ function L(e, n) {
752
+ return a.isAbsolute(n) ? n : a.resolve(e, n);
753
+ }
754
+ function sn(e) {
755
+ const n = P(e);
756
+ return a.join(a.dirname(n), "Images.xcassets");
757
+ }
758
+ const dn = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
759
+ async function cn(e = {}) {
760
+ const n = a.resolve(e.rootDir ?? process.cwd()), r = e.dryRun ?? !1, o = e.platform ?? "all";
761
+ if (!["all", "android", "ios"].includes(o))
762
+ throw new Error("Platform must be all, android, or ios");
763
+ const i = a.join(n, "package.json"), t = B(i), s = JSON.parse(t), d = e.version ?? s.version;
764
+ if (typeof d != "string" || !dn.test(d))
765
+ throw new Error("Version must contain three non-negative integers, for example 1.2.3");
766
+ const u = e.buildNumber === void 0 ? void 0 : String(e.buildNumber);
767
+ if (u !== void 0 && (!/^[1-9]\d*$/.test(u) || Number(u) > 21e8))
768
+ throw new Error("Build number must be a positive integer no greater than 2100000000");
769
+ const y = O(e.logger, {
770
+ dryRun: r,
771
+ verbose: e.verbose,
772
+ quiet: e.quiet,
773
+ color: e.color,
774
+ scope: "version"
775
+ }), l = /* @__PURE__ */ new Map(), b = (p, f, v) => {
776
+ v !== f && l.set(p, v);
777
+ }, w = (p, f, v, g, N) => {
778
+ const h = p.match(f) ?? [], m = p.match(new RegExp(`^[ \\t]*${g}\\b[^\\r\\n]*`, "gm")) ?? [];
779
+ if (h.length === 0 || h.length !== m.length)
780
+ throw new Error(`Could not find a literal ${g} in ${N}`);
781
+ return f.lastIndex = 0, p.replace(f, v);
782
+ };
783
+ if (o === "all" || o === "android") {
784
+ const p = a.join(n, "android/app/build.gradle"), f = a.join(n, "android/app/build.gradle.kts"), v = S(p), g = v === null ? f : p, N = v ?? B(f);
785
+ let h = w(
786
+ N,
787
+ /^([ \t]*versionName[ \t]*(?:=[ \t]*)?)(["'])([^"'\r\n]*)\2([ \t]*;?[ \t]*(?:\/\/[^\r\n]*)?\r?)$/gm,
788
+ (m, c, I, A, C) => `${c}${I}${d}${I}${C}`,
789
+ "versionName",
790
+ g
791
+ );
792
+ u !== void 0 && (h = w(
793
+ h,
794
+ /^([ \t]*versionCode[ \t]*(?:=[ \t]*)?)(\d+)([ \t]*;?[ \t]*(?:\/\/[^\r\n]*)?\r?)$/gm,
795
+ (m, c, I, A) => `${c}${u}${A}`,
796
+ "versionCode",
797
+ g
798
+ )), b(g, N, h);
799
+ }
800
+ if (o === "all" || o === "ios") {
801
+ const p = W(
802
+ n,
803
+ "project.pbxproj",
804
+ (m, c) => a.relative(m, c).split(a.sep).length === 2 && a.dirname(c).endsWith(".xcodeproj") && a.basename(c) === "project.pbxproj"
805
+ ), f = B(p);
806
+ let v = w(
807
+ f,
808
+ /^([ \t]*MARKETING_VERSION[ \t]*=[ \t]*)("?)[\d.]+\2([ \t]*;[^\r\n]*\r?)$/gm,
809
+ (m, c, I, A) => `${c}${I}${d}${I}${A}`,
810
+ "MARKETING_VERSION",
811
+ p
812
+ );
813
+ u !== void 0 && (v = w(
814
+ v,
815
+ /^([ \t]*CURRENT_PROJECT_VERSION[ \t]*=[ \t]*)("?)[\d.]+\2([ \t]*;[^\r\n]*\r?)$/gm,
816
+ (m, c, I, A) => `${c}${I}${u}${I}${A}`,
817
+ "CURRENT_PROJECT_VERSION",
818
+ p
819
+ )), b(p, f, v);
820
+ const g = P(n), N = B(g);
821
+ let h = N;
822
+ for (const [m, c, I] of [
823
+ ["CFBundleShortVersionString", "MARKETING_VERSION", d],
824
+ ["CFBundleVersion", "CURRENT_PROJECT_VERSION", u]
825
+ ]) {
826
+ if (I === void 0) continue;
827
+ const A = new RegExp(`(<key>${m}</key>\\s*<string>)([^<]*)(</string>)`), C = h.match(A);
828
+ if (!C) throw new Error(`Could not find ${m} in ${g}`);
829
+ const k = C[2];
830
+ if (!(k === `$(${c})` || k === "${" + c + "}")) {
831
+ if (/\$[({]/.test(k))
832
+ throw new Error(`Unsupported ${m} reference ${k} in ${g}`);
833
+ h = h.replace(
834
+ A,
835
+ (E, F, D, R) => `${F}${I}${R}`
836
+ );
837
+ }
838
+ }
839
+ b(g, N, h);
840
+ }
841
+ e.version !== void 0 && s.version !== d && b(i, t, `${JSON.stringify({ ...s, version: d }, null, 2)}
842
+ `);
843
+ for (const [p, f] of l)
844
+ x(p, f, r);
845
+ return y.info(
846
+ `${r ? "Would set" : "Set"} version ${d}${u === void 0 ? "" : ` (${u})`}`
847
+ ), { changedFiles: [...l.keys()].sort(), movedFiles: [], warnings: [], dryRun: r };
848
+ }
849
+ const ln = {
850
+ name: "bundle-id",
851
+ description: "Rename the iOS bundle identifier and Android application package",
852
+ async run(e, n) {
853
+ return ye({
854
+ ...n,
855
+ rootDir: n.rootDir ?? e.rootDir,
856
+ dryRun: n.dryRun ?? e.dryRun,
857
+ verbose: n.verbose ?? e.verbose,
858
+ quiet: n.quiet ?? e.quiet,
859
+ color: n.color ?? e.color,
860
+ logger: n.logger ?? e.logger
861
+ });
862
+ }
863
+ }, un = {
864
+ name: "display-name",
865
+ description: "Update the app display name on iOS and Android",
866
+ async run(e, n) {
867
+ return xe({
868
+ ...n,
869
+ rootDir: n.rootDir ?? e.rootDir,
870
+ dryRun: n.dryRun ?? e.dryRun,
871
+ verbose: n.verbose ?? e.verbose,
872
+ quiet: n.quiet ?? e.quiet,
873
+ color: n.color ?? e.color,
874
+ logger: n.logger ?? e.logger
875
+ });
876
+ }
877
+ }, fn = {
878
+ name: "version",
879
+ description: "Sync the app version and build number to Android and iOS",
880
+ async run(e, n) {
881
+ return cn({
882
+ ...n,
883
+ rootDir: n.rootDir ?? e.rootDir,
884
+ dryRun: n.dryRun ?? e.dryRun,
885
+ verbose: n.verbose ?? e.verbose,
886
+ quiet: n.quiet ?? e.quiet,
887
+ color: n.color ?? e.color,
888
+ logger: n.logger ?? e.logger
889
+ });
890
+ }
891
+ }, mn = {
892
+ name: "clean",
893
+ description: "Remove common build and cache artifacts",
894
+ async run(e, n) {
895
+ return Ae({
896
+ ...n,
897
+ rootDir: n.rootDir ?? e.rootDir,
898
+ dryRun: n.dryRun ?? e.dryRun,
899
+ verbose: n.verbose ?? e.verbose,
900
+ quiet: n.quiet ?? e.quiet,
901
+ color: n.color ?? e.color,
902
+ logger: n.logger ?? e.logger
903
+ });
904
+ }
905
+ }, pn = {
906
+ name: "doctor",
907
+ description: "Check common RN project health signals",
908
+ async run(e, n) {
909
+ return Re({
910
+ ...n,
911
+ rootDir: n.rootDir ?? e.rootDir,
912
+ verbose: n.verbose ?? e.verbose,
913
+ quiet: n.quiet ?? e.quiet,
914
+ color: n.color ?? e.color,
915
+ logger: n.logger ?? e.logger
916
+ });
917
+ }
918
+ }, gn = {
919
+ name: "icon",
920
+ description: "Generate Android and iOS app icons from a single source image",
921
+ async run(e, n) {
922
+ return ze({
923
+ ...n,
924
+ rootDir: n.rootDir ?? e.rootDir,
925
+ dryRun: n.dryRun ?? e.dryRun,
926
+ verbose: n.verbose ?? e.verbose,
927
+ quiet: n.quiet ?? e.quiet,
928
+ color: n.color ?? e.color,
929
+ logger: n.logger ?? e.logger
930
+ });
931
+ }
932
+ };
933
+ function hn(e = [
934
+ ln,
935
+ un,
936
+ fn,
937
+ mn,
938
+ pn,
939
+ gn
940
+ ]) {
941
+ const n = /* @__PURE__ */ new Map();
942
+ for (const o of e)
943
+ n.set(o.name, o);
944
+ const r = {
945
+ listTasks() {
946
+ return Array.from(n.values());
947
+ },
948
+ getTask(o) {
949
+ return n.get(o);
950
+ },
951
+ registerTask(o) {
952
+ return n.set(o.name, o), r;
953
+ },
954
+ async runTask(o, i, t) {
955
+ const s = n.get(o);
956
+ if (!s) {
957
+ const d = Array.from(n.keys()).sort();
958
+ throw new Error(
959
+ `Unknown task "${o}". Available tasks: ${d.join(", ") || "(none)"}`
960
+ );
961
+ }
962
+ return s.run(i, t);
963
+ }
964
+ };
965
+ return r;
966
+ }
967
+ const yn = hn();
968
+ async function bn(e, n, r, o = yn) {
969
+ return o.runTask(e, n, r);
970
+ }
971
+ export {
972
+ ze as buildIconAssets,
973
+ ln as bundleIdTask,
974
+ Ae as cleanProject,
975
+ mn as cleanTask,
976
+ ge as createConsoleLogger,
977
+ hn as createProjectToolRunner,
978
+ yn as defaultProjectToolRunner,
979
+ un as displayNameTask,
980
+ Re as doctorProject,
981
+ pn as doctorTask,
982
+ O as getLogger,
983
+ gn as iconTask,
984
+ ye as renameBundleId,
985
+ bn as runProjectTask,
986
+ xe as updateDisplayName,
987
+ cn as updateVersion,
988
+ fn as versionTask
989
+ };