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