@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/README.md
CHANGED
|
@@ -1,3 +1,329 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @youlai/rn-tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
面向 React Native 项目的通用维护工具箱,适合处理团队里常见的原生工程改动:
|
|
4
|
+
|
|
5
|
+
- `bundle id` / `applicationId`
|
|
6
|
+
- 应用显示名
|
|
7
|
+
- Android 和 iOS 应用图标
|
|
8
|
+
- 工程体检
|
|
9
|
+
- 常见构建产物清理
|
|
10
|
+
|
|
11
|
+
它可以直接作为 CLI 使用,也可以在脚本里作为 API 调用。
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i -D @youlai/rn-tools
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
rn-tools bundle-id com.example.app
|
|
23
|
+
rn-tools display-name "有来医生"
|
|
24
|
+
rn-tools icon
|
|
25
|
+
rn-tools doctor --root /path/to/project
|
|
26
|
+
rn-tools clean --root /path/to/project
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## CLI
|
|
30
|
+
|
|
31
|
+
### `bundle-id`
|
|
32
|
+
|
|
33
|
+
同步更新 iOS 和 Android 的包标识。
|
|
34
|
+
|
|
35
|
+
- iOS 改的是 `project.pbxproj` 里的 `PRODUCT_BUNDLE_IDENTIFIER`,带引号和不带引号(Xcode 保存后的写法)两种值都会改,并保留原来的写法。
|
|
36
|
+
- `Info.plist` 的 `CFBundleIdentifier` 如果引用了构建设置(如 `$(PRODUCT_BUNDLE_IDENTIFIER)`),保持不变;只有写死的旧式值才会被改写。
|
|
37
|
+
- Android 的 `applicationId` 只改字符串字面量;写成表达式(如 `System.getenv(...) ?: "..."`)时不会改动,并给出警告,需手动处理。
|
|
38
|
+
- `--dry-run` 会列出将要修改和移动的文件,确认无误后再去掉 `--dry-run` 执行。
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
rn-tools bundle-id com.example.app
|
|
42
|
+
rn-tools bundle-id com.example.app --root /path/to/project
|
|
43
|
+
rn-tools bundle-id com.example.app --android-package com.example.android --ios-bundle-id com.example.ios
|
|
44
|
+
rn-tools bundle-id com.example.app --dry-run
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
可选参数:
|
|
48
|
+
|
|
49
|
+
- `--root <path>`: 指定项目根目录
|
|
50
|
+
- `--android-package <id>`: 覆盖 Android 的 `namespace` / `applicationId`
|
|
51
|
+
- `--ios-bundle-id <id>`: 覆盖 iOS 的 bundle identifier
|
|
52
|
+
- `--bundle-id <id>`: 显式传参形式
|
|
53
|
+
- `--dry-run`: 只预览,不落盘
|
|
54
|
+
- `--verbose` / `--quiet`: 控制日志层级
|
|
55
|
+
- `--color` / `--no-color`: 控制 ANSI 颜色输出
|
|
56
|
+
|
|
57
|
+
### `display-name`
|
|
58
|
+
|
|
59
|
+
同步更新 iOS 和 Android 的应用显示名。`Info.plist` 的 `CFBundleName` 如果引用了构建设置(如 `$(PRODUCT_NAME)`),保持不变;桌面上显示的是 `CFBundleDisplayName`。
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
rn-tools display-name "有来医生"
|
|
63
|
+
rn-tools display-name "有来医生" --root /path/to/project
|
|
64
|
+
rn-tools display-name --display-name "有来医生" --dry-run
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
可选参数:
|
|
68
|
+
|
|
69
|
+
- `--root <path>`: 指定项目根目录
|
|
70
|
+
- `--display-name <name>`: 显式传参形式
|
|
71
|
+
- `--dry-run`: 只预览,不落盘
|
|
72
|
+
- `--verbose` / `--quiet`: 控制日志层级
|
|
73
|
+
- `--color` / `--no-color`: 控制 ANSI 颜色输出
|
|
74
|
+
|
|
75
|
+
### `icon`
|
|
76
|
+
|
|
77
|
+
从单张源图生成 Android 和 iOS App Icon。源图必须是方形图片,支持 PNG、JPEG 和 SVG(SVG 会按输出尺寸渲染,不会放大发糊),工具会通过 `sharp` 读取图片并输出 PNG 图标。
|
|
78
|
+
|
|
79
|
+
App Store 要求 iOS 图标不透明,所以 iOS 图标中的透明像素会被填成 `iosIconBackgroundColor`(默认 `#FFFFFF`),源图有透明像素时会给出警告;Android 图标保留透明。系统会自动给图标加圆角,源图请用满版的方形底色,不要自带圆角。
|
|
80
|
+
|
|
81
|
+
#### 使用配置文件
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
rn-tools icon
|
|
85
|
+
rn-tools icon --dry-run
|
|
86
|
+
rn-tools icon --config .rn-toolsrc.js
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
默认会自动查找这些文件:
|
|
90
|
+
|
|
91
|
+
- `.rn-toolsrc`
|
|
92
|
+
- `.rn-toolsrc.json`
|
|
93
|
+
- `.rn-toolsrc.js`
|
|
94
|
+
- `.rn-toolsrc.cjs`
|
|
95
|
+
- `.rn-toolsrc.mjs`
|
|
96
|
+
|
|
97
|
+
`.rn-toolsrc.js` 示例:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
module.exports = {
|
|
101
|
+
icon: {
|
|
102
|
+
sourceImage: 'assets/icon.png',
|
|
103
|
+
androidDestinationDir: 'android/app/src/main/res',
|
|
104
|
+
androidAdaptiveIconBackgroundColor: '#FFFFFF',
|
|
105
|
+
androidAdaptiveIconForegroundScale: 0.72,
|
|
106
|
+
iosAssetsDir: 'ios/aliyunOnepass/Images.xcassets',
|
|
107
|
+
iosIconSetName: 'AppIcon.appiconset',
|
|
108
|
+
iosIconBackgroundColor: '#FFFFFF',
|
|
109
|
+
androidIconName: 'ic_launcher',
|
|
110
|
+
androidRoundIconName: 'ic_launcher_round'
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
配置也可以直接写在顶层:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
module.exports = {
|
|
119
|
+
sourceImage: 'assets/icon.png'
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
ESM 配置可以使用 `.rn-toolsrc.mjs`:
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
export default {
|
|
127
|
+
icon: {
|
|
128
|
+
sourceImage: 'assets/icon.png'
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### 直接传源图
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
rn-tools icon assets/icon.png
|
|
137
|
+
rn-tools icon --source assets/icon.png
|
|
138
|
+
rn-tools icon assets/icon.png --root /path/to/project --dry-run
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
推荐输入:
|
|
142
|
+
|
|
143
|
+
- 一张 `1024 x 1024` 的方形图片,或一张方形 SVG
|
|
144
|
+
- 图标内容尽量完整,不要带边框留白
|
|
145
|
+
- 底色铺满整张图,不要自带圆角或透明边角
|
|
146
|
+
|
|
147
|
+
默认输出:
|
|
148
|
+
|
|
149
|
+
- Android: `android/app/src/main/res/mipmap-*`
|
|
150
|
+
- Android Adaptive Icon: `android/app/src/main/res/mipmap-anydpi-v26/*.xml` 和 `drawable-*/*_foreground.png`
|
|
151
|
+
- iOS: `ios/<AppName>/Images.xcassets/AppIcon.appiconset`
|
|
152
|
+
|
|
153
|
+
可选参数:
|
|
154
|
+
|
|
155
|
+
- `--config <path>`: 图标配置文件路径;不传时自动查找 `.rn-toolsrc.*`
|
|
156
|
+
- `--root <path>`: 指定项目根目录
|
|
157
|
+
- `--source <path>`: 显式指定源图
|
|
158
|
+
- `--android-output <path>`: 自定义 Android 资源目录
|
|
159
|
+
- `--no-android-adaptive-icon`: 关闭 Android Adaptive Icon 生成
|
|
160
|
+
- `--android-adaptive-icon-background <color>`: 自定义 Android Adaptive Icon 背景色,默认 `#FFFFFF`
|
|
161
|
+
- `--android-adaptive-icon-foreground-scale <number>`: 自定义 Android Adaptive Icon 前景缩放,默认 `0.72`
|
|
162
|
+
- `--ios-assets <path>`: 自定义 iOS `Images.xcassets` 目录
|
|
163
|
+
- `--ios-icon-set-name <name>`: 自定义 iOS 图标集名称
|
|
164
|
+
- `--ios-icon-background <color>`: iOS 图标透明像素的填充色,默认 `#FFFFFF`
|
|
165
|
+
- `--android-icon-name <name>`: 自定义 Android 主图标文件名
|
|
166
|
+
- `--android-round-icon-name <name>`: 自定义 Android 圆角图标文件名
|
|
167
|
+
- `--dry-run`: 只预览,不落盘
|
|
168
|
+
- `--verbose` / `--quiet`: 控制日志层级
|
|
169
|
+
- `--color` / `--no-color`: 控制 ANSI 颜色输出
|
|
170
|
+
|
|
171
|
+
### `doctor`
|
|
172
|
+
|
|
173
|
+
检查常见的 RN 工程健康信号,不修改文件。
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
rn-tools doctor --root /path/to/project
|
|
177
|
+
rn-tools doctor --root /path/to/project --verbose
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
可选参数:
|
|
181
|
+
|
|
182
|
+
- `--root <path>`: 指定项目根目录
|
|
183
|
+
- `--verbose` / `--quiet`: 控制日志层级
|
|
184
|
+
- `--color` / `--no-color`: 控制 ANSI 颜色输出
|
|
185
|
+
|
|
186
|
+
### `clean`
|
|
187
|
+
|
|
188
|
+
清理常见构建和缓存产物。
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
rn-tools clean --root /path/to/project
|
|
192
|
+
rn-tools clean --root /path/to/project --dry-run
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
清理目标:
|
|
196
|
+
|
|
197
|
+
- `android/.gradle`
|
|
198
|
+
- `android/app/build`
|
|
199
|
+
- `ios/build`
|
|
200
|
+
- `.metro`
|
|
201
|
+
- `.expo`
|
|
202
|
+
|
|
203
|
+
可选参数:
|
|
204
|
+
|
|
205
|
+
- `--root <path>`: 指定项目根目录
|
|
206
|
+
- `--dry-run`: 只预览,不落盘
|
|
207
|
+
- `--verbose` / `--quiet`: 控制日志层级
|
|
208
|
+
- `--color` / `--no-color`: 控制 ANSI 颜色输出
|
|
209
|
+
|
|
210
|
+
### `rename`
|
|
211
|
+
|
|
212
|
+
`rename` 是分组式入口,支持这些子命令:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
rn-tools rename bundle-id com.example.app
|
|
216
|
+
rn-tools rename display-name "有来医生"
|
|
217
|
+
rn-tools rename doctor
|
|
218
|
+
rn-tools rename clean --dry-run
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 日志
|
|
222
|
+
|
|
223
|
+
CLI 默认使用基于 `picocolors` 的彩色 console logger,输出包含时间、工具名、任务名和日志等级;`--dry-run` 时会显示 `DRY-RUN` 标识。
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
rn-tools bundle-id com.example.app --verbose
|
|
227
|
+
rn-tools clean --dry-run --quiet
|
|
228
|
+
rn-tools doctor --no-color
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
日志层级:
|
|
232
|
+
|
|
233
|
+
- 默认:输出 `info` / `warn` / `error`
|
|
234
|
+
- `--verbose`: 额外输出 `debug`
|
|
235
|
+
- `--quiet`: 只输出 `warn` / `error`
|
|
236
|
+
- `--color`: 强制输出 ANSI 颜色
|
|
237
|
+
- `--no-color`: 关闭 ANSI 颜色
|
|
238
|
+
- `RN_TOOLS_DEBUG=1`: 等同开启 debug 输出
|
|
239
|
+
|
|
240
|
+
## `npx` 用法
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
npx @youlai/rn-tools bundle-id com.example.app
|
|
244
|
+
npx @youlai/rn-tools display-name "有来医生"
|
|
245
|
+
npx @youlai/rn-tools icon
|
|
246
|
+
npx @youlai/rn-tools icon assets/icon.png
|
|
247
|
+
npx @youlai/rn-tools doctor
|
|
248
|
+
npx @youlai/rn-tools clean --dry-run
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
如果项目里已经把 `rn-tools` 放到可执行路径里,也可以直接:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
npx rn-tools bundle-id com.example.app
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## 配置约定
|
|
258
|
+
|
|
259
|
+
默认情况下,工具会按 RN 项目常见结构查找文件:
|
|
260
|
+
|
|
261
|
+
- iOS `Info.plist`
|
|
262
|
+
- iOS `Images.xcassets`
|
|
263
|
+
- Android `android/app/src/main/res`
|
|
264
|
+
|
|
265
|
+
如果项目目录结构不一样,可以通过 `--root` 和各自的路径参数覆盖。
|
|
266
|
+
|
|
267
|
+
## API
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import {
|
|
271
|
+
buildIconAssets,
|
|
272
|
+
cleanProject,
|
|
273
|
+
createConsoleLogger,
|
|
274
|
+
doctorProject,
|
|
275
|
+
renameBundleId,
|
|
276
|
+
updateDisplayName
|
|
277
|
+
} from '@youlai/rn-tools';
|
|
278
|
+
|
|
279
|
+
await renameBundleId({
|
|
280
|
+
rootDir: '/path/to/project',
|
|
281
|
+
bundleId: 'com.example.app'
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
await updateDisplayName({
|
|
285
|
+
rootDir: '/path/to/project',
|
|
286
|
+
displayName: '有来医生'
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
await buildIconAssets({
|
|
290
|
+
rootDir: '/path/to/project',
|
|
291
|
+
sourceImage: 'assets/icon.png'
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
await buildIconAssets({
|
|
295
|
+
configPath: '.rn-toolsrc.js',
|
|
296
|
+
rootDir: '/path/to/project'
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
await cleanProject({
|
|
300
|
+
rootDir: '/path/to/project',
|
|
301
|
+
dryRun: true
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
await doctorProject({
|
|
305
|
+
rootDir: '/path/to/project'
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const logger = createConsoleLogger({
|
|
309
|
+
scope: 'release',
|
|
310
|
+
level: 'debug',
|
|
311
|
+
dryRun: true,
|
|
312
|
+
color: true
|
|
313
|
+
});
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## 扩展任务
|
|
317
|
+
|
|
318
|
+
包内保留了任务注册层,适合继续扩展新的项目维护能力。
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
import { createProjectToolRunner, runProjectTask } from '@youlai/rn-tools';
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
可以继续挂载:
|
|
325
|
+
|
|
326
|
+
- 签名配置检查
|
|
327
|
+
- Gradle / Xcode 结构修复
|
|
328
|
+
- 资源同步
|
|
329
|
+
- 其他 RN 项目级脚本
|
package/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";const s=require("node:path"),m=require("node:fs"),mn=require("picocolors"),gn=require("node:url"),L=require("sharp");function hn(n){return m.readFileSync(n,"utf8")}function N(n){return m.existsSync(n)?hn(n):null}function x(n,e,o){o||(m.mkdirSync(s.dirname(n),{recursive:!0}),m.writeFileSync(n,e))}function R(n,e){let o=n,i=!1;for(const[r,a]of e){const t=o.replace(r,a);t!==o&&(o=t,i=!0)}return{content:o,changed:i}}function M(n){if(!m.existsSync(n))return[];const e=[],o=i=>{for(const r of m.readdirSync(i,{withFileTypes:!0})){const a=s.join(i,r.name);r.isDirectory()?o(a):e.push(a)}};return o(n),e}function yn(n,e,o){if(!m.existsSync(n)||n===e)return[];const i=M(n),r=[];for(const a of i){const t=s.relative(n,a),d=s.join(e,t);if(m.existsSync(d))throw new Error(`Destination path already exists: ${d}`);o||(m.mkdirSync(s.dirname(d),{recursive:!0}),m.renameSync(a,d)),r.push({from:a,to:d})}return o||In(n),r}function In(n){let e=n;for(;e!==s.dirname(e);){if(!m.existsSync(e)){e=s.dirname(e);continue}if(m.readdirSync(e).length>0)break;m.rmdirSync(e),e=s.dirname(e)}}function tn(n,e){return m.existsSync(n)?(e||m.rmSync(n,{recursive:!0,force:!0}),!0):!1}function G(n){return an(n,"Info.plist",(e,o)=>s.relative(e,o).split(s.sep).length===2&&s.basename(o)==="Info.plist")}function an(n,e,o){const i=s.join(n,"ios"),a=M(i).find(t=>o(i,t));if(!a)throw new Error(`Could not find an iOS ${e} file under ${i}`);return a}const Z={debug:0,info:1,warn:2,error:3,silent:4},bn={debug:"DEBUG",info:"INFO ",warn:"WARN ",error:"ERROR"};function vn(n){return n.level?n.level:n.quiet?"warn":n.verbose||process.env.RN_TOOLS_DEBUG==="1"?"debug":"info"}function wn(n,e,o){return n==="debug"?o.gray(e):n==="info"?o.cyan(e):n==="warn"?o.yellow(e):o.red(e)}function Dn(){const n=new Date;return[n.getHours().toString().padStart(2,"0"),n.getMinutes().toString().padStart(2,"0"),n.getSeconds().toString().padStart(2,"0")].join(":")}function Nn(n,e,o,i){const r=[],a=o.prefix??"rn-tools";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(" ")}function P(n,e,o,i,r){if(Z[n]<Z[i])return;const a=Nn(n,e,o,r);if(n==="error"){console.error(a);return}if(n==="warn"){console.warn(a);return}console.log(a)}function sn(n={}){const e=vn(n),o=mn.createColors(n.color??!0);return{info(i){P("info",i,n,e,o)},warn(i){P("warn",i,n,e,o)},error(i){P("error",i,n,e,o)},debug(i){P("debug",i,n,e,o)}}}function T(n,e={}){return n??sn(e)}const An=/^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)+$/,dn=["java","kotlin"];function X(n){if(!An.test(n))throw new Error(`Invalid bundle id: ${n}. Use dot-separated Java package style names, for example com.example.app`)}async function xn(n){var O,E,j,_;const e=s.resolve(n.rootDir??process.cwd()),o=n.dryRun??!1,i=n.verbose??!1,r=T(n.logger,{dryRun:o,color:n.color,quiet:n.quiet,scope:"bundle-id",verbose:i}),a=n.androidPackage??n.bundleId,t=n.iosBundleId??n.bundleId;X(a),X(t);const d=new Set,u=new Set,c=[],l=Sn(e);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}`));const f=N(l.gradle);if(!f)throw new Error(`Android build file not found: ${l.gradle}`);const I=kn(l.gradle)??a,A=R(f,[[/namespace\s+"[^"]+"/,`namespace "${a}"`],[/applicationId\s+"[^"]+"/,`applicationId "${a}"`]]);A.changed?(x(l.gradle,A.content,o),d.add(l.gradle)):u.add(`No namespace/applicationId changes were needed in ${l.gradle}`);const b=f.match(/^\s*applicationId\b(.*)$/m);b&&!/^\s+"[^"]+"\s*$/.test(b[1])&&!b[1].includes(`"${a}"`)&&u.add(`applicationId in ${l.gradle} is not a string literal; update it manually`);const S=N(l.manifest);if(S){const g=R(S,[[/package="[^"]+"/,`package="${a}"`],[/package\s*=\s*"[^"]+"/,`package="${a}"`]]);g.changed&&(x(l.manifest,g.content,o),d.add(l.manifest))}const v=Fn(e),w=N(v);if(!w)throw new Error(`iOS project file not found: ${v}`);const D=$n(w,t);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}`);const y=G(e),p=N(y);if(p){const g=p.match(/<key>CFBundleIdentifier<\/key>\s*<string>([^<]+)<\/string>/);if(g&&cn(g[1]))(_=r.debug)==null||_.call(r,`Kept build setting reference ${g[1]} in ${y}`);else{const k=R(p,[[/<key>CFBundleIdentifier<\/key>\s*<string>[^<]+<\/string>/,`<key>CFBundleIdentifier</key>
|
|
3
|
+
<string>${t}</string>`]]);k.changed&&(x(y,k.content,o),d.add(y))}}for(const g of dn){const k=s.join(e,"android/app/src/main",g,...I.split(".")),C=s.join(e,"android/app/src/main",g,...a.split(".")),fn=yn(k,C,o);for(const pn of fn)c.push(pn)}const $=c.length>0?c.map(g=>o?g.from:g.to):Cn(e,I);for(const g of $){const k=N(g);if(!k)continue;const C=R(k,[[new RegExp(`^package\\s+${Rn(I)}$`,"m"),`package ${a}`]]);C.changed&&(x(g,C.content,o),d.add(g))}const F={changedFiles:Array.from(d).sort(),movedFiles:c,warnings:Array.from(u).sort(),dryRun:o};return o?r.info(`Dry-run completed with ${F.changedFiles.length} pending change(s)`):r.info(`Updated ${F.changedFiles.length} file(s)`),F}function $n(n,e){let o=0;const i=n.replace(/PRODUCT_BUNDLE_IDENTIFIER = ("[^"\n]*"|[^;\n]+);/g,(r,a)=>(o+=1,`PRODUCT_BUNDLE_IDENTIFIER = ${a.startsWith('"')?`"${e}"`:e};`));return{content:i,changed:i!==n,matches:o}}function cn(n){return/\$[({][A-Za-z0-9_:]+[)}]/.test(n)}function kn(n){const e=N(n);if(!e)return null;const o=e.match(/namespace\s+"([^"]+)"/);return(o==null?void 0:o[1])??null}function Sn(n){return{gradle:s.join(n,"android/app/build.gradle"),manifest:s.join(n,"android/app/src/main/AndroidManifest.xml"),javaRoot:s.join(n,"android/app/src/main/java"),kotlinRoot:s.join(n,"android/app/src/main/kotlin")}}function Fn(n){return an(n,"project.pbxproj",(e,o)=>s.relative(e,o).split(s.sep).length===2&&o.endsWith(".xcodeproj/project.pbxproj"))}function Cn(n,e){const o=dn.map(r=>s.join(n,"android/app/src/main",r,...e.split("."))),i=[];for(const r of o)i.push(...M(r));return i}function Rn(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const On=["android/.gradle","android/app/build","ios/build",".metro",".expo"];async function En(n){var u;const e=s.resolve(n.rootDir??process.cwd()),o=n.dryRun??!1,i=n.verbose??!1,r=T(n.logger,{dryRun:o,color:n.color,quiet:n.quiet,scope:"clean",verbose:i});i&&((u=r.debug)==null||u.call(r,`rootDir=${e}`));const a=new Set,t=new Set;for(const c of On){const l=s.join(e,c);tn(l,o)&&(i&&r.info(`${o?"[dry-run] ":""}clean target: ${l}`),a.add(l))}const d={changedFiles:Array.from(a).sort(),movedFiles:[],warnings:Array.from(t).sort(),dryRun:o};return o?r.info(`Dry-run completed with ${d.changedFiles.length} target(s)`):r.info(`Cleaned ${d.changedFiles.length} target(s)`),d}function jn(n){if(!n||!n.trim())throw new Error("Display name cannot be empty")}async function _n(n){var S,v;const e=s.resolve(n.rootDir??process.cwd()),o=n.dryRun??!1,i=n.verbose??!1,r=T(n.logger,{dryRun:o,color:n.color,quiet:n.quiet,scope:"display-name",verbose:i}),a=n.displayName.trim();jn(a),i&&((S=r.debug)==null||S.call(r,`rootDir=${e}`),(v=r.debug)==null||v.call(r,`displayName=${a}`));const t=new Set,d=new Set,u=s.join(e,"app.json"),c=N(u);if(c)try{const D={...JSON.parse(c),displayName:a},y=`${JSON.stringify(D,null,2)}
|
|
4
|
+
`;y!==c&&(x(u,y,o),t.add(u))}catch{d.add(`Skipped invalid JSON file: ${u}`)}const l=G(e),f=N(l);if(f){const w=[[/<key>CFBundleDisplayName<\/key>\s*<string>[^<]*<\/string>/,`<key>CFBundleDisplayName</key>
|
|
5
|
+
<string>${a}</string>`]],D=f.match(/<key>CFBundleName<\/key>\s*<string>([^<]*)<\/string>/);(!D||!cn(D[1]))&&w.push([/<key>CFBundleName<\/key>\s*<string>[^<]*<\/string>/,`<key>CFBundleName</key>
|
|
6
|
+
<string>${a}</string>`]);const y=R(f,w);y.changed?(x(l,y.content,o),t.add(l)):d.add(`No iOS display-name changes were needed in ${l}`)}const I=s.join(e,"android/app/src/main/res/values/strings.xml"),A=N(I);if(A){const w=R(A,[[/<string name="app_name">[^<]*<\/string>/,`<string name="app_name">${a}</string>`]]);w.changed?(x(I,w.content,o),t.add(I)):d.add(`No Android app_name changes were needed in ${I}`)}const b={changedFiles:Array.from(t).sort(),movedFiles:[],warnings:Array.from(d).sort(),dryRun:o};return o?r.info(`Dry-run completed with ${b.changedFiles.length} pending change(s)`):r.info(`Updated ${b.changedFiles.length} file(s)`),b}async function Bn(n){var v,w,D,y;const e=s.resolve(n.rootDir??process.cwd()),o=n.verbose??!1,i=T(n.logger,{color:n.color,quiet:n.quiet,scope:"doctor",verbose:o});o&&((v=i.debug)==null||v.call(i,`rootDir=${e}`));const r=new Set,a=[],t={},d=s.join(e,"app.json"),u=N(d);if(!u)r.add(`Missing app.json: ${d}`);else try{const p=JSON.parse(u);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}`)}catch{r.add(`Invalid JSON: ${d}`)}const c=s.join(e,"android/app/build.gradle"),l=N(c);if(!l)r.add(`Missing Android build file: ${c}`);else{const p=(w=l.match(/namespace\s+"([^"]+)"/))==null?void 0:w[1],$=(D=l.match(/applicationId\s+"([^"]+)"/))==null?void 0:D[1];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 ${$}`)}const f=s.join(e,"android/app/src/main/res/values/strings.xml"),I=N(f);if(!I)r.add(`Missing Android strings: ${f}`);else{const p=(y=I.match(/<string name="app_name">([^<]+)<\/string>/))==null?void 0:y[1];t.androidAppName=p,p||r.add(`Missing app_name in ${f}`)}const A=G(e),b=N(A);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(p=>/\.(kt|java)$/.test(p)).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(`app.json "name" and "displayName" differ: ${t.appName} vs ${t.displayName}`);for(const p of r)i.warn(p);return r.size===0?i.info("Doctor check passed"):i.info(`Doctor found ${r.size} issue(s)`),{changedFiles:a,movedFiles:[],warnings:Array.from(r).sort(),dryRun:!0}}function J(n,e){var o;return(o=n.match(new RegExp(`<key>${e}<\\/key>\\s*<string>([^<]*)<\\/string>`)))==null?void 0:o[1]}function B(n){return typeof n=="string"&&!n.startsWith("$(")&&!n.startsWith("${")}function Tn(n,e){n.androidNamespace&&n.androidApplicationId&&n.androidNamespace!==n.androidApplicationId&&e.add(`Android namespace and applicationId differ: ${n.androidNamespace} vs ${n.androidApplicationId}`),B(n.iosDisplayName)&&B(n.iosName)&&n.iosDisplayName!==n.iosName&&e.add(`iOS CFBundleDisplayName and CFBundleName differ: ${n.iosDisplayName} vs ${n.iosName}`);const o=n.displayName;B(o)&&(B(n.androidAppName)&&n.androidAppName!==o&&e.add(`Android app_name does not match app.json displayName: ${n.androidAppName} vs ${o}`),B(n.iosDisplayName)&&n.iosDisplayName!==o&&e.add(`iOS CFBundleDisplayName does not match app.json displayName: ${n.iosDisplayName} vs ${o}`))}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=.72,Wn="#FFFFFF",ln=[{dir:"mipmap-mdpi",size:48},{dir:"mipmap-hdpi",size:72},{dir:"mipmap-xhdpi",size:96},{dir:"mipmap-xxhdpi",size:144},{dir:"mipmap-xxxhdpi",size:192}],Vn=[{dir:"drawable-mdpi",size:108},{dir:"drawable-hdpi",size:162},{dir:"drawable-xhdpi",size:216},{dir:"drawable-xxhdpi",size:324},{dir:"drawable-xxxhdpi",size:432}],K=[{idiom:"iphone",size:"20x20",scale:"2x",filename:"icon-20x20-2x-iphone.png"},{idiom:"iphone",size:"20x20",scale:"3x",filename:"icon-20x20-3x-iphone.png"},{idiom:"ipad",size:"20x20",scale:"1x",filename:"icon-20x20-1x-ipad.png"},{idiom:"ipad",size:"20x20",scale:"2x",filename:"icon-20x20-2x-ipad.png"},{idiom:"iphone",size:"29x29",scale:"2x",filename:"icon-29x29-2x-iphone.png"},{idiom:"iphone",size:"29x29",scale:"3x",filename:"icon-29x29-3x-iphone.png"},{idiom:"ipad",size:"29x29",scale:"1x",filename:"icon-29x29-1x-ipad.png"},{idiom:"ipad",size:"29x29",scale:"2x",filename:"icon-29x29-2x-ipad.png"},{idiom:"iphone",size:"40x40",scale:"2x",filename:"icon-40x40-2x-iphone.png"},{idiom:"iphone",size:"40x40",scale:"3x",filename:"icon-40x40-3x-iphone.png"},{idiom:"ipad",size:"40x40",scale:"1x",filename:"icon-40x40-1x-ipad.png"},{idiom:"ipad",size:"40x40",scale:"2x",filename:"icon-40x40-2x-ipad.png"},{idiom:"iphone",size:"60x60",scale:"2x",filename:"icon-60x60-2x-iphone.png"},{idiom:"iphone",size:"60x60",scale:"3x",filename:"icon-60x60-3x-iphone.png"},{idiom:"ipad",size:"76x76",scale:"1x",filename:"icon-76x76-1x-ipad.png"},{idiom:"ipad",size:"76x76",scale:"2x",filename:"icon-76x76-2x-ipad.png"},{idiom:"ipad",size:"83.5x83.5",scale:"2x",filename:"icon-83_5x83_5-2x-ipad.png"},{idiom:"ios-marketing",size:"1024x1024",scale:"1x",filename:"icon-1024x1024.png"}];async function Zn(n){var O,E,j,_,g,k;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,{dryRun:r,color:n.color,quiet:n.quiet,scope:"icon",verbose:a}),d=W(i,o.sourceImage??Un),u=W(i,o.androidDestinationDir??Pn),c=W(i,o.iosAssetsDir??me(i)),l=s.join(c,o.iosIconSetName??zn),f=o.androidIconName??qn,I=o.androidRoundIconName??Ln,A=o.androidAdaptiveIcon??Mn,b=o.androidAdaptiveIconBackgroundColor??Gn,S=o.androidAdaptiveIconForegroundScale??Jn,v=o.iosIconBackgroundColor??Wn;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);const w=await re(d);ne(w,d);const D=new Set,y=new Set,p=await Kn({sourceImage:d,destinationDir:u,iconName:f,roundIconName:I,adaptiveIcon:A,adaptiveIconBackgroundColor:b,adaptiveIconForegroundScale:S,dryRun:r}),$=await Yn({sourceImage:d,iconSetDir:l,backgroundColor:v,dryRun:r});(await L(d).stats()).isOpaque||y.add(`Icon source has transparent pixels; iOS icons were filled with ${v}`);for(const C of[...p,...$])D.add(C);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}`);const F={changedFiles:Array.from(D).sort(),movedFiles:[],warnings:Array.from(y).sort(),dryRun:r};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}function Xn(n,e){return{...n,...e}}async function Kn(n){const e=[];for(const{dir:o,size:i}of ln){const r=s.join(n.destinationDir,o),a=s.join(r,`${n.iconName}.png`),t=s.join(r,`${n.roundIconName}.png`);n.dryRun||(m.mkdirSync(r,{recursive:!0}),await V(n.sourceImage,a,i),await V(n.sourceImage,t,i)),e.push(a,t)}if(n.adaptiveIcon){const o=`${n.iconName}_foreground`,i=`${n.iconName}_background`;for(const{dir:d,size:u}of Vn){const c=s.join(n.destinationDir,d),l=s.join(c,`${o}.png`);n.dryRun||(m.mkdirSync(c,{recursive:!0}),await te(n.sourceImage,l,u,n.adaptiveIconForegroundScale)),e.push(l)}const r=s.join(n.destinationDir,"values",`${i}.xml`),a=s.join(n.destinationDir,"mipmap-anydpi-v26",`${n.iconName}.xml`),t=s.join(n.destinationDir,"mipmap-anydpi-v26",`${n.roundIconName}.xml`);n.dryRun||(x(r,ae(i,n.adaptiveIconBackgroundColor),!1),x(a,Y(i,o),!1),x(t,Y(i,o),!1)),e.push(r,a,t)}return e}async function Yn(n){const e=[],o=K.map(a=>({idiom:a.idiom,size:a.size,scale:a.scale,filename:a.filename}));n.dryRun||(tn(n.iconSetDir,!1),m.mkdirSync(n.iconSetDir,{recursive:!0}));for(const a of K){const t=s.join(n.iconSetDir,a.filename),d=Hn(a.size,a.scale);n.dryRun||await V(n.sourceImage,t,d,n.backgroundColor),e.push(t)}const i=s.join(n.iconSetDir,"Contents.json"),r=JSON.stringify({images:o,info:{version:1,author:"xcode"}},null,2);return n.dryRun||x(i,`${r}
|
|
7
|
+
`,!1),e.push(i),e}function Hn(n,e){const o=Number.parseFloat(n.split("x")[0]??"0"),i=Number.parseFloat(e.replace("x",""));return Math.round(o*i)}function Qn(n,e){if(!m.existsSync(n))throw new Error(`${e} not found: ${n}`)}function ne(n,e){if(!n.width||!n.height)throw new Error(`Unable to read image dimensions for ${e}`);if(n.width!==n.height)throw new Error(`Icon source image must be square, but got ${n.width}x${n.height}: ${e}`)}function ee(n){if(!Number.isFinite(n)||n<=0||n>1)throw new Error(`Android adaptive icon foreground scale must be a number between 0 and 1, but got ${n}`)}function oe(n,e,o){const i=ln.map(({dir:a})=>s.join(e,a)),r=[o,...i].filter(a=>ie(n,a));if(r.length>0)throw new Error(`Icon source image must be outside generated icon directories: ${r.join(", ")}
|
|
8
|
+
Use a source file such as assets/icon.png instead: ${n}`)}function ie(n,e){const o=s.relative(e,n);return o===""||!o.startsWith("..")&&!s.isAbsolute(o)}function W(n,e){return s.isAbsolute(e)?e:s.join(n,e)}async function re(n){return L(n).metadata()}async function V(n,e,o,i){m.mkdirSync(s.dirname(e),{recursive:!0});const r=L(n).resize(o,o,{fit:"fill"});i&&r.flatten({background:i}).removeAlpha(),await r.png().toFile(e)}async function te(n,e,o,i){const r=Math.max(1,Math.round(o*i));m.mkdirSync(s.dirname(e),{recursive:!0}),await L(n).resize(r,r,{fit:"contain"}).extend({top:Math.floor((o-r)/2),bottom:Math.ceil((o-r)/2),left:Math.floor((o-r)/2),right:Math.ceil((o-r)/2),background:{r:0,g:0,b:0,alpha:0}}).png().toFile(e)}function ae(n,e){return['<?xml version="1.0" encoding="utf-8"?>',"<resources>",` <color name="${n}">${e}</color>`,"</resources>",""].join(`
|
|
9
|
+
`)}function Y(n,e){return['<?xml version="1.0" encoding="utf-8"?>','<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">',` <background android:drawable="@color/${n}" />`,` <foreground android:drawable="@drawable/${e}" />`,"</adaptive-icon>",""].join(`
|
|
10
|
+
`)}async function se(n,e){if(!n){const r=le(e);return r?H(r):{}}ce(n);const o=de(n,e),i=o.find(r=>m.existsSync(r));if(!i)throw new Error(`Icon config file not found: ${o[0]??s.resolve(n)}`);return H(i)}function de(n,e){if(s.isAbsolute(n))return[n];const o=s.resolve(process.cwd(),n),i=e?s.resolve(e,n):null,r=[o];return i&&i!==o&&r.push(i),r}function ce(n){const e=s.basename(n);if(e==="rn-tools.config"||e.startsWith("rn-tools.config."))throw new Error(`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.`)}function le(n){const e=[n?s.resolve(n):null,process.cwd()].filter(i=>!!i),o=[".rn-toolsrc",".rn-toolsrc.json",".rn-toolsrc.js",".rn-toolsrc.cjs",".rn-toolsrc.mjs"];for(const i of e)for(const r of o){const a=s.join(i,r);if(m.existsSync(a))return a}return null}async function H(n){const e=s.extname(n).toLowerCase();if(e===".json"||e===""){const i=N(n);if(!i)throw new Error(`Icon config file not found: ${n}`);let r;try{r=JSON.parse(i)}catch{throw new Error(`Icon config file is not valid JSON: ${n}`)}return Q(r,n)}const o=await import(gn.pathToFileURL(n).href);return Q(o,n)}function Q(n,e){if(!n||typeof n!="object")throw new Error(`Icon config file must contain an object: ${e}`);const o=ue(n);if(!o)throw new Error(`Icon config section must be an object: ${e}`);return pe(o,s.dirname(e))}function ue(n){if(!z(n))return null;const e=z(n.default)?n.default:n;return fe(e)?z(e.icon)?e.icon:null:z(e)?e:null}function fe(n){return Object.prototype.hasOwnProperty.call(n,"icon")}function z(n){return!!n&&typeof n=="object"&&!Array.isArray(n)}function pe(n,e){const o={};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}function q(n,e){return s.isAbsolute(e)?e:s.resolve(n,e)}function me(n){const e=G(n);return s.join(s.dirname(e),"Images.xcassets")}const ge={name:"bundle-id",description:"Rename the iOS bundle identifier and Android application package",async run(n,e){return xn({...e,rootDir:e.rootDir??n.rootDir,dryRun:e.dryRun??n.dryRun,verbose:e.verbose??n.verbose,quiet:e.quiet??n.quiet,color:e.color??n.color,logger:e.logger??n.logger})}},he={name:"display-name",description:"Update the app display name on iOS and Android",async run(n,e){return _n({...e,rootDir:e.rootDir??n.rootDir,dryRun:e.dryRun??n.dryRun,verbose:e.verbose??n.verbose,quiet:e.quiet??n.quiet,color:e.color??n.color,logger:e.logger??n.logger})}},ye={name:"clean",description:"Remove common build and cache artifacts",async run(n,e){return En({...e,rootDir:e.rootDir??n.rootDir,dryRun:e.dryRun??n.dryRun,verbose:e.verbose??n.verbose,quiet:e.quiet??n.quiet,color:e.color??n.color,logger:e.logger??n.logger})}},Ie={name:"doctor",description:"Check common RN project health signals",async run(n,e){return Bn({...e,rootDir:e.rootDir??n.rootDir,verbose:e.verbose??n.verbose,quiet:e.quiet??n.quiet,color:e.color??n.color,logger:e.logger??n.logger})}},be={name:"icon",description:"Generate Android and iOS app icons from a single source image",async run(n,e){return Zn({...e,rootDir:e.rootDir??n.rootDir,dryRun:e.dryRun??n.dryRun,verbose:e.verbose??n.verbose,quiet:e.quiet??n.quiet,color:e.color??n.color,logger:e.logger??n.logger})}};function un(n=[ge,he,ye,Ie,be]){const e=new Map;for(const i of n)e.set(i.name,i);const o={listTasks(){return Array.from(e.values())},getTask(i){return e.get(i)},registerTask(i){return e.set(i.name,i),o},async runTask(i,r,a){const t=e.get(i);if(!t){const d=Array.from(e.keys()).sort();throw new Error(`Unknown task "${i}". Available tasks: ${d.join(", ")||"(none)"}`)}return t.run(r,a)}};return o}un();async function ve(n){const e=we(n);if(e.kind==="help")return Ne(),Promise.resolve();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({color:a,dryRun:r,quiet:o,scope:e.kind,verbose:i}),d=un(),u={rootDir:e.options.rootDir??process.cwd(),color:a,dryRun:r,quiet:o,verbose:i,logger:t};return d.runTask(e.kind,u,e.options).then(c=>{if(e.kind==="doctor"){t.info(c.warnings.length===0?"Doctor completed successfully":`Doctor completed with ${c.warnings.length} issue(s)`);return}t.info(`Task completed: ${c.dryRun?"dry-run":"write"} mode, ${c.changedFiles.length} file(s) changed, ${c.movedFiles.length} file(s) moved`);const l=f=>{var I;return c.dryRun?t.info(f):(I=t.debug)==null?void 0:I.call(t,f)};for(const f of c.changedFiles)l(` ${c.dryRun?"would change":"changed"} ${s.relative(u.rootDir,f)}`);for(const f of c.movedFiles)l(` ${c.dryRun?"would move":"moved"} ${s.relative(u.rootDir,f.from)} -> ${s.relative(u.rootDir,f.to)}`);for(const f of c.warnings)t.warn(f)}).catch(c=>{t.error(c instanceof Error?c.message:String(c)),process.exitCode=1})}function we(n){const e=[...n];if(e.length===0||e.includes("--help")||e.includes("-h"))return{kind:"help"};const o=e.shift();if(o==="rename"){const i=e.shift();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"}}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"}}function nn(n){const e=[...n],o=[],i={bundleId:""};for(;e.length>0;){const r=e.shift();if(r){if(!r.startsWith("-")){o.push(r);continue}if(r==="--root"){i.rootDir=h("--root",e);continue}if(r==="--android-package"){i.androidPackage=h("--android-package",e);continue}if(r==="--ios-bundle-id"){i.iosBundleId=h("--ios-bundle-id",e);continue}if(!U(r,i)){if(r==="--bundle-id"){i.bundleId=h("--bundle-id",e);continue}throw new Error(`Unknown flag: ${r}`)}}}if(!i.bundleId&&o.length>0&&(i.bundleId=o.shift()??""),!i.bundleId)throw new Error("Missing bundle id. Example: bundle-id com.example.app");return i}function en(n){const e=[...n],o=[],i={displayName:""};for(;e.length>0;){const r=e.shift();if(r){if(!r.startsWith("-")){o.push(r);continue}if(r==="--root"){i.rootDir=h("--root",e);continue}if(!U(r,i)){if(r==="--display-name"){i.displayName=h("--display-name",e);continue}throw new Error(`Unknown flag: ${r}`)}}}if(!i.displayName&&o.length>0&&(i.displayName=o.shift()??""),!i.displayName)throw new Error('Missing display name. Example: display-name "Youlai 医生"');return i}function on(n){const e=[...n],o={};for(;e.length>0;){const i=e.shift();if(i){if(i==="--root"){o.rootDir=h("--root",e);continue}if(!U(i,o))throw new Error(`Unknown flag: ${i}`)}}return o}function rn(n){const e=[...n],o={};for(;e.length>0;){const i=e.shift();if(i){if(i==="--root"){o.rootDir=h("--root",e);continue}if(!U(i,o,{allowDryRun:!1}))throw new Error(`Unknown flag: ${i}`)}}return o}function De(n){const e=[...n],o={};for(;e.length>0;){const i=e.shift();if(i){if(!i.startsWith("-")&&!o.sourceImage){o.sourceImage=i;continue}if(i==="--root"){o.rootDir=h("--root",e);continue}if(i==="--source"){o.sourceImage=h("--source",e);continue}if(i==="--config"){o.configPath=h("--config",e);continue}if(i==="--android-output"){o.androidDestinationDir=h("--android-output",e);continue}if(i==="--android-adaptive-icon"){o.androidAdaptiveIcon=!0;continue}if(i==="--no-android-adaptive-icon"){o.androidAdaptiveIcon=!1;continue}if(i==="--android-adaptive-icon-background"){o.androidAdaptiveIconBackgroundColor=h("--android-adaptive-icon-background",e);continue}if(i==="--ios-icon-background"){o.iosIconBackgroundColor=h("--ios-icon-background",e);continue}if(i==="--android-adaptive-icon-foreground-scale"){o.androidAdaptiveIconForegroundScale=Number.parseFloat(h("--android-adaptive-icon-foreground-scale",e));continue}if(i==="--ios-assets"){o.iosAssetsDir=h("--ios-assets",e);continue}if(i==="--ios-icon-set-name"){o.iosIconSetName=h("--ios-icon-set-name",e);continue}if(i==="--android-icon-name"){o.androidIconName=h("--android-icon-name",e);continue}if(i==="--android-round-icon-name"){o.androidRoundIconName=h("--android-round-icon-name",e);continue}if(!U(i,o))throw new Error(`Unknown flag: ${i}`)}}return o}function h(n,e){const o=e.shift();if(!o||o.startsWith("-"))throw new Error(`Missing value for ${n}`);return o}function U(n,e,o={}){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}function Ne(){process.stdout.write(["rn-tools","","Usage:"," rn-tools bundle-id <bundleId> [--root <path>] [--dry-run] [--verbose]"," rn-tools display-name <name> [--root <path>] [--dry-run] [--verbose]"," rn-tools clean [--root <path>] [--dry-run] [--verbose]"," rn-tools doctor [--root <path>] [--verbose]"," rn-tools icon [source.png] [--root <path>] [--source <png>] [--dry-run] [--verbose]"," rn-tools rename bundle-id <bundleId> [--root <path>] [--dry-run] [--verbose]"," rn-tools rename display-name <name> [--root <path>] [--dry-run] [--verbose]"," rn-tools rename clean [--root <path>] [--dry-run] [--verbose]"," rn-tools rename doctor [--root <path>] [--verbose]","","npx:"," npx @youlai/rn-tools bundle-id <bundleId>"," npx rn-tools bundle-id <bundleId>"," npx @youlai/rn-tools display-name <name>"," npx rn-tools display-name <name>"," npx @youlai/rn-tools clean"," npx rn-tools clean"," npx @youlai/rn-tools doctor"," npx rn-tools doctor"," npx @youlai/rn-tools icon"," npx rn-tools icon","","Flags:"," --android-package <id> Override Android namespace/applicationId"," --ios-bundle-id <id> Override iOS bundle identifier"," --display-name <name> Explicit display name flag form"," --bundle-id <id> Explicit bundle id flag form"," --config <path> Icon build config file path (.rn-toolsrc.* preferred)"," --source <image> Source image (PNG, JPEG or SVG) for icon generation"," --android-output <path> Android resource directory"," --no-android-adaptive-icon Disable Android adaptive icon generation"," --android-adaptive-icon-background <color> Android adaptive icon background color"," --android-adaptive-icon-foreground-scale <number> Android adaptive foreground scale"," --ios-assets <path> iOS Images.xcassets directory"," --ios-icon-set-name <name> iOS app icon set folder name"," --ios-icon-background <color> Fill for transparent pixels in iOS icons (default #FFFFFF)"," --android-icon-name <name> Android icon file name"," --android-round-icon-name <name> Android round icon file name"," --color Force color output"," --no-color Disable color output"," --quiet Show only warnings and errors"," --help, -h Show this help",""].join(`
|
|
11
|
+
`))}ve(process.argv.slice(2));
|