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